Skip to content

Commit 891dde6

Browse files
authored
Merge pull request #19295 from alibektas/rust_analyzer_run_on_cargo_toml
fix: Make RustAnalyzer:Run available in manifest file
2 parents 1ea081f + 4c74900 commit 891dde6

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

editors/code/src/ctx.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as ra from "./lsp_ext";
55
import { Config, prepareVSCodeConfig } from "./config";
66
import { createClient } from "./client";
77
import {
8+
isCargoTomlEditor,
89
isDocumentInWorkspace,
910
isRustDocument,
1011
isRustEditor,
@@ -429,6 +430,11 @@ export class Ctx implements RustAnalyzerExtensionApi {
429430
return editor && isRustEditor(editor) ? editor : undefined;
430431
}
431432

433+
get activeCargoTomlEditor(): RustEditor | undefined {
434+
const editor = vscode.window.activeTextEditor;
435+
return editor && isCargoTomlEditor(editor) ? editor : undefined;
436+
}
437+
432438
get extensionPath(): string {
433439
return this.extCtx.extensionPath;
434440
}

editors/code/src/run.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { CtxInit } from "./ctx";
77
import { makeDebugConfig } from "./debug";
88
import type { Config } from "./config";
99
import type { LanguageClient } from "vscode-languageclient/node";
10-
import { unwrapUndefinable, type RustEditor } from "./util";
10+
import { log, unwrapUndefinable, type RustEditor } from "./util";
1111

1212
const quickPickButtons = [
1313
{ iconPath: new vscode.ThemeIcon("save"), tooltip: "Save as a launch.json configuration." },
@@ -19,7 +19,7 @@ export async function selectRunnable(
1919
debuggeeOnly = false,
2020
showButtons: boolean = true,
2121
): Promise<RunnableQuickPick | undefined> {
22-
const editor = ctx.activeRustEditor;
22+
const editor = ctx.activeRustEditor ?? ctx.activeCargoTomlEditor;
2323
if (!editor) return;
2424

2525
// show a placeholder while we get the runnables from the server
@@ -175,10 +175,17 @@ async function getRunnables(
175175
uri: editor.document.uri.toString(),
176176
};
177177

178-
const runnables = await client.sendRequest(ra.runnables, {
179-
textDocument,
180-
position: client.code2ProtocolConverter.asPosition(editor.selection.active),
181-
});
178+
const runnables = await client
179+
.sendRequest(ra.runnables, {
180+
textDocument,
181+
position: client.code2ProtocolConverter.asPosition(editor.selection.active),
182+
})
183+
.catch((err) => {
184+
// If this command is run for a virtual manifest at the workspace root, then this request
185+
// will fail as we do not watch this file.
186+
log.error(`${err}`);
187+
return [];
188+
});
182189
const items: RunnableQuickPick[] = [];
183190
if (prevRunnable) {
184191
items.push(prevRunnable);

editors/code/src/util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ export function isRustEditor(editor: vscode.TextEditor): editor is RustEditor {
9090
return isRustDocument(editor.document);
9191
}
9292

93+
export function isCargoTomlEditor(editor: vscode.TextEditor): editor is RustEditor {
94+
return isCargoTomlDocument(editor.document);
95+
}
96+
9397
export function isDocumentInWorkspace(document: RustDocument): boolean {
9498
const workspaceFolders = vscode.workspace.workspaceFolders;
9599
if (!workspaceFolders) {

0 commit comments

Comments
 (0)