Skip to content

Commit

Permalink
フォーマットエラー時にステータスバーのアイコンの背景色で通知するように変更 (#53)
Browse files Browse the repository at this point in the history
* adding icon to status bar

* add error icon

* npx prettier

* Create gentle-flies-own.md

---------

Co-authored-by: kawabuchi4280 <k.kawabuchi.z8@future.co.jp>
Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
  • Loading branch information
3 people committed Apr 30, 2024
1 parent aa8b1d8 commit 5df3a5c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-flies-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"uroborosql-fmt": minor
---

Improved to notify the status bar when formatting errors.
54 changes: 53 additions & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import * as path from "path";
import { workspace, ExtensionContext, window, commands } from "vscode";
import {
workspace,
ExtensionContext,
window,
commands,
StatusBarAlignment,
ThemeColor,
StatusBarItem,
} from "vscode";

import {
LanguageClient,
Expand Down Expand Up @@ -66,10 +74,54 @@ export function activate(context: ExtensionContext) {
}),
);

// ステータスバーの作成と表示
const statusBar = createStatusBar();
statusBar.show();

client.onReady().then(() => {
// ステータスバーの背景色を黄色に変更
client.onRequest("custom/warning", () => {
statusBar.backgroundColor = new ThemeColor(
"statusBarItem.warningBackground",
);
statusBar.text = "$(warning) Uroborosql-fmt";
});

// ステータスバーの背景色を赤色に変更
client.onRequest("custom/error", () => {
statusBar.backgroundColor = new ThemeColor(
"statusBarItem.errorBackground",
);
statusBar.text = "$(alert) Uroborosql-fmt";
});

// ステータスバーの背景色を通常色に変更
client.onRequest("custom/normal", () => {
statusBar.backgroundColor = new ThemeColor(
"statusBarItem.fourgroundBackground",
);
statusBar.text = "Uroborosql-fmt";
});
});

// Start the client. This will also launch the server
client.start();
}

function createStatusBar(): StatusBarItem {
commands.registerCommand("uroborosql-fmt.show-output", async () => {
const output_channnel = client.outputChannel;
output_channnel.show();
});

const statusBar = window.createStatusBarItem(StatusBarAlignment.Right, 100);
statusBar.text = "Uroborosql-fmt";
statusBar.name = "Uroborosql-fmt";
statusBar.command = "uroborosql-fmt.show-output";

return statusBar;
}

export function deactivate(): Thenable<void> | undefined {
if (!client) {
return undefined;
Expand Down
11 changes: 8 additions & 3 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,12 @@ async function formatText(

try {
formattedText = runfmt(text, configPath);
// ステータスバーの背景を通常色に変更
connection.sendRequest("custom/normal", []);
} catch (e) {
console.error(e);
// ステータスバーの背景を赤色に変更
connection.sendRequest("custom/error", []);
return [];
}

Expand All @@ -227,11 +231,12 @@ async function formatText(
const startTime = performance.now();
try {
formattedText = runfmt(text, configPath);
// ステータスバーの背景を通常色に変更
connection.sendRequest("custom/normal", []);
} catch (e) {
console.error(e);
connection.window.showErrorMessage(
`Formatter error. src:${textDocument.uri}, config:${configPath} msg: ${e}`,
);
// ステータスバーの背景を赤色に変更
connection.sendRequest("custom/error", []);
return [];
}
//タイマーストップ
Expand Down

0 comments on commit 5df3a5c

Please sign in to comment.