mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-30 19:49:36 +00:00
fix: Make RustAnalyzer:Run available in manifest file
This commit is contained in:
parent
d426cbee76
commit
4c7490010a
3 changed files with 23 additions and 6 deletions
|
|
@ -5,6 +5,7 @@ import * as ra from "./lsp_ext";
|
|||
import { Config, prepareVSCodeConfig } from "./config";
|
||||
import { createClient } from "./client";
|
||||
import {
|
||||
isCargoTomlEditor,
|
||||
isDocumentInWorkspace,
|
||||
isRustDocument,
|
||||
isRustEditor,
|
||||
|
|
@ -429,6 +430,11 @@ export class Ctx implements RustAnalyzerExtensionApi {
|
|||
return editor && isRustEditor(editor) ? editor : undefined;
|
||||
}
|
||||
|
||||
get activeCargoTomlEditor(): RustEditor | undefined {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
return editor && isCargoTomlEditor(editor) ? editor : undefined;
|
||||
}
|
||||
|
||||
get extensionPath(): string {
|
||||
return this.extCtx.extensionPath;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import type { CtxInit } from "./ctx";
|
|||
import { makeDebugConfig } from "./debug";
|
||||
import type { Config } from "./config";
|
||||
import type { LanguageClient } from "vscode-languageclient/node";
|
||||
import { unwrapUndefinable, type RustEditor } from "./util";
|
||||
import { log, unwrapUndefinable, type RustEditor } from "./util";
|
||||
|
||||
const quickPickButtons = [
|
||||
{ iconPath: new vscode.ThemeIcon("save"), tooltip: "Save as a launch.json configuration." },
|
||||
|
|
@ -19,7 +19,7 @@ export async function selectRunnable(
|
|||
debuggeeOnly = false,
|
||||
showButtons: boolean = true,
|
||||
): Promise<RunnableQuickPick | undefined> {
|
||||
const editor = ctx.activeRustEditor;
|
||||
const editor = ctx.activeRustEditor ?? ctx.activeCargoTomlEditor;
|
||||
if (!editor) return;
|
||||
|
||||
// show a placeholder while we get the runnables from the server
|
||||
|
|
@ -175,10 +175,17 @@ async function getRunnables(
|
|||
uri: editor.document.uri.toString(),
|
||||
};
|
||||
|
||||
const runnables = await client.sendRequest(ra.runnables, {
|
||||
textDocument,
|
||||
position: client.code2ProtocolConverter.asPosition(editor.selection.active),
|
||||
});
|
||||
const runnables = await client
|
||||
.sendRequest(ra.runnables, {
|
||||
textDocument,
|
||||
position: client.code2ProtocolConverter.asPosition(editor.selection.active),
|
||||
})
|
||||
.catch((err) => {
|
||||
// If this command is run for a virtual manifest at the workspace root, then this request
|
||||
// will fail as we do not watch this file.
|
||||
log.error(`${err}`);
|
||||
return [];
|
||||
});
|
||||
const items: RunnableQuickPick[] = [];
|
||||
if (prevRunnable) {
|
||||
items.push(prevRunnable);
|
||||
|
|
|
|||
|
|
@ -90,6 +90,10 @@ export function isRustEditor(editor: vscode.TextEditor): editor is RustEditor {
|
|||
return isRustDocument(editor.document);
|
||||
}
|
||||
|
||||
export function isCargoTomlEditor(editor: vscode.TextEditor): editor is RustEditor {
|
||||
return isCargoTomlDocument(editor.document);
|
||||
}
|
||||
|
||||
export function isDocumentInWorkspace(document: RustDocument): boolean {
|
||||
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||
if (!workspaceFolders) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue