Skip to content

Commit 4c0569b

Browse files
authored
Merge pull request #18722 from markmurphydev/status_bar_settings
Rename `rust-analyzer.statusBar.documentSelector` to `showStatusBar`, add "always" and "never" options.
2 parents c679648 + ed0df30 commit 4c0569b

File tree

3 files changed

+62
-35
lines changed

3 files changed

+62
-35
lines changed

editors/code/package.json

+44-29
Original file line numberDiff line numberDiff line change
@@ -426,40 +426,55 @@
426426
"default": "openLogs",
427427
"markdownDescription": "Action to run when clicking the extension status bar item."
428428
},
429-
"rust-analyzer.statusBar.documentSelector": {
430-
"type": [
431-
"array",
432-
"null"
433-
],
434-
"items": {
435-
"type": "object",
436-
"properties": {
437-
"language": {
438-
"type": [
439-
"string",
440-
"null"
441-
]
442-
},
443-
"pattern": {
444-
"type": [
445-
"string",
446-
"null"
447-
]
448-
}
449-
}
450-
},
451-
"default": [
452-
{
453-
"language": "rust"
454-
},
429+
"rust-analyzer.statusBar.showStatusBar": {
430+
"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.",
431+
"anyOf": [
455432
{
456-
"pattern": "**/Cargo.toml"
433+
"type": "string",
434+
"enum": [
435+
"always",
436+
"never"
437+
]
457438
},
458439
{
459-
"pattern": "**/Cargo.lock"
440+
"type": "object",
441+
"properties": {
442+
"documentSelector": {
443+
"type": "array",
444+
"items": {
445+
"type": "object",
446+
"properties": {
447+
"language": {
448+
"type": "string"
449+
},
450+
"notebookType": {
451+
"type": "string"
452+
},
453+
"scheme": {
454+
"type": "string"
455+
},
456+
"pattern": {
457+
"type": "string"
458+
}
459+
}
460+
}
461+
}
462+
}
460463
}
461464
],
462-
"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."
465+
"default": {
466+
"documentSelector": [
467+
{
468+
"language": "rust"
469+
},
470+
{
471+
"pattern": "**/Cargo.toml"
472+
},
473+
{
474+
"pattern": "**/Cargo.lock"
475+
}
476+
]
477+
}
463478
}
464479
}
465480
},

editors/code/src/config.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ export type RunnableEnvCfgItem = {
1313
};
1414
export type RunnableEnvCfg = Record<string, string> | RunnableEnvCfgItem[];
1515

16+
type ShowStatusBar =
17+
| "always"
18+
| "never"
19+
| {
20+
documentSelector: vscode.DocumentSelector;
21+
};
22+
1623
export class Config {
1724
readonly extensionId = "rust-lang.rust-analyzer";
1825
configureLang: vscode.Disposable | undefined;
@@ -348,8 +355,8 @@ export class Config {
348355
return this.get<string>("statusBar.clickAction");
349356
}
350357

351-
get statusBarDocumentSelector() {
352-
return this.get<vscode.DocumentSelector>("statusBar.documentSelector");
358+
get statusBarShowStatusBar() {
359+
return this.get<ShowStatusBar>("statusBar.showStatusBar");
353360
}
354361

355362
get initializeStopped() {

editors/code/src/ctx.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -480,14 +480,19 @@ export class Ctx implements RustAnalyzerExtensionApi {
480480
}
481481

482482
private updateStatusBarVisibility(editor: vscode.TextEditor | undefined) {
483-
const documentSelector = this.config.statusBarDocumentSelector;
484-
if (documentSelector != null) {
483+
const showStatusBar = this.config.statusBarShowStatusBar;
484+
if (showStatusBar == null || showStatusBar === "never") {
485+
this.statusBar.hide();
486+
} else if (showStatusBar === "always") {
487+
this.statusBar.show();
488+
} else {
489+
const documentSelector = showStatusBar.documentSelector;
485490
if (editor != null && vscode.languages.match(documentSelector, editor.document) > 0) {
486491
this.statusBar.show();
487-
return;
492+
} else {
493+
this.statusBar.hide();
488494
}
489495
}
490-
this.statusBar.hide();
491496
}
492497

493498
pushExtCleanup(d: Disposable) {

0 commit comments

Comments
 (0)