diff options
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/rust.tmGrammar.json | 32 | ||||
-rw-r--r-- | editors/code/src/client.ts | 17 |
2 files changed, 33 insertions, 16 deletions
diff --git a/editors/code/rust.tmGrammar.json b/editors/code/rust.tmGrammar.json index 77595aa00..b3a10795e 100644 --- a/editors/code/rust.tmGrammar.json +++ b/editors/code/rust.tmGrammar.json | |||
@@ -50,7 +50,7 @@ | |||
50 | { | 50 | { |
51 | "comment": "macro type metavariables", | 51 | "comment": "macro type metavariables", |
52 | "name": "meta.macro.metavariable.type.rust", | 52 | "name": "meta.macro.metavariable.type.rust", |
53 | "match": "(\\$)((crate)|([A-Z][A-Za-z0-9_]*))((:)(block|expr|ident|item|lifetime|literal|meta|pat|path|stmt|tt|ty|vis))?", | 53 | "match": "(\\$)((crate)|([A-Z][A-Za-z0-9_]*))((:)(block|expr|ident|item|lifetime|literal|meta|path?|stmt|tt|ty|vis))?", |
54 | "captures": { | 54 | "captures": { |
55 | "1": { | 55 | "1": { |
56 | "name": "keyword.operator.macro.dollar.rust" | 56 | "name": "keyword.operator.macro.dollar.rust" |
@@ -77,7 +77,7 @@ | |||
77 | { | 77 | { |
78 | "comment": "macro metavariables", | 78 | "comment": "macro metavariables", |
79 | "name": "meta.macro.metavariable.rust", | 79 | "name": "meta.macro.metavariable.rust", |
80 | "match": "(\\$)([a-z][A-Za-z0-9_]*)((:)(block|expr|ident|item|lifetime|literal|meta|pat|path|stmt|tt|ty|vis))?", | 80 | "match": "(\\$)([a-z][A-Za-z0-9_]*)((:)(block|expr|ident|item|lifetime|literal|meta|path?|stmt|tt|ty|vis))?", |
81 | "captures": { | 81 | "captures": { |
82 | "1": { | 82 | "1": { |
83 | "name": "keyword.operator.macro.dollar.rust" | 83 | "name": "keyword.operator.macro.dollar.rust" |
@@ -167,7 +167,7 @@ | |||
167 | "match": "(mod)\\s+((?:r#(?!crate|[Ss]elf|super))?[a-z][A-Za-z0-9_]*)", | 167 | "match": "(mod)\\s+((?:r#(?!crate|[Ss]elf|super))?[a-z][A-Za-z0-9_]*)", |
168 | "captures": { | 168 | "captures": { |
169 | "1": { | 169 | "1": { |
170 | "name": "keyword.control.rust" | 170 | "name": "storage.type.rust" |
171 | }, | 171 | }, |
172 | "2": { | 172 | "2": { |
173 | "name": "entity.name.module.rust" | 173 | "name": "entity.name.module.rust" |
@@ -180,7 +180,7 @@ | |||
180 | "begin": "\\b(extern)\\s+(crate)", | 180 | "begin": "\\b(extern)\\s+(crate)", |
181 | "beginCaptures": { | 181 | "beginCaptures": { |
182 | "1": { | 182 | "1": { |
183 | "name": "keyword.control.rust" | 183 | "name": "storage.type.rust" |
184 | }, | 184 | }, |
185 | "2": { | 185 | "2": { |
186 | "name": "keyword.other.crate.rust" | 186 | "name": "keyword.other.crate.rust" |
@@ -213,7 +213,7 @@ | |||
213 | "begin": "\\b(use)\\s", | 213 | "begin": "\\b(use)\\s", |
214 | "beginCaptures": { | 214 | "beginCaptures": { |
215 | "1": { | 215 | "1": { |
216 | "name": "keyword.control.rust" | 216 | "name": "keyword.other.rust" |
217 | } | 217 | } |
218 | }, | 218 | }, |
219 | "end": ";", | 219 | "end": ";", |
@@ -342,7 +342,7 @@ | |||
342 | "match": "\\b(const)\\s+([A-Z][A-Za-z0-9_]*)\\b", | 342 | "match": "\\b(const)\\s+([A-Z][A-Za-z0-9_]*)\\b", |
343 | "captures": { | 343 | "captures": { |
344 | "1": { | 344 | "1": { |
345 | "name": "keyword.control.rust" | 345 | "name": "storage.type.rust" |
346 | }, | 346 | }, |
347 | "2": { | 347 | "2": { |
348 | "name": "constant.other.caps.rust" | 348 | "name": "constant.other.caps.rust" |
@@ -450,7 +450,7 @@ | |||
450 | "begin": "\\b(fn)\\s+((?:r#(?!crate|[Ss]elf|super))?[A-Za-z0-9_]+)((\\()|(<))", | 450 | "begin": "\\b(fn)\\s+((?:r#(?!crate|[Ss]elf|super))?[A-Za-z0-9_]+)((\\()|(<))", |
451 | "beginCaptures": { | 451 | "beginCaptures": { |
452 | "1": { | 452 | "1": { |
453 | "name": "keyword.control.fn.rust" | 453 | "name": "keyword.other.fn.rust" |
454 | }, | 454 | }, |
455 | "2": { | 455 | "2": { |
456 | "name": "entity.name.function.rust" | 456 | "name": "entity.name.function.rust" |
@@ -643,7 +643,7 @@ | |||
643 | { | 643 | { |
644 | "comment": "control flow keywords", | 644 | "comment": "control flow keywords", |
645 | "name": "keyword.control.rust", | 645 | "name": "keyword.control.rust", |
646 | "match": "\\b(async|await|break|continue|do|else|for|if|loop|match|move|return|try|where|while|yield)\\b" | 646 | "match": "\\b(await|break|continue|do|else|for|if|loop|match|return|try|while|yield)\\b" |
647 | }, | 647 | }, |
648 | { | 648 | { |
649 | "comment": "storage keywords", | 649 | "comment": "storage keywords", |
@@ -658,7 +658,7 @@ | |||
658 | { | 658 | { |
659 | "comment": "other keywords", | 659 | "comment": "other keywords", |
660 | "name": "keyword.other.rust", | 660 | "name": "keyword.other.rust", |
661 | "match": "\\b(as|become|box|dyn|final|impl|in|override|priv|pub|ref|typeof|union|unsafe|unsized|use|virtual)\\b" | 661 | "match": "\\b(as|async|become|box|dyn|move|final|impl|in|override|priv|pub|ref|typeof|union|unsafe|unsized|use|virtual|where)\\b" |
662 | }, | 662 | }, |
663 | { | 663 | { |
664 | "comment": "fn", | 664 | "comment": "fn", |
@@ -676,11 +676,6 @@ | |||
676 | "match": "\\bmut\\b" | 676 | "match": "\\bmut\\b" |
677 | }, | 677 | }, |
678 | { | 678 | { |
679 | "comment": "math operators", | ||
680 | "name": "keyword.operator.math.rust", | ||
681 | "match": "(([+%]|(\\*(?!\\w)))(?!=))|(-(?!>))|(/(?!/))" | ||
682 | }, | ||
683 | { | ||
684 | "comment": "logical operators", | 679 | "comment": "logical operators", |
685 | "name": "keyword.operator.logical.rust", | 680 | "name": "keyword.operator.logical.rust", |
686 | "match": "(\\^|\\||\\|\\||&&|<<|>>|!)(?!=)" | 681 | "match": "(\\^|\\||\\|\\||&&|<<|>>|!)(?!=)" |
@@ -693,7 +688,7 @@ | |||
693 | { | 688 | { |
694 | "comment": "assignment operators", | 689 | "comment": "assignment operators", |
695 | "name": "keyword.operator.assignment.rust", | 690 | "name": "keyword.operator.assignment.rust", |
696 | "match": "(-=|\\*=|/=|%=|\\^=|&=|\\|=|<<=|>>=)" | 691 | "match": "(\\+=|-=|\\*=|/=|%=|\\^=|&=|\\|=|<<=|>>=)" |
697 | }, | 692 | }, |
698 | { | 693 | { |
699 | "comment": "single equal", | 694 | "comment": "single equal", |
@@ -706,6 +701,11 @@ | |||
706 | "match": "(=(=)?(?!>)|!=|<=|(?<!=)>=)" | 701 | "match": "(=(=)?(?!>)|!=|<=|(?<!=)>=)" |
707 | }, | 702 | }, |
708 | { | 703 | { |
704 | "comment": "math operators", | ||
705 | "name": "keyword.operator.math.rust", | ||
706 | "match": "(([+%]|(\\*(?!\\w)))(?!=))|(-(?!>))|(/(?!/))" | ||
707 | }, | ||
708 | { | ||
709 | "comment": "less than, greater than (special case)", | 709 | "comment": "less than, greater than (special case)", |
710 | "match": "(?:\\b|(?:(\\))|(\\])|(\\})))[ \\t]+([<>])[ \\t]+(?:\\b|(?:(\\()|(\\[)|(\\{)))", | 710 | "match": "(?:\\b|(?:(\\))|(\\])|(\\})))[ \\t]+([<>])[ \\t]+(?:\\b|(?:(\\()|(\\[)|(\\{)))", |
711 | "captures": { | 711 | "captures": { |
@@ -1127,7 +1127,7 @@ | |||
1127 | { | 1127 | { |
1128 | "comment": "variables", | 1128 | "comment": "variables", |
1129 | "name": "variable.other.rust", | 1129 | "name": "variable.other.rust", |
1130 | "match": "\\b(?<!\\.)(?:r#(?!(crate|[Ss]elf|super)))?[a-z0-9_]+\\b" | 1130 | "match": "\\b(?<!(?<!\\.)\\.)(?:r#(?!(crate|[Ss]elf|super)))?[a-z0-9_]+\\b" |
1131 | } | 1131 | } |
1132 | ] | 1132 | ] |
1133 | } | 1133 | } |
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 1ba2352ee..d032b45b7 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts | |||
@@ -2,6 +2,7 @@ import * as lc from 'vscode-languageclient/node'; | |||
2 | import * as vscode from 'vscode'; | 2 | import * as vscode from 'vscode'; |
3 | import * as ra from '../src/lsp_ext'; | 3 | import * as ra from '../src/lsp_ext'; |
4 | import * as Is from 'vscode-languageclient/lib/common/utils/is'; | 4 | import * as Is from 'vscode-languageclient/lib/common/utils/is'; |
5 | import { DocumentSemanticsTokensSignature, DocumentSemanticsTokensEditsSignature, DocumentRangeSemanticTokensSignature } from 'vscode-languageclient/lib/common/semanticTokens'; | ||
5 | import { assert } from './util'; | 6 | import { assert } from './util'; |
6 | 7 | ||
7 | function renderCommand(cmd: ra.CommandLink) { | 8 | function renderCommand(cmd: ra.CommandLink) { |
@@ -18,6 +19,13 @@ function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownStri | |||
18 | return result; | 19 | return result; |
19 | } | 20 | } |
20 | 21 | ||
22 | // Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576 | ||
23 | async function semanticHighlightingWorkaround<R, F extends (...args: any[]) => vscode.ProviderResult<R>>(next: F, ...args: Parameters<F>): Promise<R> { | ||
24 | const res = await next(...args); | ||
25 | if (res == null) throw new Error('busy'); | ||
26 | return res; | ||
27 | } | ||
28 | |||
21 | export function createClient(serverPath: string, cwd: string): lc.LanguageClient { | 29 | export function createClient(serverPath: string, cwd: string): lc.LanguageClient { |
22 | // '.' Is the fallback if no folder is open | 30 | // '.' Is the fallback if no folder is open |
23 | // TODO?: Workspace folders support Uri's (eg: file://test.txt). | 31 | // TODO?: Workspace folders support Uri's (eg: file://test.txt). |
@@ -41,6 +49,15 @@ export function createClient(serverPath: string, cwd: string): lc.LanguageClient | |||
41 | diagnosticCollectionName: "rustc", | 49 | diagnosticCollectionName: "rustc", |
42 | traceOutputChannel, | 50 | traceOutputChannel, |
43 | middleware: { | 51 | middleware: { |
52 | provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken, next: DocumentSemanticsTokensSignature): vscode.ProviderResult<vscode.SemanticTokens> { | ||
53 | return semanticHighlightingWorkaround(next, document, token); | ||
54 | }, | ||
55 | provideDocumentSemanticTokensEdits(document: vscode.TextDocument, previousResultId: string, token: vscode.CancellationToken, next: DocumentSemanticsTokensEditsSignature): vscode.ProviderResult<vscode.SemanticTokensEdits | vscode.SemanticTokens> { | ||
56 | return semanticHighlightingWorkaround(next, document, previousResultId, token); | ||
57 | }, | ||
58 | provideDocumentRangeSemanticTokens(document: vscode.TextDocument, range: vscode.Range, token: vscode.CancellationToken, next: DocumentRangeSemanticTokensSignature): vscode.ProviderResult<vscode.SemanticTokens> { | ||
59 | return semanticHighlightingWorkaround(next, document, range, token); | ||
60 | }, | ||
44 | async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, _next: lc.ProvideHoverSignature) { | 61 | async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, _next: lc.ProvideHoverSignature) { |
45 | return client.sendRequest(lc.HoverRequest.type, client.code2ProtocolConverter.asTextDocumentPositionParams(document, position), token).then( | 62 | return client.sendRequest(lc.HoverRequest.type, client.code2ProtocolConverter.asTextDocumentPositionParams(document, position), token).then( |
46 | (result) => { | 63 | (result) => { |