Skip to content

Commit

Permalink
Added language status (#3507)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntotten authored Aug 14, 2024
1 parent ef1fa15 commit c2b029d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to the "prettier-vscode" extension will be documented in thi
## [Unreleased]

- [BREAKING CHANGE] Prevent `.editorconfig` from satisfying the `requireConfig` setting
- Added Language Status Item for Prettier
- Fix issue where formatting multiple files in a workspace with multiple instances of Prettier could result in files being overwritten with the contents of other files (#3423, #3040)
- Add support for `experimentalTernaries` option

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"url": "https://github.com/prettier/prettier-vscode/issues"
},
"engines": {
"vscode": "^1.60.0"
"vscode": "^1.80.0"
},
"keywords": [
"multi-root ready",
Expand Down Expand Up @@ -100,7 +100,7 @@
"@types/semver": "^7.5.8",
"@types/sinon": "^17.0.3",
"@types/tmp": "^0.2.6",
"@types/vscode": "^1.60.0",
"@types/vscode": "^1.80.0",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"@vscode/test-electron": "^2.4.1",
Expand Down
4 changes: 4 additions & 0 deletions src/PrettierEditService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ export default class PrettierEditService implements Disposable {
workspaceFolder.uri
);

this.statusBar.updateConfig({
selector: selectors.languageSelector,
});

if (!isRegistered) {
this.registerDocumentFormatEditorProviders(selectors);
this.registeredWorkspaces.add(workspaceFolder.uri.fsPath);
Expand Down
40 changes: 37 additions & 3 deletions src/StatusBar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { StatusBarAlignment, StatusBarItem, window, ThemeColor } from "vscode";
import {
Disposable,
DocumentSelector,
languages,
LanguageStatusItem,
LanguageStatusSeverity,
StatusBarAlignment,
StatusBarItem,
ThemeColor,
window,
} from "vscode";

export enum FormatterStatus {
Ready = "check-all",
Expand All @@ -9,20 +19,36 @@ export enum FormatterStatus {
Disabled = "circle-slash",
}

export class StatusBar {
export class StatusBar implements Disposable {
private statusBarItem: StatusBarItem;
private languageStatusItem: LanguageStatusItem;
constructor() {
// Setup the statusBarItem
this.statusBarItem = window.createStatusBarItem(
"prettier.status",
StatusBarAlignment.Right,
-1
);
this.languageStatusItem = languages.createLanguageStatusItem(
"prettier.status",
[]
);

this.statusBarItem.name = "Prettier";
this.statusBarItem.text = "Prettier";
this.statusBarItem.command = "prettier.openOutput";
this.update(FormatterStatus.Ready);
this.statusBarItem.show();

this.languageStatusItem.name = "Prettier";
this.languageStatusItem.text = "Prettier";
this.languageStatusItem.command = {
title: "View Logs",
command: "prettier.openOutput",
};
}

public updateConfig({ selector }: { selector: DocumentSelector }) {
this.languageStatusItem.selector = selector;
}

/**
Expand All @@ -38,16 +64,19 @@ export class StatusBar {
this.statusBarItem.backgroundColor = new ThemeColor(
"statusBarItem.warningBackground"
);
this.languageStatusItem.severity = LanguageStatusSeverity.Warning;
break;
case FormatterStatus.Error:
this.statusBarItem.backgroundColor = new ThemeColor(
"statusBarItem.errorBackground"
);
this.languageStatusItem.severity = LanguageStatusSeverity.Error;
break;
default:
this.statusBarItem.backgroundColor = new ThemeColor(
"statusBarItem.fourgroundBackground"
);
this.languageStatusItem.severity = LanguageStatusSeverity.Information;
break;
}
this.statusBarItem.show();
Expand All @@ -56,4 +85,9 @@ export class StatusBar {
public hide() {
this.statusBarItem.hide();
}

public dispose(): void {
this.languageStatusItem.dispose();
this.statusBarItem.dispose();
}
}
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function activate(context: ExtensionContext) {
);

context.subscriptions.push(
statusBar,
editService,
createConfigFileCommand,
openOutputCommand,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,10 @@
resolved "https://registry.yarnpkg.com/@types/tmp/-/tmp-0.2.6.tgz#d785ee90c52d7cc020e249c948c36f7b32d1e217"
integrity sha512-chhaNf2oKHlRkDGt+tiKE2Z5aJ6qalm7Z9rlLdBwmOiAAf09YQvvoLXjWK4HWPF1xU/fqvMgfNfpVoBscA/tKA==

"@types/vscode@^1.60.0":
version "1.69.0"
resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.69.0.tgz#a472011af392fbcf82cbb82f60b4c239c21b921c"
integrity sha512-RlzDAnGqUoo9wS6d4tthNyAdZLxOIddLiX3djMoWk29jFfSA1yJbIwr0epBYqqYarWB6s2Z+4VaZCQ80Jaa3kA==
"@types/vscode@^1.80.0":
version "1.92.0"
resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.92.0.tgz#b4d6bc180e7206defe643a1a5f38a1367947d418"
integrity sha512-DcZoCj17RXlzB4XJ7IfKdPTcTGDLYvTOcTNkvtjXWF+K2TlKzHHkBEXNWQRpBIXixNEUgx39cQeTFunY0E2msw==

"@typescript-eslint/eslint-plugin@^5.45.0":
version "5.45.0"
Expand Down

0 comments on commit c2b029d

Please sign in to comment.