rust/editors/code/package.json
bors[bot] 232785251b
Merge #2061
2061: Theme loading and "editor.tokenColorCustomizations" support. r=matklad a=seivan

Fixes: [Issue#1294](https://github.com/rust-analyzer/rust-analyzer/issues/1294#issuecomment-497450325)

TODO: 
- [x] Load themes
- [x] Load existing `ralsp`-prefixed overrides from `"workbench.colorCustomizations"`.
- [x] Load overrides from `"editor.tokenColorCustomizations.textMateRules"`.
- [x] Use RA tags to load `vscode.DecorationRenderOptions` (colors) from theme & overrides.
- [x] Map RA tags to common TextMate scopes before loading colors.
- [x] Add default scope mappings in extension.
- [x] Cache mappings between settings updates. 
- [x] Add scope mapping configuration manifest in `package.json`
- [x] Load configurable scope mappings from settings.
- [x] Load JSON Scheme for text mate scope rules in settings.
- [x] Update [Readme](https://github.com/seivan/rust-analyzer/blob/feature/themes/docs/user/README.md#settings).

Borrowed the theme loading (`scopes.ts`) from `Tree Sitter` with some modifications to reading `"editor.tokenColorCustomizations"` for merging with loaded themes and had to remove the async portions to be able to load it from settings updates. 

~Just a PoC and an idea I toyed around with a lot of room for improvement.~
For starters, certain keywords aren't part of the standard TextMate grammar, so it still reads colors from the `ralsp` prefixed values in `"workbench.colorCustomizations"`. 

But I think there's more value making the extension work with existing themes by maping some of the decoration tags to existing key or keys. 

<img width="453" alt="Screenshot 2019-11-09 at 17 43 18" src="https://user-images.githubusercontent.com/55424/68531968-71b4e380-0318-11ea-924e-cdbb8d5eae06.png">
<img width="780" alt="Screenshot 2019-11-09 at 17 41 45" src="https://user-images.githubusercontent.com/55424/68531950-4b8f4380-0318-11ea-8f85-24a84efaf23b.png">
<img width="468" alt="Screenshot 2019-11-09 at 17 40 29" src="https://user-images.githubusercontent.com/55424/68531952-51852480-0318-11ea-800a-6ae9215f5368.png">


These will merge with the default ones coming with the extension, so you don't have to implement all of them and works well with overrides defined in settings. 

```jsonc
    "editor.tokenColorCustomizations": {
        "textMateRules": [
            {
                "scope": "keyword",
                "settings": {
                    "fontStyle": "bold",
                }
            },
        ]
    },
```


Edit: The idea is to work with 90% of the themes out there by working within existing scopes available that are generally styled. It's not to say I want to erase the custom Rust scopes - those should still remain and eventually worked into a custom grammar bundle for Rust specific themes that target those, I just want to make it work with generic themes offered on the market place for now. 

A custom grammar bundle and themes for Rust specific scopes is out of... scope for this PR. 
We'll make another round to tackle those issues. 


Current fallbacks implemented

```typescript
    [
        'comment',
        [
            'comment',
            'comment.block',
            'comment.line',
            'comment.block.documentation'
        ]
    ],
    ['string', ['string']],
    ['keyword', ['keyword']],
    ['keyword.control', ['keyword.control', 'keyword', 'keyword.other']],
    [
        'keyword.unsafe',
        ['storage.modifier', 'keyword.other', 'keyword.control', 'keyword']
    ],
    ['function', ['entity.name.function']],
    ['parameter', ['variable.parameter']],
    ['constant', ['constant', 'variable']],
    ['type', ['entity.name.type']],
    ['builtin', ['variable.language', 'support.type', 'support.type']],
    ['text', ['string', 'string.quoted', 'string.regexp']],
    ['attribute', ['keyword']],
    ['literal', ['string', 'string.quoted', 'string.regexp']],
    ['macro', ['support.other']],
    ['variable', ['variable']],
    ['variable.mut', ['variable', 'storage.modifier']],
    [
        'field',
        [
            'variable.object.property',
            'meta.field.declaration',
            'meta.definition.property',
            'variable.other'
        ]
    ],
    ['module', ['entity.name.section', 'entity.other']]
```


Co-authored-by: Seivan Heidari <seivan.heidari@icloud.com>
2019-12-29 16:49:40 +00:00

632 lines
23 KiB
JSON

{
"name": "ra-lsp",
"displayName": "ra-lsp",
"description": "An alternative rust language server to the RLS",
"preview": true,
"private": true,
"version": "0.0.1",
"publisher": "matklad",
"repository": {
"url": "https://github.com/matklad/rust-analyzer/"
},
"categories": [
"Other"
],
"engines": {
"vscode": "^1.41.0"
},
"scripts": {
"vscode:prepublish": "npm run compile",
"package": "vsce package",
"compile": "rollup -c",
"watch": "tsc -watch -p ./",
"fix": "prettier **/*.{json,ts} --write && tslint --project . --fix",
"lint": "tslint --project .",
"prettier": "prettier **/*.{json,ts}",
"test": "tsc -p . && node ./out/test/runTest.js",
"travis": "npm run compile && npm run test && npm run lint && npm run prettier -- --write && git diff --exit-code"
},
"prettier": {
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "all"
},
"dependencies": {
"lookpath": "^1.0.4",
"seedrandom": "^3.0.5",
"vscode-languageclient": "^6.0.0-next.9",
"jsonc-parser": "^2.1.0"
},
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.7",
"@types/node": "^12.12.21",
"@types/seedrandom": "^2.4.28",
"@types/vscode": "^1.41.0",
"glob": "^7.1.6",
"mocha": "^6.2.2",
"prettier": "^1.19.1",
"rollup": "^1.27.13",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-typescript": "^1.0.1",
"shx": "^0.3.1",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",
"typescript": "^3.7.3",
"vsce": "^1.71.0",
"vscode-test": "^1.3.0"
},
"activationEvents": [
"onLanguage:rust",
"onCommand:rust-analyzer.analyzerStatus",
"onCommand:rust-analyzer.collectGarbage",
"workspaceContains:**/Cargo.toml"
],
"main": "./bundle/extension",
"contributes": {
"taskDefinitions": [
{
"type": "cargo",
"required": [
"command"
],
"properties": {
"label": {
"type": "string"
},
"command": {
"type": "string"
},
"args": {
"type": "array"
},
"env": {
"type": "object"
}
}
}
],
"commands": [
{
"command": "rust-analyzer.syntaxTree",
"title": "Show Syntax Tree",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.expandMacro",
"title": "Expand macro recursively",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.matchingBrace",
"title": "Find matching brace",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.parentModule",
"title": "Locate parent module",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.joinLines",
"title": "Join lines",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.run",
"title": "Run",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.analyzerStatus",
"title": "Status",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.collectGarbage",
"title": "Run garbage collection",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.reload",
"title": "Restart server",
"category": "Rust Analyzer"
}
],
"keybindings": [
{
"command": "rust-analyzer.parentModule",
"key": "ctrl+u",
"when": "editorTextFocus && editorLangId == rust"
},
{
"command": "rust-analyzer.matchingBrace",
"key": "ctrl+shift+m",
"when": "editorTextFocus && editorLangId == rust"
},
{
"command": "rust-analyzer.joinLines",
"key": "ctrl+shift+j",
"when": "editorTextFocus && editorLangId == rust"
},
{
"command": "rust-analyzer.run",
"key": "ctrl+r",
"when": "editorTextFocus && editorLangId == rust"
}
],
"configuration": {
"type": "object",
"title": "Rust Analyzer",
"properties": {
"rust-analyzer.highlightingOn": {
"type": "boolean",
"default": false,
"description": "Highlight Rust code (overrides built-in syntax highlighting)"
},
"rust-analyzer.scopeMappings": {
"type": "object",
"definitions": {},
"properties": {
"comment": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"string": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"keyword": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"keyword.control": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"keyword.unsafe": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"function": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"parameter": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"constant": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"type": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"builtin": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"text": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"attribute": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"literal": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"macro": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"variable": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"variable.mut": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"field": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
},
"module": {
"$ref": "vscode://schemas/textmate-colors#/items/properties/scope"
}
},
"additionalProperties": false,
"description": "Mapping Rust Analyzer scopes to TextMateRule scopes list."
},
"rust-analyzer.rainbowHighlightingOn": {
"type": "boolean",
"default": false,
"description": "When highlighting Rust code, use a unique color per identifier"
},
"rust-analyzer.featureFlags": {
"type": "object",
"default": {},
"description": "Fine grained feature flags to disable annoying features"
},
"rust-analyzer.enableEnhancedTyping": {
"type": "boolean",
"default": true,
"description": "Enables enhanced typing. NOTE: If using a VIM extension, you should set this to false"
},
"rust-analyzer.raLspServerPath": {
"type": [
"string"
],
"default": "ra_lsp_server",
"description": "Path to ra_lsp_server executable"
},
"rust-analyzer.excludeGlobs": {
"type": "array",
"default": [],
"description": "Paths to exclude from analysis"
},
"rust-analyzer.useClientWatching": {
"type": "boolean",
"default": true,
"description": "client provided file watching instead of notify watching."
},
"rust-analyzer.cargo-watch.enable": {
"type": "boolean",
"default": true,
"description": "Run `cargo check` for diagnostics on save"
},
"rust-analyzer.cargo-watch.arguments": {
"type": "array",
"description": "`cargo-watch` arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo watch -x \"check --features=\"shumway,pdf\"\"` )",
"default": []
},
"rust-analyzer.cargo-watch.command": {
"type": "string",
"description": "`cargo-watch` command. (e.g: `clippy` will run as `cargo watch -x clippy` )",
"default": "check"
},
"rust-analyzer.cargo-watch.allTargets": {
"type": "boolean",
"description": "Check all targets and tests (will be passed as `--all-targets`)",
"default": true
},
"rust-analyzer.trace.server": {
"type": "string",
"scope": "window",
"enum": [
"off",
"messages",
"verbose"
],
"enumDescriptions": [
"No traces",
"Error only",
"Full log"
],
"default": "off",
"description": "Trace requests to the ra_lsp_server"
},
"rust-analyzer.lruCapacity": {
"type": "number",
"default": null,
"description": "Number of syntax trees rust-analyzer keeps in memory"
},
"rust-analyzer.displayInlayHints": {
"type": "boolean",
"default": true,
"description": "Display additional type information in the editor"
},
"rust-analyzer.maxInlayHintLength": {
"type": "number",
"default": 20,
"description": "Maximum length for inlay hints"
},
"rust-analyzer.cargoFeatures.noDefaultFeatures": {
"type": "boolean",
"default": false,
"description": "Do not activate the `default` feature"
},
"rust-analyzer.cargoFeatures.allFeatures": {
"type": "boolean",
"default": true,
"description": "Activate all available features"
},
"rust-analyzer.cargoFeatures.features": {
"type": "array",
"default": [],
"description": "List of features to activate"
}
}
},
"problemPatterns": [
{
"name": "rustc",
"patterns": [
{
"regexp": "^(warning|warn|error)(?:\\[(.*?)\\])?: (.*)$",
"severity": 1,
"code": 2,
"message": 3
},
{
"regexp": "^[\\s->=]*(.*?):(\\d*):(\\d*)\\s*$",
"file": 1,
"line": 2,
"column": 3
}
]
},
{
"name": "rustc-json",
"patterns": [
{
"regexp": "^.*\"message\":{\"message\":\"([^\"]*).*?\"file_name\":\"([^\"]+).*?\"line_start\":(\\d+).*?\"line_end\":(\\d+).*?\"column_start\":(\\d+).*?\"column_end\":(\\d+).*}$",
"message": 1,
"file": 2,
"line": 3,
"endLine": 4,
"column": 5,
"endColumn": 6
}
]
}
],
"problemMatchers": [
{
"name": "rustc",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": "$rustc"
},
{
"name": "rustc-json",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": "$rustc-json"
},
{
"name": "rustc-watch",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"background": {
"beginsPattern": "^\\[Running\\b",
"endsPattern": "^\\[Finished running\\b"
},
"pattern": "$rustc"
}
],
"colors": [
{
"id": "ralsp.comment",
"description": "Color for comments",
"defaults": {
"dark": "#6A9955",
"light": "#008000",
"highContrast": "#7CA668"
}
},
{
"id": "ralsp.string",
"description": "Color for strings",
"defaults": {
"dark": "#CE9178",
"light": "#A31515",
"highContrast": "#CE9178"
}
},
{
"id": "ralsp.keyword",
"description": "Color for keywords",
"defaults": {
"dark": "#569cd6",
"light": "#0000FF",
"highContrast": "#569CD6"
}
},
{
"id": "ralsp.keyword.control",
"description": "Color for control keywords",
"defaults": {
"dark": "#C586C0",
"light": "#AF00DB",
"highContrast": "#C586C0"
}
},
{
"id": "ralsp.keyword.unsafe",
"description": "Color for unsafe",
"defaults": {
"dark": "#FF3030",
"light": "#FF1010",
"highContrast": "#FF1010"
}
},
{
"id": "ralsp.function",
"description": "Color for functions",
"defaults": {
"dark": "#DCDCAA",
"light": "#795E26",
"highContrast": "#DCDCAA"
}
},
{
"id": "ralsp.parameter",
"description": "Color for parameters",
"defaults": {
"dark": "#9CDCFE",
"light": "#001080",
"highContrast": "#9CDCFE"
}
},
{
"id": "ralsp.builtin",
"description": "Color for builtins",
"defaults": {
"dark": "#DD6718",
"light": "#DD6718",
"highContrast": "#DD6718"
}
},
{
"id": "ralsp.text",
"description": "Color for text",
"defaults": {
"dark": "#D4D4D4",
"light": "#000000",
"highContrast": "#FFFFFF"
}
},
{
"id": "ralsp.attribute",
"description": "Color for attributes",
"defaults": {
"dark": "#9FE9BF",
"light": "#1F4B1F",
"highContrast": "#108010"
}
},
{
"id": "ralsp.literal",
"description": "Color for literals",
"defaults": {
"dark": "#BECEA8",
"light": "#09885A",
"highContrast": "#B5CEA8"
}
},
{
"id": "ralsp.literal.numeric",
"description": "Color for numeric literals",
"defaults": {
"dark": "#BECEA8",
"light": "#09885A",
"highContrast": "#B5CEA8"
}
},
{
"id": "ralsp.literal.char",
"description": "Color for character literals",
"defaults": {
"dark": "#BECEA8",
"light": "#09885A",
"highContrast": "#B5CEA8"
}
},
{
"id": "ralsp.literal.byte",
"description": "Color for byte literals",
"defaults": {
"dark": "#BECEA8",
"light": "#09885A",
"highContrast": "#B5CEA8"
}
},
{
"id": "ralsp.macro",
"description": "Color for macros",
"defaults": {
"dark": "#BFEBBF",
"light": "#DD6718",
"highContrast": "#ED7718"
}
},
{
"id": "ralsp.constant",
"description": "Color for constants",
"defaults": {
"dark": "#569cd6",
"light": "#267cb6",
"highContrast": "#569cd6"
}
},
{
"id": "ralsp.type",
"description": "Color for other types (traits, aliases..)",
"defaults": {
"dark": "#4EC9B0",
"light": "#267F99",
"highContrast": "#4EC9B0"
}
},
{
"id": "ralsp.type.builtin",
"description": "Color for built-in types (&str, bool, u16, u32)",
"defaults": {
"dark": "#4EC9B0",
"light": "#267F99",
"highContrast": "#4EC9B0"
}
},
{
"id": "ralsp.type.lifetime",
"description": "Color for lifetimes parameters",
"defaults": {
"dark": "#4EC9B0",
"light": "#267F99",
"highContrast": "#4EC9B0"
}
},
{
"id": "ralsp.type.self",
"description": "Color for `Self` param type",
"defaults": {
"dark": "#4EC9B0",
"light": "#267F99",
"highContrast": "#4EC9B0"
}
},
{
"id": "ralsp.type.param",
"description": "Color for type parameters",
"defaults": {
"dark": "#4EC9B0",
"light": "#267F99",
"highContrast": "#4EC9B0"
}
},
{
"id": "ralsp.field",
"description": "Color for fields",
"defaults": {
"dark": "#4EC9B0",
"light": "#267F99",
"highContrast": "#4EC9B0"
}
},
{
"id": "ralsp.variable",
"description": "Color for variables",
"defaults": {
"dark": "#4EC9B0",
"light": "#267F99",
"highContrast": "#4EC9B0"
}
},
{
"id": "ralsp.variable.mut",
"description": "Color for mutable variables",
"defaults": {
"dark": "#4EC9B0",
"light": "#267F99",
"highContrast": "#4EC9B0"
}
},
{
"id": "ralsp.module",
"description": "Color for modules",
"defaults": {
"dark": "#D4D4D4",
"light": "#000000",
"highContrast": "#FFFFFF"
}
},
{
"id": "ralsp.inlayHint",
"description": "Color for inlay hints",
"defaults": {
"dark": "#A0A0A0F0",
"light": "#747474",
"highContrast": "#BEBEBE"
}
}
]
}
}