mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-03 05:13:35 +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 { Config, prepareVSCodeConfig } from "./config";
|
||||||
import { createClient } from "./client";
|
import { createClient } from "./client";
|
||||||
import {
|
import {
|
||||||
|
isCargoTomlEditor,
|
||||||
isDocumentInWorkspace,
|
isDocumentInWorkspace,
|
||||||
isRustDocument,
|
isRustDocument,
|
||||||
isRustEditor,
|
isRustEditor,
|
||||||
|
|
@ -429,6 +430,11 @@ export class Ctx implements RustAnalyzerExtensionApi {
|
||||||
return editor && isRustEditor(editor) ? editor : undefined;
|
return editor && isRustEditor(editor) ? editor : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get activeCargoTomlEditor(): RustEditor | undefined {
|
||||||
|
const editor = vscode.window.activeTextEditor;
|
||||||
|
return editor && isCargoTomlEditor(editor) ? editor : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
get extensionPath(): string {
|
get extensionPath(): string {
|
||||||
return this.extCtx.extensionPath;
|
return this.extCtx.extensionPath;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import type { CtxInit } from "./ctx";
|
||||||
import { makeDebugConfig } from "./debug";
|
import { makeDebugConfig } from "./debug";
|
||||||
import type { Config } from "./config";
|
import type { Config } from "./config";
|
||||||
import type { LanguageClient } from "vscode-languageclient/node";
|
import type { LanguageClient } from "vscode-languageclient/node";
|
||||||
import { unwrapUndefinable, type RustEditor } from "./util";
|
import { log, unwrapUndefinable, type RustEditor } from "./util";
|
||||||
|
|
||||||
const quickPickButtons = [
|
const quickPickButtons = [
|
||||||
{ iconPath: new vscode.ThemeIcon("save"), tooltip: "Save as a launch.json configuration." },
|
{ iconPath: new vscode.ThemeIcon("save"), tooltip: "Save as a launch.json configuration." },
|
||||||
|
|
@ -19,7 +19,7 @@ export async function selectRunnable(
|
||||||
debuggeeOnly = false,
|
debuggeeOnly = false,
|
||||||
showButtons: boolean = true,
|
showButtons: boolean = true,
|
||||||
): Promise<RunnableQuickPick | undefined> {
|
): Promise<RunnableQuickPick | undefined> {
|
||||||
const editor = ctx.activeRustEditor;
|
const editor = ctx.activeRustEditor ?? ctx.activeCargoTomlEditor;
|
||||||
if (!editor) return;
|
if (!editor) return;
|
||||||
|
|
||||||
// show a placeholder while we get the runnables from the server
|
// show a placeholder while we get the runnables from the server
|
||||||
|
|
@ -175,9 +175,16 @@ async function getRunnables(
|
||||||
uri: editor.document.uri.toString(),
|
uri: editor.document.uri.toString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
const runnables = await client.sendRequest(ra.runnables, {
|
const runnables = await client
|
||||||
|
.sendRequest(ra.runnables, {
|
||||||
textDocument,
|
textDocument,
|
||||||
position: client.code2ProtocolConverter.asPosition(editor.selection.active),
|
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[] = [];
|
const items: RunnableQuickPick[] = [];
|
||||||
if (prevRunnable) {
|
if (prevRunnable) {
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,10 @@ export function isRustEditor(editor: vscode.TextEditor): editor is RustEditor {
|
||||||
return isRustDocument(editor.document);
|
return isRustDocument(editor.document);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isCargoTomlEditor(editor: vscode.TextEditor): editor is RustEditor {
|
||||||
|
return isCargoTomlDocument(editor.document);
|
||||||
|
}
|
||||||
|
|
||||||
export function isDocumentInWorkspace(document: RustDocument): boolean {
|
export function isDocumentInWorkspace(document: RustDocument): boolean {
|
||||||
const workspaceFolders = vscode.workspace.workspaceFolders;
|
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||||
if (!workspaceFolders) {
|
if (!workspaceFolders) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue