aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/code/rust.tmGrammar.json47
-rw-r--r--editors/code/src/snippets.ts23
2 files changed, 44 insertions, 26 deletions
diff --git a/editors/code/rust.tmGrammar.json b/editors/code/rust.tmGrammar.json
index 77595aa00..cd4775d27 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": ";",
@@ -307,9 +307,14 @@
307 "block-comments": { 307 "block-comments": {
308 "patterns": [ 308 "patterns": [
309 { 309 {
310 "comment": "block comments", 310 "comment": "empty block comments",
311 "name": "comment.block.rust", 311 "name": "comment.block.rust",
312 "begin": "/\\*(?!\\*)", 312 "match": "/\\*\\*/"
313 },
314 {
315 "comment": "block documentation comments",
316 "name": "comment.block.documentation.rust",
317 "begin": "/\\*\\*",
313 "end": "\\*/", 318 "end": "\\*/",
314 "patterns": [ 319 "patterns": [
315 { 320 {
@@ -318,9 +323,9 @@
318 ] 323 ]
319 }, 324 },
320 { 325 {
321 "comment": "block documentation comments", 326 "comment": "block comments",
322 "name": "comment.block.documentation.rust", 327 "name": "comment.block.rust",
323 "begin": "/\\*\\*", 328 "begin": "/\\*(?!\\*)",
324 "end": "\\*/", 329 "end": "\\*/",
325 "patterns": [ 330 "patterns": [
326 { 331 {
@@ -342,7 +347,7 @@
342 "match": "\\b(const)\\s+([A-Z][A-Za-z0-9_]*)\\b", 347 "match": "\\b(const)\\s+([A-Z][A-Za-z0-9_]*)\\b",
343 "captures": { 348 "captures": {
344 "1": { 349 "1": {
345 "name": "keyword.control.rust" 350 "name": "storage.type.rust"
346 }, 351 },
347 "2": { 352 "2": {
348 "name": "constant.other.caps.rust" 353 "name": "constant.other.caps.rust"
@@ -450,7 +455,7 @@
450 "begin": "\\b(fn)\\s+((?:r#(?!crate|[Ss]elf|super))?[A-Za-z0-9_]+)((\\()|(<))", 455 "begin": "\\b(fn)\\s+((?:r#(?!crate|[Ss]elf|super))?[A-Za-z0-9_]+)((\\()|(<))",
451 "beginCaptures": { 456 "beginCaptures": {
452 "1": { 457 "1": {
453 "name": "keyword.control.fn.rust" 458 "name": "keyword.other.fn.rust"
454 }, 459 },
455 "2": { 460 "2": {
456 "name": "entity.name.function.rust" 461 "name": "entity.name.function.rust"
@@ -643,7 +648,7 @@
643 { 648 {
644 "comment": "control flow keywords", 649 "comment": "control flow keywords",
645 "name": "keyword.control.rust", 650 "name": "keyword.control.rust",
646 "match": "\\b(async|await|break|continue|do|else|for|if|loop|match|move|return|try|where|while|yield)\\b" 651 "match": "\\b(await|break|continue|do|else|for|if|loop|match|return|try|while|yield)\\b"
647 }, 652 },
648 { 653 {
649 "comment": "storage keywords", 654 "comment": "storage keywords",
@@ -658,7 +663,7 @@
658 { 663 {
659 "comment": "other keywords", 664 "comment": "other keywords",
660 "name": "keyword.other.rust", 665 "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" 666 "match": "\\b(as|async|become|box|dyn|move|final|impl|in|override|priv|pub|ref|typeof|union|unsafe|unsized|use|virtual|where)\\b"
662 }, 667 },
663 { 668 {
664 "comment": "fn", 669 "comment": "fn",
@@ -676,11 +681,6 @@
676 "match": "\\bmut\\b" 681 "match": "\\bmut\\b"
677 }, 682 },
678 { 683 {
679 "comment": "math operators",
680 "name": "keyword.operator.math.rust",
681 "match": "(([+%]|(\\*(?!\\w)))(?!=))|(-(?!>))|(/(?!/))"
682 },
683 {
684 "comment": "logical operators", 684 "comment": "logical operators",
685 "name": "keyword.operator.logical.rust", 685 "name": "keyword.operator.logical.rust",
686 "match": "(\\^|\\||\\|\\||&&|<<|>>|!)(?!=)" 686 "match": "(\\^|\\||\\|\\||&&|<<|>>|!)(?!=)"
@@ -693,7 +693,7 @@
693 { 693 {
694 "comment": "assignment operators", 694 "comment": "assignment operators",
695 "name": "keyword.operator.assignment.rust", 695 "name": "keyword.operator.assignment.rust",
696 "match": "(-=|\\*=|/=|%=|\\^=|&=|\\|=|<<=|>>=)" 696 "match": "(\\+=|-=|\\*=|/=|%=|\\^=|&=|\\|=|<<=|>>=)"
697 }, 697 },
698 { 698 {
699 "comment": "single equal", 699 "comment": "single equal",
@@ -706,6 +706,11 @@
706 "match": "(=(=)?(?!>)|!=|<=|(?<!=)>=)" 706 "match": "(=(=)?(?!>)|!=|<=|(?<!=)>=)"
707 }, 707 },
708 { 708 {
709 "comment": "math operators",
710 "name": "keyword.operator.math.rust",
711 "match": "(([+%]|(\\*(?!\\w)))(?!=))|(-(?!>))|(/(?!/))"
712 },
713 {
709 "comment": "less than, greater than (special case)", 714 "comment": "less than, greater than (special case)",
710 "match": "(?:\\b|(?:(\\))|(\\])|(\\})))[ \\t]+([<>])[ \\t]+(?:\\b|(?:(\\()|(\\[)|(\\{)))", 715 "match": "(?:\\b|(?:(\\))|(\\])|(\\})))[ \\t]+([<>])[ \\t]+(?:\\b|(?:(\\()|(\\[)|(\\{)))",
711 "captures": { 716 "captures": {
@@ -1127,7 +1132,7 @@
1127 { 1132 {
1128 "comment": "variables", 1133 "comment": "variables",
1129 "name": "variable.other.rust", 1134 "name": "variable.other.rust",
1130 "match": "\\b(?<!\\.)(?:r#(?!(crate|[Ss]elf|super)))?[a-z0-9_]+\\b" 1135 "match": "\\b(?<!(?<!\\.)\\.)(?:r#(?!(crate|[Ss]elf|super)))?[a-z0-9_]+\\b"
1131 } 1136 }
1132 ] 1137 ]
1133 } 1138 }
diff --git a/editors/code/src/snippets.ts b/editors/code/src/snippets.ts
index 258b49982..fee736e7d 100644
--- a/editors/code/src/snippets.ts
+++ b/editors/code/src/snippets.ts
@@ -3,16 +3,29 @@ import * as vscode from 'vscode';
3import { assert } from './util'; 3import { assert } from './util';
4 4
5export async function applySnippetWorkspaceEdit(edit: vscode.WorkspaceEdit) { 5export async function applySnippetWorkspaceEdit(edit: vscode.WorkspaceEdit) {
6 assert(edit.entries().length === 1, `bad ws edit: ${JSON.stringify(edit)}`); 6 if (edit.entries().length === 1) {
7 const [uri, edits] = edit.entries()[0]; 7 const [uri, edits] = edit.entries()[0];
8 const editor = await editorFromUri(uri);
9 if (editor) await applySnippetTextEdits(editor, edits);
10 return;
11 }
12 for (const [uri, edits] of edit.entries()) {
13 const editor = await editorFromUri(uri);
14 if (editor) await editor.edit((builder) => {
15 for (const indel of edits) {
16 assert(!parseSnippet(indel.newText), `bad ws edit: snippet received with multiple edits: ${JSON.stringify(edit)}`);
17 builder.replace(indel.range, indel.newText);
18 }
19 });
20 }
21}
8 22
23async function editorFromUri(uri: vscode.Uri): Promise<vscode.TextEditor | undefined> {
9 if (vscode.window.activeTextEditor?.document.uri !== uri) { 24 if (vscode.window.activeTextEditor?.document.uri !== uri) {
10 // `vscode.window.visibleTextEditors` only contains editors whose contents are being displayed 25 // `vscode.window.visibleTextEditors` only contains editors whose contents are being displayed
11 await vscode.window.showTextDocument(uri, {}); 26 await vscode.window.showTextDocument(uri, {});
12 } 27 }
13 const editor = vscode.window.visibleTextEditors.find((it) => it.document.uri.toString() === uri.toString()); 28 return vscode.window.visibleTextEditors.find((it) => it.document.uri.toString() === uri.toString());
14 if (!editor) return;
15 await applySnippetTextEdits(editor, edits);
16} 29}
17 30
18export async function applySnippetTextEdits(editor: vscode.TextEditor, edits: vscode.TextEdit[]) { 31export async function applySnippetTextEdits(editor: vscode.TextEditor, edits: vscode.TextEdit[]) {