Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add status bar instead of error notifications (VSC extension) #826

Merged
merged 4 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions stylua-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ To view the changelog of the StyLua binary, see [here](https://github.com/Johnny

## [Unreleased]

### Changed

- Removed excessive error notifications on formatting failure and replaced with VSCode language status bar item

## [1.5.0] - 2023-03-11

### Added
Expand Down
7 changes: 6 additions & 1 deletion stylua-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
"command": "stylua.authenticate",
"title": "Authorize StyLua to use GitHub API",
"category": "StyLua"
},
{
"command": "stylua.showOutputChannel",
"title": "Show Output Channel",
"category": "StyLua"
}
],
"configuration": {
Expand Down Expand Up @@ -87,7 +92,7 @@
"stylua.disableVersionCheck": {
"type": "boolean",
"default": false,
"description": "Disable checking the version of stylua for newer versions. Useful if you do not want network requests"
"description": "Disable checking the version of stylua for newer versions. Useful if you do not want network requests."
},
"stylua.searchParentDirectories": {
"type": "boolean",
Expand Down
44 changes: 42 additions & 2 deletions stylua-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const byteOffset = (
export async function activate(context: vscode.ExtensionContext) {
console.log("stylua activated");

const outputChannel = vscode.window.createOutputChannel("StyLua", {
log: true,
});
outputChannel.info("StyLua activated");

const github = new GitHub();
context.subscriptions.push(github);

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

context.subscriptions.push(
vscode.commands.registerCommand("stylua.showOutputChannel", async () => {
outputChannel.show();
})
);

context.subscriptions.push(
vscode.workspace.onDidChangeConfiguration(async (change) => {
if (change.affectsConfiguration("stylua")) {
Expand All @@ -58,8 +69,22 @@ export async function activate(context: vscode.ExtensionContext) {
})
);

const documentSelector = ["lua", "luau"];

const languageStatusItem = vscode.languages.createLanguageStatusItem(
"stylua",
documentSelector
);
languageStatusItem.name = "StyLua";
languageStatusItem.text = "$(check) StyLua";
languageStatusItem.detail = "Ready";
languageStatusItem.command = {
title: "Show Output",
command: "stylua.showOutputChannel",
};

let disposable = vscode.languages.registerDocumentRangeFormattingEditProvider(
["lua", "luau"],
documentSelector,
{
async provideDocumentRangeFormattingEdits(
document: vscode.TextDocument,
Expand Down Expand Up @@ -112,16 +137,31 @@ export async function activate(context: vscode.ExtensionContext) {
fullDocumentRange,
formattedText
);
languageStatusItem.text = "$(check) StyLua";
languageStatusItem.detail = "File formatted successfully";
languageStatusItem.severity =
vscode.LanguageStatusSeverity.Information;
return [format];
} catch (err) {
vscode.window.showErrorMessage(`Could not format file: ${err}`);
languageStatusItem.text = "StyLua";
languageStatusItem.detail = "Failed to format file";
languageStatusItem.severity = vscode.LanguageStatusSeverity.Error;
outputChannel.error(err as string);
return [];
}
},
}
);

context.subscriptions.push(disposable);
context.subscriptions.push(languageStatusItem);
context.subscriptions.push(
vscode.window.onDidChangeActiveTextEditor((editor) => {
languageStatusItem.text = "$(check) StyLua";
languageStatusItem.detail = "Ready";
languageStatusItem.severity = vscode.LanguageStatusSeverity.Information;
})
);
}

// this method is called when your extension is deactivated
Expand Down