aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/code/.eslintrc.js5
-rw-r--r--editors/code/src/client.ts4
-rw-r--r--editors/code/src/commands.ts12
-rw-r--r--editors/code/src/debug.ts12
-rw-r--r--editors/code/src/inlay_hints.ts2
-rw-r--r--editors/code/src/main.ts13
-rw-r--r--editors/code/src/run.ts7
-rw-r--r--editors/code/src/snippets.ts4
8 files changed, 33 insertions, 26 deletions
diff --git a/editors/code/.eslintrc.js b/editors/code/.eslintrc.js
index c6bf410f4..b145330a0 100644
--- a/editors/code/.eslintrc.js
+++ b/editors/code/.eslintrc.js
@@ -14,7 +14,7 @@ module.exports = {
14 "rules": { 14 "rules": {
15 "camelcase": ["error"], 15 "camelcase": ["error"],
16 "eqeqeq": ["error", "always", { "null": "ignore" }], 16 "eqeqeq": ["error", "always", { "null": "ignore" }],
17 "no-console": ["error"], 17 "no-console": ["error", { allow: ["warn", "error"] }],
18 "prefer-const": "error", 18 "prefer-const": "error",
19 "@typescript-eslint/member-delimiter-style": [ 19 "@typescript-eslint/member-delimiter-style": [
20 "error", 20 "error",
@@ -33,6 +33,7 @@ module.exports = {
33 "error", 33 "error",
34 "always" 34 "always"
35 ], 35 ],
36 "@typescript-eslint/no-unnecessary-type-assertion": "error" 36 "@typescript-eslint/no-unnecessary-type-assertion": "error",
37 "@typescript-eslint/no-floating-promises": "error"
37 } 38 }
38}; 39};
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 539e487ec..aec5c70c0 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -11,7 +11,7 @@ export interface Env {
11} 11}
12 12
13function renderCommand(cmd: ra.CommandLink) { 13function renderCommand(cmd: ra.CommandLink) {
14 return `[${cmd.title}](command:${cmd.command}?${encodeURIComponent(JSON.stringify(cmd.arguments))} '${cmd.tooltip!}')`; 14 return `[${cmd.title}](command:${cmd.command}?${encodeURIComponent(JSON.stringify(cmd.arguments))} '${cmd.tooltip}')`;
15} 15}
16 16
17function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownString { 17function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownString {
@@ -138,7 +138,7 @@ export function createClient(serverPath: string, cwd: string, extraEnv: Env): lc
138 command: "rust-analyzer.applyActionGroup", 138 command: "rust-analyzer.applyActionGroup",
139 title: "", 139 title: "",
140 arguments: [items.map((item) => { 140 arguments: [items.map((item) => {
141 return { label: item.title, arguments: item.command!!.arguments!![0] }; 141 return { label: item.title, arguments: item.command!.arguments![0] };
142 })], 142 })],
143 }; 143 };
144 144
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index e3a23c0d2..283b9a160 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -125,7 +125,7 @@ export function joinLines(ctx: Ctx): Cmd {
125 ranges: editor.selections.map((it) => client.code2ProtocolConverter.asRange(it)), 125 ranges: editor.selections.map((it) => client.code2ProtocolConverter.asRange(it)),
126 textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document), 126 textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document),
127 }); 127 });
128 editor.edit((builder) => { 128 await editor.edit((builder) => {
129 client.protocol2CodeConverter.asTextEdits(items).forEach((edit: any) => { 129 client.protocol2CodeConverter.asTextEdits(items).forEach((edit: any) => {
130 builder.replace(edit.range, edit.newText); 130 builder.replace(edit.range, edit.newText);
131 }); 131 });
@@ -236,7 +236,7 @@ export function ssr(ctx: Ctx): Cmd {
236 const request = await vscode.window.showInputBox(options); 236 const request = await vscode.window.showInputBox(options);
237 if (!request) return; 237 if (!request) return;
238 238
239 vscode.window.withProgress({ 239 await vscode.window.withProgress({
240 location: vscode.ProgressLocation.Notification, 240 location: vscode.ProgressLocation.Notification,
241 title: "Structured search replace in progress...", 241 title: "Structured search replace in progress...",
242 cancellable: false, 242 cancellable: false,
@@ -457,10 +457,10 @@ export function reloadWorkspace(ctx: Ctx): Cmd {
457} 457}
458 458
459export function showReferences(ctx: Ctx): Cmd { 459export function showReferences(ctx: Ctx): Cmd {
460 return (uri: string, position: lc.Position, locations: lc.Location[]) => { 460 return async (uri: string, position: lc.Position, locations: lc.Location[]) => {
461 const client = ctx.client; 461 const client = ctx.client;
462 if (client) { 462 if (client) {
463 vscode.commands.executeCommand( 463 await vscode.commands.executeCommand(
464 'editor.action.showReferences', 464 'editor.action.showReferences',
465 vscode.Uri.parse(uri), 465 vscode.Uri.parse(uri),
466 client.protocol2CodeConverter.asPosition(position), 466 client.protocol2CodeConverter.asPosition(position),
@@ -474,7 +474,7 @@ export function applyActionGroup(_ctx: Ctx): Cmd {
474 return async (actions: { label: string; arguments: lc.CodeAction }[]) => { 474 return async (actions: { label: string; arguments: lc.CodeAction }[]) => {
475 const selectedAction = await vscode.window.showQuickPick(actions); 475 const selectedAction = await vscode.window.showQuickPick(actions);
476 if (!selectedAction) return; 476 if (!selectedAction) return;
477 vscode.commands.executeCommand( 477 await vscode.commands.executeCommand(
478 'rust-analyzer.resolveCodeAction', 478 'rust-analyzer.resolveCodeAction',
479 selectedAction.arguments, 479 selectedAction.arguments,
480 ); 480 );
@@ -510,7 +510,7 @@ export function openDocs(ctx: Ctx): Cmd {
510 const doclink = await client.sendRequest(ra.openDocs, { position, textDocument }); 510 const doclink = await client.sendRequest(ra.openDocs, { position, textDocument });
511 511
512 if (doclink != null) { 512 if (doclink != null) {
513 vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(doclink)); 513 await vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(doclink));
514 } 514 }
515 }; 515 };
516 516
diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts
index 925126a16..3889a2773 100644
--- a/editors/code/src/debug.ts
+++ b/editors/code/src/debug.ts
@@ -77,7 +77,7 @@ async function getDebugConfiguration(ctx: Ctx, runnable: ra.Runnable): Promise<v
77 } 77 }
78 78
79 if (!debugEngine) { 79 if (!debugEngine) {
80 vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)` 80 await vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)`
81 + ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension for debugging.`); 81 + ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension for debugging.`);
82 return; 82 return;
83 } 83 }
@@ -86,12 +86,14 @@ async function getDebugConfiguration(ctx: Ctx, runnable: ra.Runnable): Promise<v
86 if (ctx.config.debug.openDebugPane) { 86 if (ctx.config.debug.openDebugPane) {
87 debugOutput.show(true); 87 debugOutput.show(true);
88 } 88 }
89 89 // folder exists or RA is not active.
90 const isMultiFolderWorkspace = vscode.workspace.workspaceFolders!.length > 1; 90 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
91 const firstWorkspace = vscode.workspace.workspaceFolders![0]; // folder exists or RA is not active. 91 const workspaceFolders = vscode.workspace.workspaceFolders!;
92 const isMultiFolderWorkspace = workspaceFolders.length > 1;
93 const firstWorkspace = workspaceFolders[0];
92 const workspace = !isMultiFolderWorkspace || !runnable.args.workspaceRoot ? 94 const workspace = !isMultiFolderWorkspace || !runnable.args.workspaceRoot ?
93 firstWorkspace : 95 firstWorkspace :
94 vscode.workspace.workspaceFolders!.find(w => runnable.args.workspaceRoot?.includes(w.uri.fsPath)) || firstWorkspace; 96 workspaceFolders.find(w => runnable.args.workspaceRoot?.includes(w.uri.fsPath)) || firstWorkspace;
95 97
96 const wsFolder = path.normalize(workspace.uri.fsPath); 98 const wsFolder = path.normalize(workspace.uri.fsPath);
97 const workspaceQualifier = isMultiFolderWorkspace ? `:${workspace.name}` : ''; 99 const workspaceQualifier = isMultiFolderWorkspace ? `:${workspace.name}` : '';
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts
index 38eb1c15b..61db6b8d0 100644
--- a/editors/code/src/inlay_hints.ts
+++ b/editors/code/src/inlay_hints.ts
@@ -36,7 +36,7 @@ export function activateInlayHints(ctx: Ctx) {
36 maybeUpdater.onConfigChange, maybeUpdater, ctx.subscriptions 36 maybeUpdater.onConfigChange, maybeUpdater, ctx.subscriptions
37 ); 37 );
38 38
39 maybeUpdater.onConfigChange(); 39 maybeUpdater.onConfigChange().catch(console.error);
40} 40}
41 41
42const typeHints = createHintStyle("type"); 42const typeHints = createHintStyle("type");
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 43cae5c7f..d18d6c8a9 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -76,7 +76,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
76 // This a horribly, horribly wrong way to deal with this problem. 76 // This a horribly, horribly wrong way to deal with this problem.
77 ctx = await Ctx.create(config, context, serverPath, workspaceFolder.uri.fsPath); 77 ctx = await Ctx.create(config, context, serverPath, workspaceFolder.uri.fsPath);
78 78
79 setContextValue(RUST_PROJECT_CONTEXT_NAME, true); 79 await setContextValue(RUST_PROJECT_CONTEXT_NAME, true);
80 80
81 // Commands which invokes manually via command palette, shortcut, etc. 81 // Commands which invokes manually via command palette, shortcut, etc.
82 82
@@ -143,7 +143,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
143} 143}
144 144
145export async function deactivate() { 145export async function deactivate() {
146 setContextValue(RUST_PROJECT_CONTEXT_NAME, undefined); 146 await setContextValue(RUST_PROJECT_CONTEXT_NAME, undefined);
147 await ctx?.client.stop(); 147 await ctx?.client.stop();
148 ctx = undefined; 148 ctx = undefined;
149} 149}
@@ -184,10 +184,10 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
184 184
185 const release = await downloadWithRetryDialog(state, async () => { 185 const release = await downloadWithRetryDialog(state, async () => {
186 return await fetchRelease("nightly", state.githubToken); 186 return await fetchRelease("nightly", state.githubToken);
187 }).catch((e) => { 187 }).catch(async (e) => {
188 log.error(e); 188 log.error(e);
189 if (state.releaseId === undefined) { // Show error only for the initial download 189 if (state.releaseId === undefined) { // Show error only for the initial download
190 vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`); 190 await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`);
191 } 191 }
192 return undefined; 192 return undefined;
193 }); 193 });
@@ -299,7 +299,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
299 }; 299 };
300 const platform = platforms[`${process.arch} ${process.platform}`]; 300 const platform = platforms[`${process.arch} ${process.platform}`];
301 if (platform === undefined) { 301 if (platform === undefined) {
302 vscode.window.showErrorMessage( 302 await vscode.window.showErrorMessage(
303 "Unfortunately we don't ship binaries for your platform yet. " + 303 "Unfortunately we don't ship binaries for your platform yet. " +
304 "You need to manually clone rust-analyzer repository and " + 304 "You need to manually clone rust-analyzer repository and " +
305 "run `cargo xtask install --server` to build the language server from sources. " + 305 "run `cargo xtask install --server` to build the language server from sources. " +
@@ -434,6 +434,7 @@ function warnAboutExtensionConflicts() {
434 vscode.window.showWarningMessage( 434 vscode.window.showWarningMessage(
435 `You have both the ${fst[0]} (${fst[1]}) and ${sec[0]} (${sec[1]}) ` + 435 `You have both the ${fst[0]} (${fst[1]}) and ${sec[0]} (${sec[1]}) ` +
436 "plugins enabled. These are known to conflict and cause various functions of " + 436 "plugins enabled. These are known to conflict and cause various functions of " +
437 "both plugins to not work correctly. You should disable one of them.", "Got it"); 437 "both plugins to not work correctly. You should disable one of them.", "Got it")
438 .then(() => { }, console.error);
438 }; 439 };
439} 440}
diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts
index f42baed16..138e3f686 100644
--- a/editors/code/src/run.ts
+++ b/editors/code/src/run.ts
@@ -45,7 +45,7 @@ export async function selectRunnable(ctx: Ctx, prevRunnable?: RunnableQuickPick,
45 if (items.length === 0) { 45 if (items.length === 0) {
46 // it is the debug case, run always has at least 'cargo check ...' 46 // it is the debug case, run always has at least 'cargo check ...'
47 // see crates\rust-analyzer\src\main_loop\handlers.rs, handle_runnables 47 // see crates\rust-analyzer\src\main_loop\handlers.rs, handle_runnables
48 vscode.window.showErrorMessage("There's no debug target!"); 48 await vscode.window.showErrorMessage("There's no debug target!");
49 return; 49 return;
50 } 50 }
51 51
@@ -65,8 +65,8 @@ export async function selectRunnable(ctx: Ctx, prevRunnable?: RunnableQuickPick,
65 disposables.push( 65 disposables.push(
66 quickPick.onDidHide(() => close()), 66 quickPick.onDidHide(() => close()),
67 quickPick.onDidAccept(() => close(quickPick.selectedItems[0])), 67 quickPick.onDidAccept(() => close(quickPick.selectedItems[0])),
68 quickPick.onDidTriggerButton((_button) => { 68 quickPick.onDidTriggerButton(async (_button) => {
69 (async () => await makeDebugConfig(ctx, quickPick.activeItems[0].runnable))(); 69 await makeDebugConfig(ctx, quickPick.activeItems[0].runnable);
70 close(); 70 close();
71 }), 71 }),
72 quickPick.onDidChangeActive((active) => { 72 quickPick.onDidChangeActive((active) => {
@@ -139,6 +139,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
139 overrideCargo: runnable.args.overrideCargo, 139 overrideCargo: runnable.args.overrideCargo,
140 }; 140 };
141 141
142 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
142 const target = vscode.workspace.workspaceFolders![0]; // safe, see main activate() 143 const target = vscode.workspace.workspaceFolders![0]; // safe, see main activate()
143 const cargoTask = await tasks.buildCargoTask(target, definition, runnable.label, args, config.cargoRunner, true); 144 const cargoTask = await tasks.buildCargoTask(target, definition, runnable.label, args, config.cargoRunner, true);
144 cargoTask.presentationOptions.clear = true; 145 cargoTask.presentationOptions.clear = true;
diff --git a/editors/code/src/snippets.ts b/editors/code/src/snippets.ts
index fee736e7d..dc53ebe2e 100644
--- a/editors/code/src/snippets.ts
+++ b/editors/code/src/snippets.ts
@@ -62,7 +62,9 @@ function parseSnippet(snip: string): [string, [number, number]] | undefined {
62 const m = snip.match(/\$(0|\{0:([^}]*)\})/); 62 const m = snip.match(/\$(0|\{0:([^}]*)\})/);
63 if (!m) return undefined; 63 if (!m) return undefined;
64 const placeholder = m[2] ?? ""; 64 const placeholder = m[2] ?? "";
65 const range: [number, number] = [m.index!!, placeholder.length]; 65 if (m.index == null)
66 return undefined;
67 const range: [number, number] = [m.index, placeholder.length];
66 const insert = snip.replace(m[0], placeholder); 68 const insert = snip.replace(m[0], placeholder);
67 return [insert, range]; 69 return [insert, range];
68} 70}