diff options
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/icon.png | bin | 17918 -> 15341 bytes | |||
-rw-r--r-- | editors/code/package-lock.json | 30 | ||||
-rw-r--r-- | editors/code/package.json | 4 | ||||
-rw-r--r-- | editors/code/rollup.config.js | 2 | ||||
-rw-r--r-- | editors/code/src/commands/index.ts | 13 | ||||
-rw-r--r-- | editors/code/src/config.ts | 16 | ||||
-rw-r--r-- | editors/code/src/inlay_hints.ts | 51 | ||||
-rw-r--r-- | editors/code/src/main.ts | 1 | ||||
-rw-r--r-- | editors/code/src/status_display.ts | 36 |
9 files changed, 96 insertions, 57 deletions
diff --git a/editors/code/icon.png b/editors/code/icon.png index 992aee4bd..072090c6f 100644 --- a/editors/code/icon.png +++ b/editors/code/icon.png | |||
Binary files differ | |||
diff --git a/editors/code/package-lock.json b/editors/code/package-lock.json index 746dd4bc3..05c57c7ff 100644 --- a/editors/code/package-lock.json +++ b/editors/code/package-lock.json | |||
@@ -889,32 +889,32 @@ | |||
889 | } | 889 | } |
890 | }, | 890 | }, |
891 | "vscode-jsonrpc": { | 891 | "vscode-jsonrpc": { |
892 | "version": "5.0.0-next.7", | 892 | "version": "5.0.0", |
893 | "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-5.0.0-next.7.tgz", | 893 | "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-5.0.0.tgz", |
894 | "integrity": "sha512-DZuEyxaWuA0srFh9kKu2fudVG6d5CJhte3OW2ILM8lZqpHjI+/D2byrowFd0YmEbyQB2nh0yqg0sa1mhxOtivA==" | 894 | "integrity": "sha512-QeAniC/xTWauVQgyNgEqNJ0Qm/Jw8QySGRQhRFPwb8c4FPp9k6QNgJp0ayXWws5qhdaHkiXkGPlzjOPZFQQKLw==" |
895 | }, | 895 | }, |
896 | "vscode-languageclient": { | 896 | "vscode-languageclient": { |
897 | "version": "6.0.0-next.10", | 897 | "version": "6.0.0", |
898 | "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-6.0.0-next.10.tgz", | 898 | "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-6.0.0.tgz", |
899 | "integrity": "sha512-xJ9KNJnHfGIMz7ewuXijtUTje1Tc2fpuyYS/DHZI/MBwYRLp7L38KnivvYJmUICdPnrQTSvPSWKbjlwWhMlKwQ==", | 899 | "integrity": "sha512-6MDksAP79GRbcHFsXS6ndo12s0m/h7eNdS/IanRgWxaezqB4a4KzHIHrE0bE+nSFB+snaSToGs1bxnPeKdO5fQ==", |
900 | "requires": { | 900 | "requires": { |
901 | "semver": "^6.3.0", | 901 | "semver": "^6.3.0", |
902 | "vscode-languageserver-protocol": "^3.15.0-next.15" | 902 | "vscode-languageserver-protocol": "^3.15.0" |
903 | } | 903 | } |
904 | }, | 904 | }, |
905 | "vscode-languageserver-protocol": { | 905 | "vscode-languageserver-protocol": { |
906 | "version": "3.15.0-next.15", | 906 | "version": "3.15.0", |
907 | "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.15.0-next.15.tgz", | 907 | "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.15.0.tgz", |
908 | "integrity": "sha512-c1f47pxAtUE+gYTGLoySVA+nBUbPtz8NMOLOB69RiTBQobSJBO1XXKB8TXz8BSxpG5T8qRXeEm2vXrM/eepYKg==", | 908 | "integrity": "sha512-PZEopQzHR3Lo422HeDxCpGN0sYz+kReO+du3F/AcFT1cCPunoVsDJv7ikEolFRKEn+hEIZiAaIX4yoSZ+ip5Nw==", |
909 | "requires": { | 909 | "requires": { |
910 | "vscode-jsonrpc": "^5.0.0-next.7", | 910 | "vscode-jsonrpc": "^5.0.0", |
911 | "vscode-languageserver-types": "^3.15.0-next.10" | 911 | "vscode-languageserver-types": "3.15.0" |
912 | } | 912 | } |
913 | }, | 913 | }, |
914 | "vscode-languageserver-types": { | 914 | "vscode-languageserver-types": { |
915 | "version": "3.15.0-next.10", | 915 | "version": "3.15.0", |
916 | "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.15.0-next.10.tgz", | 916 | "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.15.0.tgz", |
917 | "integrity": "sha512-s9Psd+0sQVkH4o1U7hwTNJRuXQQgFvGVZIim7Wb44tcq54rZou3kJKCtdFEm0aHUuYxIrMPYrzuh1jlqCbRegw==" | 917 | "integrity": "sha512-AXteNagMhBWnZ6gNN0UB4HTiD/7TajgfHl6jaM6O7qz3zDJw0H3Jf83w05phihnBRCML+K6Ockh8f8bL0OObPw==" |
918 | }, | 918 | }, |
919 | "wrappy": { | 919 | "wrappy": { |
920 | "version": "1.0.2", | 920 | "version": "1.0.2", |
diff --git a/editors/code/package.json b/editors/code/package.json index fe2948861..d4c310734 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -25,7 +25,7 @@ | |||
25 | "dependencies": { | 25 | "dependencies": { |
26 | "jsonc-parser": "^2.1.0", | 26 | "jsonc-parser": "^2.1.0", |
27 | "seedrandom": "^3.0.5", | 27 | "seedrandom": "^3.0.5", |
28 | "vscode-languageclient": "^6.0.0-next.10" | 28 | "vscode-languageclient": "^6.0.0" |
29 | }, | 29 | }, |
30 | "devDependencies": { | 30 | "devDependencies": { |
31 | "@rollup/plugin-commonjs": "^11.0.0", | 31 | "@rollup/plugin-commonjs": "^11.0.0", |
@@ -228,7 +228,7 @@ | |||
228 | "rust-analyzer.displayInlayHints": { | 228 | "rust-analyzer.displayInlayHints": { |
229 | "type": "boolean", | 229 | "type": "boolean", |
230 | "default": true, | 230 | "default": true, |
231 | "description": "Display additional type information in the editor" | 231 | "description": "Display additional type and parameter information in the editor" |
232 | }, | 232 | }, |
233 | "rust-analyzer.maxInlayHintLength": { | 233 | "rust-analyzer.maxInlayHintLength": { |
234 | "type": "number", | 234 | "type": "number", |
diff --git a/editors/code/rollup.config.js b/editors/code/rollup.config.js index 14fb9e085..de6a3b2b7 100644 --- a/editors/code/rollup.config.js +++ b/editors/code/rollup.config.js | |||
@@ -13,7 +13,7 @@ export default { | |||
13 | commonjs({ | 13 | commonjs({ |
14 | namedExports: { | 14 | namedExports: { |
15 | // squelch missing import warnings | 15 | // squelch missing import warnings |
16 | 'vscode-languageclient': ['CreateFile', 'RenameFile', 'ErrorCodes'] | 16 | 'vscode-languageclient': ['CreateFile', 'RenameFile', 'ErrorCodes', 'WorkDoneProgress', 'WorkDoneProgressBegin', 'WorkDoneProgressReport', 'WorkDoneProgressEnd'] |
17 | } | 17 | } |
18 | }) | 18 | }) |
19 | ], | 19 | ], |
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index 9a1697dcb..dc075aa82 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts | |||
@@ -39,6 +39,18 @@ function applySourceChange(ctx: Ctx): Cmd { | |||
39 | }; | 39 | }; |
40 | } | 40 | } |
41 | 41 | ||
42 | function selectAndApplySourceChange(ctx: Ctx): Cmd { | ||
43 | return async (changes: sourceChange.SourceChange[]) => { | ||
44 | if (changes.length === 1) { | ||
45 | await sourceChange.applySourceChange(ctx, changes[0]); | ||
46 | } else if (changes.length > 0) { | ||
47 | const selectedChange = await vscode.window.showQuickPick(changes); | ||
48 | if (!selectedChange) return; | ||
49 | await sourceChange.applySourceChange(ctx, selectedChange); | ||
50 | } | ||
51 | }; | ||
52 | } | ||
53 | |||
42 | function reload(ctx: Ctx): Cmd { | 54 | function reload(ctx: Ctx): Cmd { |
43 | return async () => { | 55 | return async () => { |
44 | vscode.window.showInformationMessage('Reloading rust-analyzer...'); | 56 | vscode.window.showInformationMessage('Reloading rust-analyzer...'); |
@@ -59,5 +71,6 @@ export { | |||
59 | runSingle, | 71 | runSingle, |
60 | showReferences, | 72 | showReferences, |
61 | applySourceChange, | 73 | applySourceChange, |
74 | selectAndApplySourceChange, | ||
62 | reload | 75 | reload |
63 | }; | 76 | }; |
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index ec2790b63..fc21c8813 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -42,6 +42,7 @@ export class Config { | |||
42 | 42 | ||
43 | private prevEnhancedTyping: null | boolean = null; | 43 | private prevEnhancedTyping: null | boolean = null; |
44 | private prevCargoFeatures: null | CargoFeatures = null; | 44 | private prevCargoFeatures: null | CargoFeatures = null; |
45 | private prevCargoWatchOptions: null | CargoWatchOptions = null; | ||
45 | 46 | ||
46 | constructor(ctx: vscode.ExtensionContext) { | 47 | constructor(ctx: vscode.ExtensionContext) { |
47 | vscode.workspace.onDidChangeConfiguration(_ => this.refresh(), ctx.subscriptions); | 48 | vscode.workspace.onDidChangeConfiguration(_ => this.refresh(), ctx.subscriptions); |
@@ -174,6 +175,21 @@ export class Config { | |||
174 | } | 175 | } |
175 | this.prevCargoFeatures = { ...this.cargoFeatures }; | 176 | this.prevCargoFeatures = { ...this.cargoFeatures }; |
176 | 177 | ||
178 | if (this.prevCargoWatchOptions !== null) { | ||
179 | const changed = | ||
180 | this.cargoWatchOptions.enable !== this.prevCargoWatchOptions.enable || | ||
181 | this.cargoWatchOptions.command !== this.prevCargoWatchOptions.command || | ||
182 | this.cargoWatchOptions.allTargets !== this.prevCargoWatchOptions.allTargets || | ||
183 | this.cargoWatchOptions.arguments.length !== this.prevCargoWatchOptions.arguments.length || | ||
184 | this.cargoWatchOptions.arguments.some( | ||
185 | (v, i) => v !== this.prevCargoWatchOptions!.arguments[i], | ||
186 | ); | ||
187 | if (changed) { | ||
188 | requireReloadMessage = 'Changing cargo-watch options requires a reload'; | ||
189 | } | ||
190 | } | ||
191 | this.prevCargoWatchOptions = { ...this.cargoWatchOptions }; | ||
192 | |||
177 | if (requireReloadMessage !== null) { | 193 | if (requireReloadMessage !== null) { |
178 | const reloadAction = 'Reload now'; | 194 | const reloadAction = 'Reload now'; |
179 | vscode.window | 195 | vscode.window |
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index 078d18f0f..6357e44f1 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts | |||
@@ -38,6 +38,12 @@ const typeHintDecorationType = vscode.window.createTextEditorDecorationType({ | |||
38 | }, | 38 | }, |
39 | }); | 39 | }); |
40 | 40 | ||
41 | const parameterHintDecorationType = vscode.window.createTextEditorDecorationType({ | ||
42 | before: { | ||
43 | color: new vscode.ThemeColor('rust_analyzer.inlayHint'), | ||
44 | } | ||
45 | }); | ||
46 | |||
41 | class HintsUpdater { | 47 | class HintsUpdater { |
42 | private pending: Map<string, vscode.CancellationTokenSource> = new Map(); | 48 | private pending: Map<string, vscode.CancellationTokenSource> = new Map(); |
43 | private ctx: Ctx; | 49 | private ctx: Ctx; |
@@ -55,7 +61,10 @@ class HintsUpdater { | |||
55 | if (this.enabled) { | 61 | if (this.enabled) { |
56 | await this.refresh(); | 62 | await this.refresh(); |
57 | } else { | 63 | } else { |
58 | this.allEditors.forEach(it => this.setDecorations(it, [])); | 64 | this.allEditors.forEach(it => { |
65 | this.setTypeDecorations(it, []); | ||
66 | this.setParameterDecorations(it, []); | ||
67 | }); | ||
59 | } | 68 | } |
60 | } | 69 | } |
61 | 70 | ||
@@ -68,15 +77,27 @@ class HintsUpdater { | |||
68 | private async refreshEditor(editor: vscode.TextEditor): Promise<void> { | 77 | private async refreshEditor(editor: vscode.TextEditor): Promise<void> { |
69 | const newHints = await this.queryHints(editor.document.uri.toString()); | 78 | const newHints = await this.queryHints(editor.document.uri.toString()); |
70 | if (newHints == null) return; | 79 | if (newHints == null) return; |
71 | const newDecorations = newHints.map(hint => ({ | 80 | const newTypeDecorations = newHints.filter(hint => hint.kind === 'TypeHint') |
72 | range: hint.range, | 81 | .map(hint => ({ |
73 | renderOptions: { | 82 | range: hint.range, |
74 | after: { | 83 | renderOptions: { |
75 | contentText: `: ${hint.label}`, | 84 | after: { |
85 | contentText: `: ${hint.label}`, | ||
86 | }, | ||
76 | }, | 87 | }, |
77 | }, | 88 | })); |
78 | })); | 89 | this.setTypeDecorations(editor, newTypeDecorations); |
79 | this.setDecorations(editor, newDecorations); | 90 | |
91 | const newParameterDecorations = newHints.filter(hint => hint.kind === 'ParameterHint') | ||
92 | .map(hint => ({ | ||
93 | range: hint.range, | ||
94 | renderOptions: { | ||
95 | before: { | ||
96 | contentText: `${hint.label}: `, | ||
97 | }, | ||
98 | }, | ||
99 | })); | ||
100 | this.setParameterDecorations(editor, newParameterDecorations); | ||
80 | } | 101 | } |
81 | 102 | ||
82 | private get allEditors(): vscode.TextEditor[] { | 103 | private get allEditors(): vscode.TextEditor[] { |
@@ -85,7 +106,7 @@ class HintsUpdater { | |||
85 | ); | 106 | ); |
86 | } | 107 | } |
87 | 108 | ||
88 | private setDecorations( | 109 | private setTypeDecorations( |
89 | editor: vscode.TextEditor, | 110 | editor: vscode.TextEditor, |
90 | decorations: vscode.DecorationOptions[], | 111 | decorations: vscode.DecorationOptions[], |
91 | ) { | 112 | ) { |
@@ -95,6 +116,16 @@ class HintsUpdater { | |||
95 | ); | 116 | ); |
96 | } | 117 | } |
97 | 118 | ||
119 | private setParameterDecorations( | ||
120 | editor: vscode.TextEditor, | ||
121 | decorations: vscode.DecorationOptions[], | ||
122 | ) { | ||
123 | editor.setDecorations( | ||
124 | parameterHintDecorationType, | ||
125 | this.enabled ? decorations : [], | ||
126 | ); | ||
127 | } | ||
128 | |||
98 | private async queryHints(documentUri: string): Promise<InlayHint[] | null> { | 129 | private async queryHints(documentUri: string): Promise<InlayHint[] | null> { |
99 | let client = this.ctx.client; | 130 | let client = this.ctx.client; |
100 | if (!client) return null; | 131 | if (!client) return null; |
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 430ad31b4..0494ccf63 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -26,6 +26,7 @@ export async function activate(context: vscode.ExtensionContext) { | |||
26 | ctx.registerCommand('runSingle', commands.runSingle); | 26 | ctx.registerCommand('runSingle', commands.runSingle); |
27 | ctx.registerCommand('showReferences', commands.showReferences); | 27 | ctx.registerCommand('showReferences', commands.showReferences); |
28 | ctx.registerCommand('applySourceChange', commands.applySourceChange); | 28 | ctx.registerCommand('applySourceChange', commands.applySourceChange); |
29 | ctx.registerCommand('selectAndApplySourceChange', commands.selectAndApplySourceChange); | ||
29 | 30 | ||
30 | if (ctx.config.enableEnhancedTyping) { | 31 | if (ctx.config.enableEnhancedTyping) { |
31 | ctx.overrideCommand('type', commands.onEnter); | 32 | ctx.overrideCommand('type', commands.onEnter); |
diff --git a/editors/code/src/status_display.ts b/editors/code/src/status_display.ts index 371a2f3bb..c75fddf9d 100644 --- a/editors/code/src/status_display.ts +++ b/editors/code/src/status_display.ts | |||
@@ -1,5 +1,7 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | 2 | ||
3 | import { WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressReport, WorkDoneProgressEnd } from 'vscode-languageclient'; | ||
4 | |||
3 | import { Ctx } from './ctx'; | 5 | import { Ctx } from './ctx'; |
4 | 6 | ||
5 | const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; | 7 | const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; |
@@ -8,7 +10,7 @@ export function activateStatusDisplay(ctx: Ctx) { | |||
8 | const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command); | 10 | const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command); |
9 | ctx.pushCleanup(statusDisplay); | 11 | ctx.pushCleanup(statusDisplay); |
10 | ctx.onDidRestart(client => { | 12 | ctx.onDidRestart(client => { |
11 | client.onNotification('$/progress', params => statusDisplay.handleProgressNotification(params)); | 13 | client.onProgress(WorkDoneProgress.type, 'rustAnalyzer/cargoWatcher', params => statusDisplay.handleProgressNotification(params)); |
12 | }); | 14 | }); |
13 | } | 15 | } |
14 | 16 | ||
@@ -63,20 +65,15 @@ class StatusDisplay implements vscode.Disposable { | |||
63 | this.statusBarItem.dispose(); | 65 | this.statusBarItem.dispose(); |
64 | } | 66 | } |
65 | 67 | ||
66 | handleProgressNotification(params: ProgressParams) { | 68 | handleProgressNotification(params: WorkDoneProgressBegin | WorkDoneProgressReport | WorkDoneProgressEnd) { |
67 | const { token, value } = params; | 69 | switch (params.kind) { |
68 | if (token !== 'rustAnalyzer/cargoWatcher') { | ||
69 | return; | ||
70 | } | ||
71 | |||
72 | switch (value.kind) { | ||
73 | case 'begin': | 70 | case 'begin': |
74 | this.show(); | 71 | this.show(); |
75 | break; | 72 | break; |
76 | 73 | ||
77 | case 'report': | 74 | case 'report': |
78 | if (value.message) { | 75 | if (params.message) { |
79 | this.packageName = value.message; | 76 | this.packageName = params.message; |
80 | } | 77 | } |
81 | break; | 78 | break; |
82 | 79 | ||
@@ -90,22 +87,3 @@ class StatusDisplay implements vscode.Disposable { | |||
90 | return spinnerFrames[(this.i = ++this.i % spinnerFrames.length)]; | 87 | return spinnerFrames[(this.i = ++this.i % spinnerFrames.length)]; |
91 | } | 88 | } |
92 | } | 89 | } |
93 | |||
94 | // FIXME: Replace this once vscode-languageclient is updated to LSP 3.15 | ||
95 | interface ProgressParams { | ||
96 | token: string; | ||
97 | value: WorkDoneProgress; | ||
98 | } | ||
99 | |||
100 | enum WorkDoneProgressKind { | ||
101 | Begin = 'begin', | ||
102 | Report = 'report', | ||
103 | End = 'end', | ||
104 | } | ||
105 | |||
106 | interface WorkDoneProgress { | ||
107 | kind: WorkDoneProgressKind; | ||
108 | message?: string; | ||
109 | cancelable?: boolean; | ||
110 | percentage?: string; | ||
111 | } | ||