Skip to content

Commit c3a9d97

Browse files
Add status bar instead of error notifications (VSC extension) (#826)
* Add option to hide formatting errors * Add status bar item and remove notification setting * Switch to language status item and update on editor change * Update changelog --------- Co-authored-by: JohnnyMorganz <johnnymorganz@outlook.com>
1 parent a61d983 commit c3a9d97

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

stylua-vscode/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ To view the changelog of the StyLua binary, see [here](https://github.com/Johnny
1111

1212
## [Unreleased]
1313

14+
### Changed
15+
16+
- Removed excessive error notifications on formatting failure and replaced with VSCode language status bar item
17+
1418
## [1.5.0] - 2023-03-11
1519

1620
### Added

stylua-vscode/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
"command": "stylua.authenticate",
4343
"title": "Authorize StyLua to use GitHub API",
4444
"category": "StyLua"
45+
},
46+
{
47+
"command": "stylua.showOutputChannel",
48+
"title": "Show Output Channel",
49+
"category": "StyLua"
4550
}
4651
],
4752
"configuration": {
@@ -87,7 +92,7 @@
8792
"stylua.disableVersionCheck": {
8893
"type": "boolean",
8994
"default": false,
90-
"description": "Disable checking the version of stylua for newer versions. Useful if you do not want network requests"
95+
"description": "Disable checking the version of stylua for newer versions. Useful if you do not want network requests."
9196
},
9297
"stylua.searchParentDirectories": {
9398
"type": "boolean",

stylua-vscode/src/extension.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ const byteOffset = (
2424
export async function activate(context: vscode.ExtensionContext) {
2525
console.log("stylua activated");
2626

27+
const outputChannel = vscode.window.createOutputChannel("StyLua", {
28+
log: true,
29+
});
30+
outputChannel.info("StyLua activated");
31+
2732
const github = new GitHub();
2833
context.subscriptions.push(github);
2934

@@ -48,6 +53,12 @@ export async function activate(context: vscode.ExtensionContext) {
4853
})
4954
);
5055

56+
context.subscriptions.push(
57+
vscode.commands.registerCommand("stylua.showOutputChannel", async () => {
58+
outputChannel.show();
59+
})
60+
);
61+
5162
context.subscriptions.push(
5263
vscode.workspace.onDidChangeConfiguration(async (change) => {
5364
if (change.affectsConfiguration("stylua")) {
@@ -58,8 +69,22 @@ export async function activate(context: vscode.ExtensionContext) {
5869
})
5970
);
6071

72+
const documentSelector = ["lua", "luau"];
73+
74+
const languageStatusItem = vscode.languages.createLanguageStatusItem(
75+
"stylua",
76+
documentSelector
77+
);
78+
languageStatusItem.name = "StyLua";
79+
languageStatusItem.text = "$(check) StyLua";
80+
languageStatusItem.detail = "Ready";
81+
languageStatusItem.command = {
82+
title: "Show Output",
83+
command: "stylua.showOutputChannel",
84+
};
85+
6186
let disposable = vscode.languages.registerDocumentRangeFormattingEditProvider(
62-
["lua", "luau"],
87+
documentSelector,
6388
{
6489
async provideDocumentRangeFormattingEdits(
6590
document: vscode.TextDocument,
@@ -112,16 +137,31 @@ export async function activate(context: vscode.ExtensionContext) {
112137
fullDocumentRange,
113138
formattedText
114139
);
140+
languageStatusItem.text = "$(check) StyLua";
141+
languageStatusItem.detail = "File formatted successfully";
142+
languageStatusItem.severity =
143+
vscode.LanguageStatusSeverity.Information;
115144
return [format];
116145
} catch (err) {
117-
vscode.window.showErrorMessage(`Could not format file: ${err}`);
146+
languageStatusItem.text = "StyLua";
147+
languageStatusItem.detail = "Failed to format file";
148+
languageStatusItem.severity = vscode.LanguageStatusSeverity.Error;
149+
outputChannel.error(err as string);
118150
return [];
119151
}
120152
},
121153
}
122154
);
123155

124156
context.subscriptions.push(disposable);
157+
context.subscriptions.push(languageStatusItem);
158+
context.subscriptions.push(
159+
vscode.window.onDidChangeActiveTextEditor((editor) => {
160+
languageStatusItem.text = "$(check) StyLua";
161+
languageStatusItem.detail = "Ready";
162+
languageStatusItem.severity = vscode.LanguageStatusSeverity.Information;
163+
})
164+
);
125165
}
126166

127167
// this method is called when your extension is deactivated

0 commit comments

Comments
 (0)