Skip to content

Commit

Permalink
feat(vscode): migrate to LanguageStatusItem
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Mar 19, 2024
1 parent 1a2e5fc commit 95630c4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
22 changes: 8 additions & 14 deletions packages/vscode/lib/features/tsVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ export function activate(
) {

const subscriptions: vscode.Disposable[] = [];
const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
statusBar.command = cmd;
const statusBar = vscode.languages.createLanguageStatusItem(cmd, selector);
statusBar.command = {
title: 'Select Version',
command: cmd,
};

subscriptions.push({ dispose: () => statusBar.dispose() });
subscriptions.push(vscode.commands.registerCommand(cmd, onCommand));
Expand Down Expand Up @@ -74,18 +77,9 @@ export function activate(
}

async function updateStatusBar() {
if (
!vscode.window.activeTextEditor
|| !vscode.languages.match(selector, vscode.window.activeTextEditor.document)
) {
statusBar.hide();
}
else {
const tsVersion = (await getTsdk(context)).version;
statusBar.text = tsVersion ?? 'x.x.x';
statusBar.text = resolveStatusText(statusBar.text);
statusBar.show();
}
const tsVersion = (await getTsdk(context)).version;
statusBar.text = tsVersion ?? 'x.x.x';
statusBar.text = resolveStatusText(statusBar.text);
}

async function reloadServers() {
Expand Down
38 changes: 19 additions & 19 deletions packages/vscode/lib/features/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function activate(
) {

const subscriptions: vscode.Disposable[] = [];
const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
const statusBar = vscode.languages.createLanguageStatusItem(cmd, selector);
let currentTsconfigUri: vscode.Uri | undefined;

updateStatusBar();
Expand All @@ -31,26 +31,26 @@ export function activate(
!vscode.window.activeTextEditor
|| !vscode.languages.match(selector, vscode.window.activeTextEditor.document)
) {
statusBar.hide();
return;
}
else {
const tsconfig = await client.sendRequest(
GetMatchTsConfigRequest.type,
client.code2ProtocolConverter.asTextDocumentIdentifier(vscode.window.activeTextEditor.document),
const tsconfig = await client.sendRequest(
GetMatchTsConfigRequest.type,
client.code2ProtocolConverter.asTextDocumentIdentifier(vscode.window.activeTextEditor.document),
);
if (tsconfig?.uri) {
currentTsconfigUri = vscode.Uri.parse(tsconfig.uri);
statusBar.text = path.relative(
(vscode.workspace.rootPath?.replace(/\\/g, '/') || '/'),
currentTsconfigUri.fsPath.replace(/\\/g, '/'),
);
if (tsconfig?.uri) {
currentTsconfigUri = vscode.Uri.parse(tsconfig.uri);
statusBar.text = path.relative(
(vscode.workspace.rootPath?.replace(/\\/g, '/') || '/'),
currentTsconfigUri.fsPath.replace(/\\/g, '/'),
);
statusBar.command = cmd;
}
else {
statusBar.text = 'No tsconfig';
statusBar.command = undefined;
}
statusBar.show();
statusBar.command = {
title: 'Open config file',
command: cmd,
};
}
else {
statusBar.text = 'No tsconfig';
statusBar.command = undefined;
}
}
}

0 comments on commit 95630c4

Please sign in to comment.