Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--editors/code/package.json5
-rw-r--r--editors/code/src/commands.ts7
-rw-r--r--editors/code/src/config.ts33
-rw-r--r--editors/code/src/ctx.ts18
-rw-r--r--editors/code/src/main.ts1
-rw-r--r--editors/code/src/util.ts2
6 files changed, 63 insertions, 3 deletions
diff --git a/editors/code/package.json b/editors/code/package.json
index 96fc8d7ecf..83460c82c1 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -292,6 +292,11 @@
"command": "rust-analyzer.viewMemoryLayout",
"title": "View Memory Layout",
"category": "rust-analyzer"
+ },
+ {
+ "command": "rust-analyzer.toggleCheckOnSave",
+ "title": "Toggle Check on Save",
+ "category": "rust-analyzer"
}
],
"keybindings": [
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index e21f536f26..aba37bac27 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -1407,3 +1407,10 @@ locate()
ctx.pushExtCleanup(document);
};
}
+
+export function toggleCheckOnSave(ctx: Ctx): Cmd {
+ return async () => {
+ await ctx.config.toggleCheckOnSave();
+ ctx.refreshServerStatus();
+ };
+}
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 0e64054c11..39e2f767c7 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -216,6 +216,39 @@ export class Config {
),
);
}
+ get checkOnSave() {
+ return this.get<boolean>("checkOnSave") ?? false;
+ }
+ async toggleCheckOnSave() {
+ const config = this.cfg.inspect<boolean>("checkOnSave") ?? { key: "checkOnSave" };
+ let overrideInLanguage;
+ let target;
+ let value;
+ if (
+ config.workspaceFolderValue !== undefined ||
+ config.workspaceFolderLanguageValue !== undefined
+ ) {
+ target = vscode.ConfigurationTarget.WorkspaceFolder;
+ overrideInLanguage = config.workspaceFolderLanguageValue;
+ value = config.workspaceFolderValue || config.workspaceFolderLanguageValue;
+ } else if (
+ config.workspaceValue !== undefined ||
+ config.workspaceLanguageValue !== undefined
+ ) {
+ target = vscode.ConfigurationTarget.Workspace;
+ overrideInLanguage = config.workspaceLanguageValue;
+ value = config.workspaceValue || config.workspaceLanguageValue;
+ } else if (config.globalValue !== undefined || config.globalLanguageValue !== undefined) {
+ target = vscode.ConfigurationTarget.Global;
+ overrideInLanguage = config.globalLanguageValue;
+ value = config.globalValue || config.globalLanguageValue;
+ } else if (config.defaultValue !== undefined || config.defaultLanguageValue !== undefined) {
+ overrideInLanguage = config.defaultLanguageValue;
+ value = config.defaultValue || config.defaultLanguageValue;
+ }
+ await this.cfg.update("checkOnSave", !(value || false), target || null, overrideInLanguage);
+ }
+
get traceExtension() {
return this.get<boolean>("trace.extension");
}
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index 16c14ca54f..363a7a82e6 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -94,6 +94,7 @@ export class Ctx {
private unlinkedFiles: vscode.Uri[];
private _dependencies: RustDependenciesProvider | undefined;
private _treeView: vscode.TreeView<Dependency | DependencyFile | DependencyId> | undefined;
+ private lastStatus: ServerStatusParams | { health: "stopped" } = { health: "stopped" };
get client() {
return this._client;
@@ -404,7 +405,15 @@ export class Ctx {
}
setServerStatus(status: ServerStatusParams | { health: "stopped" }) {
+ this.lastStatus = status;
+ this.updateStatusBarItem();
+ }
+ refreshServerStatus() {
+ this.updateStatusBarItem();
+ }
+ private updateStatusBarItem() {
let icon = "";
+ const status = this.lastStatus;
const statusBar = this.statusBar;
statusBar.show();
statusBar.tooltip = new vscode.MarkdownString("", true);
@@ -447,13 +456,18 @@ export class Ctx {
"statusBarItem.warningBackground",
);
statusBar.command = "rust-analyzer.startServer";
- statusBar.text = `$(stop-circle) rust-analyzer`;
+ statusBar.text = "$(stop-circle) rust-analyzer";
return;
}
if (statusBar.tooltip.value) {
statusBar.tooltip.appendMarkdown("\n\n---\n\n");
}
- statusBar.tooltip.appendMarkdown("\n\n[Open logs](command:rust-analyzer.openLogs)");
+ statusBar.tooltip.appendMarkdown("\n\n[Open Logs](command:rust-analyzer.openLogs)");
+ statusBar.tooltip.appendMarkdown(
+ `\n\n[${
+ this.config.checkOnSave ? "Disable" : "Enable"
+ } Check on Save](command:rust-analyzer.toggleCheckOnSave)`,
+ );
statusBar.tooltip.appendMarkdown(
"\n\n[Reload Workspace](command:rust-analyzer.reloadWorkspace)",
);
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 448150bac0..ee5e5b1b80 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -180,6 +180,7 @@ function createCommands(): Record<string, CommandFactory> {
ssr: { enabled: commands.ssr },
serverVersion: { enabled: commands.serverVersion },
viewMemoryLayout: { enabled: commands.viewMemoryLayout },
+ toggleCheckOnSave: { enabled: commands.toggleCheckOnSave },
// Internal commands which are invoked by the server.
applyActionGroup: { enabled: commands.applyActionGroup },
applySnippetWorkspaceEdit: { enabled: commands.applySnippetWorkspaceEditCommand },
diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts
index e539452577..1e83c281a1 100644
--- a/editors/code/src/util.ts
+++ b/editors/code/src/util.ts
@@ -2,7 +2,7 @@ import * as vscode from "vscode";
import { strict as nativeAssert } from "assert";
import { exec, type ExecOptions, spawnSync } from "child_process";
import { inspect } from "util";
-import { Env } from "./client";
+import type { Env } from "./client";
export function assert(condition: boolean, explanation: string): asserts condition {
try {