Skip to content

Commit 5df3a5c

Browse files
ppputtyokawabuchi4280ota-meshi
authored
フォーマットエラー時にステータスバーのアイコンの背景色で通知するように変更 (#53)
* 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>
1 parent aa8b1d8 commit 5df3a5c

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

.changeset/gentle-flies-own.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"uroborosql-fmt": minor
3+
---
4+
5+
Improved to notify the status bar when formatting errors.

client/src/extension.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import * as path from "path";
2-
import { workspace, ExtensionContext, window, commands } from "vscode";
2+
import {
3+
workspace,
4+
ExtensionContext,
5+
window,
6+
commands,
7+
StatusBarAlignment,
8+
ThemeColor,
9+
StatusBarItem,
10+
} from "vscode";
311

412
import {
513
LanguageClient,
@@ -66,10 +74,54 @@ export function activate(context: ExtensionContext) {
6674
}),
6775
);
6876

77+
// ステータスバーの作成と表示
78+
const statusBar = createStatusBar();
79+
statusBar.show();
80+
81+
client.onReady().then(() => {
82+
// ステータスバーの背景色を黄色に変更
83+
client.onRequest("custom/warning", () => {
84+
statusBar.backgroundColor = new ThemeColor(
85+
"statusBarItem.warningBackground",
86+
);
87+
statusBar.text = "$(warning) Uroborosql-fmt";
88+
});
89+
90+
// ステータスバーの背景色を赤色に変更
91+
client.onRequest("custom/error", () => {
92+
statusBar.backgroundColor = new ThemeColor(
93+
"statusBarItem.errorBackground",
94+
);
95+
statusBar.text = "$(alert) Uroborosql-fmt";
96+
});
97+
98+
// ステータスバーの背景色を通常色に変更
99+
client.onRequest("custom/normal", () => {
100+
statusBar.backgroundColor = new ThemeColor(
101+
"statusBarItem.fourgroundBackground",
102+
);
103+
statusBar.text = "Uroborosql-fmt";
104+
});
105+
});
106+
69107
// Start the client. This will also launch the server
70108
client.start();
71109
}
72110

111+
function createStatusBar(): StatusBarItem {
112+
commands.registerCommand("uroborosql-fmt.show-output", async () => {
113+
const output_channnel = client.outputChannel;
114+
output_channnel.show();
115+
});
116+
117+
const statusBar = window.createStatusBarItem(StatusBarAlignment.Right, 100);
118+
statusBar.text = "Uroborosql-fmt";
119+
statusBar.name = "Uroborosql-fmt";
120+
statusBar.command = "uroborosql-fmt.show-output";
121+
122+
return statusBar;
123+
}
124+
73125
export function deactivate(): Thenable<void> | undefined {
74126
if (!client) {
75127
return undefined;

server/src/server.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,12 @@ async function formatText(
210210

211211
try {
212212
formattedText = runfmt(text, configPath);
213+
// ステータスバーの背景を通常色に変更
214+
connection.sendRequest("custom/normal", []);
213215
} catch (e) {
214216
console.error(e);
217+
// ステータスバーの背景を赤色に変更
218+
connection.sendRequest("custom/error", []);
215219
return [];
216220
}
217221

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

0 commit comments

Comments
 (0)