mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
⬆️ rust-analyzer
This commit is contained in:
parent
15b867b5db
commit
b2f6fd4f96
217 changed files with 12639 additions and 3059 deletions
|
@ -114,6 +114,11 @@
|
|||
"title": "View Hir",
|
||||
"category": "rust-analyzer (debug command)"
|
||||
},
|
||||
{
|
||||
"command": "rust-analyzer.viewMir",
|
||||
"title": "View Mir",
|
||||
"category": "rust-analyzer (debug command)"
|
||||
},
|
||||
{
|
||||
"command": "rust-analyzer.viewFileText",
|
||||
"title": "View File Text (as seen by the server)",
|
||||
|
@ -226,7 +231,7 @@
|
|||
},
|
||||
{
|
||||
"command": "rust-analyzer.openDocs",
|
||||
"title": "Open docs under cursor",
|
||||
"title": "Open Docs",
|
||||
"category": "rust-analyzer"
|
||||
},
|
||||
{
|
||||
|
@ -236,7 +241,7 @@
|
|||
},
|
||||
{
|
||||
"command": "rust-analyzer.peekTests",
|
||||
"title": "Peek related tests",
|
||||
"title": "Peek Related Tests",
|
||||
"category": "rust-analyzer"
|
||||
},
|
||||
{
|
||||
|
@ -506,6 +511,14 @@
|
|||
"default": true,
|
||||
"type": "boolean"
|
||||
},
|
||||
"rust-analyzer.cargo.extraArgs": {
|
||||
"markdownDescription": "Extra arguments that are passed to every cargo invocation.",
|
||||
"default": [],
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"rust-analyzer.cargo.extraEnv": {
|
||||
"markdownDescription": "Extra environment variables that will be set when running cargo, rustc\nor other commands within the workspace. Useful for setting RUSTFLAGS.",
|
||||
"default": {},
|
||||
|
@ -1110,6 +1123,11 @@
|
|||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"rust-analyzer.interpret.tests": {
|
||||
"markdownDescription": "Enables the experimental support for interpreting tests.",
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"rust-analyzer.joinLines.joinAssignments": {
|
||||
"markdownDescription": "Join lines merges consecutive declaration and initialization of an assignment.",
|
||||
"default": true,
|
||||
|
@ -1283,7 +1301,7 @@
|
|||
}
|
||||
},
|
||||
"rust-analyzer.rustfmt.overrideCommand": {
|
||||
"markdownDescription": "Advanced option, fully override the command rust-analyzer uses for\nformatting.",
|
||||
"markdownDescription": "Advanced option, fully override the command rust-analyzer uses for\nformatting. This should be the equivalent of `rustfmt` here, and\nnot that of `cargo fmt`. The file contents will be passed on the\nstandard input and the formatted result will be read from the\nstandard output.",
|
||||
"default": null,
|
||||
"type": [
|
||||
"null",
|
||||
|
@ -1869,8 +1887,13 @@
|
|||
"editor/context": [
|
||||
{
|
||||
"command": "rust-analyzer.peekTests",
|
||||
"when": "inRustProject",
|
||||
"when": "inRustProject && editorTextFocus && editorLangId == rust",
|
||||
"group": "navigation@1000"
|
||||
},
|
||||
{
|
||||
"command": "rust-analyzer.openDocs",
|
||||
"when": "inRustProject && editorTextFocus && editorLangId == rust",
|
||||
"group": "navigation@1001"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -93,6 +93,14 @@ export function triggerParameterHints(_: CtxInit): Cmd {
|
|||
};
|
||||
}
|
||||
|
||||
export function openLogs(ctx: CtxInit): Cmd {
|
||||
return async () => {
|
||||
if (ctx.client.outputChannel) {
|
||||
ctx.client.outputChannel.show();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function matchingBrace(ctx: CtxInit): Cmd {
|
||||
return async () => {
|
||||
const editor = ctx.activeRustEditor;
|
||||
|
@ -405,12 +413,11 @@ export function syntaxTree(ctx: CtxInit): Cmd {
|
|||
};
|
||||
}
|
||||
|
||||
// Opens the virtual file that will show the HIR of the function containing the cursor position
|
||||
//
|
||||
// The contents of the file come from the `TextDocumentContentProvider`
|
||||
export function viewHir(ctx: CtxInit): Cmd {
|
||||
function viewHirOrMir(ctx: CtxInit, xir: "hir" | "mir"): Cmd {
|
||||
const viewXir = xir === "hir" ? "viewHir" : "viewMir";
|
||||
const requestType = xir === "hir" ? ra.viewHir : ra.viewMir;
|
||||
const tdcp = new (class implements vscode.TextDocumentContentProvider {
|
||||
readonly uri = vscode.Uri.parse("rust-analyzer-hir://viewHir/hir.rs");
|
||||
readonly uri = vscode.Uri.parse(`rust-analyzer-${xir}://${viewXir}/${xir}.rs`);
|
||||
readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>();
|
||||
constructor() {
|
||||
vscode.workspace.onDidChangeTextDocument(
|
||||
|
@ -452,7 +459,7 @@ export function viewHir(ctx: CtxInit): Cmd {
|
|||
),
|
||||
position: client.code2ProtocolConverter.asPosition(rustEditor.selection.active),
|
||||
};
|
||||
return client.sendRequest(ra.viewHir, params, ct);
|
||||
return client.sendRequest(requestType, params, ct);
|
||||
}
|
||||
|
||||
get onDidChange(): vscode.Event<vscode.Uri> {
|
||||
|
@ -461,7 +468,7 @@ export function viewHir(ctx: CtxInit): Cmd {
|
|||
})();
|
||||
|
||||
ctx.pushExtCleanup(
|
||||
vscode.workspace.registerTextDocumentContentProvider("rust-analyzer-hir", tdcp)
|
||||
vscode.workspace.registerTextDocumentContentProvider(`rust-analyzer-${xir}`, tdcp)
|
||||
);
|
||||
|
||||
return async () => {
|
||||
|
@ -474,6 +481,20 @@ export function viewHir(ctx: CtxInit): Cmd {
|
|||
};
|
||||
}
|
||||
|
||||
// Opens the virtual file that will show the HIR of the function containing the cursor position
|
||||
//
|
||||
// The contents of the file come from the `TextDocumentContentProvider`
|
||||
export function viewHir(ctx: CtxInit): Cmd {
|
||||
return viewHirOrMir(ctx, "hir");
|
||||
}
|
||||
|
||||
// Opens the virtual file that will show the MIR of the function containing the cursor position
|
||||
//
|
||||
// The contents of the file come from the `TextDocumentContentProvider`
|
||||
export function viewMir(ctx: CtxInit): Cmd {
|
||||
return viewHirOrMir(ctx, "mir");
|
||||
}
|
||||
|
||||
export function viewFileText(ctx: CtxInit): Cmd {
|
||||
const tdcp = new (class implements vscode.TextDocumentContentProvider {
|
||||
readonly uri = vscode.Uri.parse("rust-analyzer-file-text://viewFileText/file.rs");
|
||||
|
|
|
@ -282,18 +282,18 @@ export class Ctx {
|
|||
setServerStatus(status: ServerStatusParams | { health: "stopped" }) {
|
||||
let icon = "";
|
||||
const statusBar = this.statusBar;
|
||||
statusBar.tooltip = new vscode.MarkdownString("", true);
|
||||
statusBar.tooltip.isTrusted = true;
|
||||
switch (status.health) {
|
||||
case "ok":
|
||||
statusBar.tooltip = (status.message ?? "Ready") + "\nClick to stop server.";
|
||||
statusBar.command = "rust-analyzer.stopServer";
|
||||
statusBar.tooltip.appendText(status.message ?? "Ready");
|
||||
statusBar.color = undefined;
|
||||
statusBar.backgroundColor = undefined;
|
||||
break;
|
||||
case "warning":
|
||||
statusBar.tooltip =
|
||||
(status.message ? status.message + "\n" : "") + "Click to reload.";
|
||||
|
||||
statusBar.command = "rust-analyzer.reloadWorkspace";
|
||||
if (status.message) {
|
||||
statusBar.tooltip.appendText(status.message);
|
||||
}
|
||||
statusBar.color = new vscode.ThemeColor("statusBarItem.warningForeground");
|
||||
statusBar.backgroundColor = new vscode.ThemeColor(
|
||||
"statusBarItem.warningBackground"
|
||||
|
@ -301,22 +301,32 @@ export class Ctx {
|
|||
icon = "$(warning) ";
|
||||
break;
|
||||
case "error":
|
||||
statusBar.tooltip =
|
||||
(status.message ? status.message + "\n" : "") + "Click to reload.";
|
||||
|
||||
statusBar.command = "rust-analyzer.reloadWorkspace";
|
||||
if (status.message) {
|
||||
statusBar.tooltip.appendText(status.message);
|
||||
}
|
||||
statusBar.color = new vscode.ThemeColor("statusBarItem.errorForeground");
|
||||
statusBar.backgroundColor = new vscode.ThemeColor("statusBarItem.errorBackground");
|
||||
icon = "$(error) ";
|
||||
break;
|
||||
case "stopped":
|
||||
statusBar.tooltip = "Server is stopped.\nClick to start.";
|
||||
statusBar.command = "rust-analyzer.startServer";
|
||||
statusBar.tooltip.appendText("Server is stopped");
|
||||
statusBar.tooltip.appendMarkdown(
|
||||
"\n\n[Start server](command:rust-analyzer.startServer)"
|
||||
);
|
||||
statusBar.color = undefined;
|
||||
statusBar.backgroundColor = undefined;
|
||||
statusBar.text = `$(stop-circle) rust-analyzer`;
|
||||
return;
|
||||
}
|
||||
if (statusBar.tooltip.value) {
|
||||
statusBar.tooltip.appendText("\n\n");
|
||||
}
|
||||
statusBar.tooltip.appendMarkdown("[Stop server](command:rust-analyzer.stopServer)");
|
||||
statusBar.tooltip.appendMarkdown(
|
||||
"\n\n[Reload Workspace](command:rust-analyzer.reloadWorkspace)"
|
||||
);
|
||||
statusBar.tooltip.appendMarkdown("\n\n[Restart server](command:rust-analyzer.startServer)");
|
||||
statusBar.tooltip.appendMarkdown("\n\n[Open logs](command:rust-analyzer.openLogs)");
|
||||
if (!status.quiescent) icon = "$(sync~spin) ";
|
||||
statusBar.text = `${icon}rust-analyzer`;
|
||||
}
|
||||
|
|
|
@ -59,6 +59,9 @@ export const viewFileText = new lc.RequestType<lc.TextDocumentIdentifier, string
|
|||
export const viewHir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>(
|
||||
"rust-analyzer/viewHir"
|
||||
);
|
||||
export const viewMir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>(
|
||||
"rust-analyzer/viewMir"
|
||||
);
|
||||
export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>(
|
||||
"rust-analyzer/viewItemTree"
|
||||
);
|
||||
|
|
|
@ -158,6 +158,7 @@ function createCommands(): Record<string, CommandFactory> {
|
|||
parentModule: { enabled: commands.parentModule },
|
||||
syntaxTree: { enabled: commands.syntaxTree },
|
||||
viewHir: { enabled: commands.viewHir },
|
||||
viewMir: { enabled: commands.viewMir },
|
||||
viewFileText: { enabled: commands.viewFileText },
|
||||
viewItemTree: { enabled: commands.viewItemTree },
|
||||
viewCrateGraph: { enabled: commands.viewCrateGraph },
|
||||
|
@ -187,5 +188,6 @@ function createCommands(): Record<string, CommandFactory> {
|
|||
runSingle: { enabled: commands.runSingle },
|
||||
showReferences: { enabled: commands.showReferences },
|
||||
triggerParameterHints: { enabled: commands.triggerParameterHints },
|
||||
openLogs: { enabled: commands.openLogs },
|
||||
};
|
||||
}
|
||||
|
|
|
@ -156,19 +156,10 @@ export const getPathForExecutable = memoizeAsync(
|
|||
|
||||
if (await lookupInPath(executableName)) return executableName;
|
||||
|
||||
try {
|
||||
// hmm, `os.homedir()` seems to be infallible
|
||||
// it is not mentioned in docs and cannot be inferred by the type signature...
|
||||
const standardPath = vscode.Uri.joinPath(
|
||||
vscode.Uri.file(os.homedir()),
|
||||
".cargo",
|
||||
"bin",
|
||||
executableName
|
||||
);
|
||||
|
||||
const cargoHome = getCargoHome();
|
||||
if (cargoHome) {
|
||||
const standardPath = vscode.Uri.joinPath(cargoHome, "bin", executableName);
|
||||
if (await isFileAtUri(standardPath)) return standardPath.fsPath;
|
||||
} catch (err) {
|
||||
log.error("Failed to read the fs info", err);
|
||||
}
|
||||
return executableName;
|
||||
}
|
||||
|
@ -190,6 +181,21 @@ async function lookupInPath(exec: string): Promise<boolean> {
|
|||
return false;
|
||||
}
|
||||
|
||||
function getCargoHome(): vscode.Uri | null {
|
||||
const envVar = process.env["CARGO_HOME"];
|
||||
if (envVar) return vscode.Uri.file(envVar);
|
||||
|
||||
try {
|
||||
// hmm, `os.homedir()` seems to be infallible
|
||||
// it is not mentioned in docs and cannot be inferred by the type signature...
|
||||
return vscode.Uri.joinPath(vscode.Uri.file(os.homedir()), ".cargo");
|
||||
} catch (err) {
|
||||
log.error("Failed to read the fs info", err);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async function isFileAtPath(path: string): Promise<boolean> {
|
||||
return isFileAtUri(vscode.Uri.file(path));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue