Merge pull request #18722 from markmurphydev/status_bar_settings

Rename `rust-analyzer.statusBar.documentSelector` to `showStatusBar`, add "always" and "never" options.
This commit is contained in:
Lukas Wirth 2024-12-24 14:12:32 +00:00 committed by GitHub
commit 4c0569b244
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 64 additions and 37 deletions

View file

@ -426,29 +426,44 @@
"default": "openLogs", "default": "openLogs",
"markdownDescription": "Action to run when clicking the extension status bar item." "markdownDescription": "Action to run when clicking the extension status bar item."
}, },
"rust-analyzer.statusBar.documentSelector": { "rust-analyzer.statusBar.showStatusBar": {
"type": [ "markdownDescription": "When to show the extension status bar.\n\n`\"always\"` Always show the status bar.\n\n`\"never\"` Never show the status bar.\n\n`{ documentSelector: <DocumentSelector>[] }` Show the status bar if the open file matches any of the given document selectors.\n\nSee [VS Code -- DocumentSelector](https://code.visualstudio.com/api/references/document-selector) for more information.",
"array", "anyOf": [
"null" {
], "type": "string",
"enum": [
"always",
"never"
]
},
{
"type": "object",
"properties": {
"documentSelector": {
"type": "array",
"items": { "items": {
"type": "object", "type": "object",
"properties": { "properties": {
"language": { "language": {
"type": [ "type": "string"
"string", },
"null" "notebookType": {
] "type": "string"
},
"scheme": {
"type": "string"
}, },
"pattern": { "pattern": {
"type": [ "type": "string"
"string",
"null"
]
} }
} }
}, }
"default": [ }
}
}
],
"default": {
"documentSelector": [
{ {
"language": "rust" "language": "rust"
}, },
@ -458,8 +473,8 @@
{ {
"pattern": "**/Cargo.lock" "pattern": "**/Cargo.lock"
} }
], ]
"markdownDescription": "Determines when to show the extension status bar item based on the currently open file. Use `{ \"pattern\": \"**\" }` to always show. Use `null` to never show." }
} }
} }
}, },

View file

@ -13,6 +13,13 @@ export type RunnableEnvCfgItem = {
}; };
export type RunnableEnvCfg = Record<string, string> | RunnableEnvCfgItem[]; export type RunnableEnvCfg = Record<string, string> | RunnableEnvCfgItem[];
type ShowStatusBar =
| "always"
| "never"
| {
documentSelector: vscode.DocumentSelector;
};
export class Config { export class Config {
readonly extensionId = "rust-lang.rust-analyzer"; readonly extensionId = "rust-lang.rust-analyzer";
configureLang: vscode.Disposable | undefined; configureLang: vscode.Disposable | undefined;
@ -348,8 +355,8 @@ export class Config {
return this.get<string>("statusBar.clickAction"); return this.get<string>("statusBar.clickAction");
} }
get statusBarDocumentSelector() { get statusBarShowStatusBar() {
return this.get<vscode.DocumentSelector>("statusBar.documentSelector"); return this.get<ShowStatusBar>("statusBar.showStatusBar");
} }
get initializeStopped() { get initializeStopped() {

View file

@ -480,15 +480,20 @@ export class Ctx implements RustAnalyzerExtensionApi {
} }
private updateStatusBarVisibility(editor: vscode.TextEditor | undefined) { private updateStatusBarVisibility(editor: vscode.TextEditor | undefined) {
const documentSelector = this.config.statusBarDocumentSelector; const showStatusBar = this.config.statusBarShowStatusBar;
if (documentSelector != null) { if (showStatusBar == null || showStatusBar === "never") {
this.statusBar.hide();
} else if (showStatusBar === "always") {
this.statusBar.show();
} else {
const documentSelector = showStatusBar.documentSelector;
if (editor != null && vscode.languages.match(documentSelector, editor.document) > 0) { if (editor != null && vscode.languages.match(documentSelector, editor.document) > 0) {
this.statusBar.show(); this.statusBar.show();
return; } else {
}
}
this.statusBar.hide(); this.statusBar.hide();
} }
}
}
pushExtCleanup(d: Disposable) { pushExtCleanup(d: Disposable) {
this.extCtx.subscriptions.push(d); this.extCtx.subscriptions.push(d);