Skip to content

Commit eb5ec1b

Browse files
committed
Use warning for partial mode language status item
1 parent af345ef commit eb5ec1b

File tree

1 file changed

+67
-44
lines changed

1 file changed

+67
-44
lines changed

extensions/typescript-language-features/src/ui/intellisenseStatus.ts

+67-44
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { isImplicitProjectConfigFile, openOrCreateConfig, openProjectConfigForFi
1414

1515
const localize = nls.loadMessageBundle();
1616

17-
1817
namespace IntellisenseState {
1918
export const enum Type { None, Pending, Resolved, SyntaxOnly }
2019

@@ -51,7 +50,7 @@ export class IntellisenseStatus extends Disposable {
5150
public readonly openOpenConfigCommandId = '_typescript.openConfig';
5251
public readonly createConfigCommandId = '_typescript.createConfig';
5352

54-
private readonly _statusItem: vscode.LanguageStatusItem;
53+
private _statusItem?: vscode.LanguageStatusItem;
5554

5655
private _ready = false;
5756
private _state: IntellisenseState.State = IntellisenseState.None;
@@ -63,9 +62,6 @@ export class IntellisenseStatus extends Disposable {
6362
) {
6463
super();
6564

66-
this._statusItem = this._register(vscode.languages.createLanguageStatusItem('typescript.projectStatus', jsTsLanguageModes));
67-
this._statusItem.name = localize('statusItem.name', "JS/TS IntelliSense Status");
68-
6965
commandManager.register({
7066
id: this.openOpenConfigCommandId,
7167
execute: async (rootPath: string, projectType: ProjectType) => {
@@ -91,6 +87,11 @@ export class IntellisenseStatus extends Disposable {
9187
});
9288
}
9389

90+
override dispose() {
91+
super.dispose();
92+
this._statusItem?.dispose();
93+
}
94+
9495
private async updateStatus() {
9596
const doc = this._activeTextEditorManager.activeJsTsEditor?.document;
9697
if (!doc || !isSupportedLanguageMode(doc)) {
@@ -140,55 +141,77 @@ export class IntellisenseStatus extends Disposable {
140141

141142
switch (this._state.type) {
142143
case IntellisenseState.Type.None:
144+
this._statusItem?.dispose();
145+
this._statusItem = undefined;
143146
break;
144147

145148
case IntellisenseState.Type.Pending:
146-
this._statusItem.text = '$(loading~spin)';
147-
this._statusItem.detail = localize('pending.detail', 'Loading IntelliSense status');
148-
this._statusItem.command = undefined;
149-
break;
149+
{
150+
const statusItem = this.ensureStatusItem();
151+
statusItem.severity = vscode.LanguageStatusSeverity.Information;
152+
statusItem.text = '$(loading~spin)';
153+
statusItem.detail = localize('pending.detail', 'Loading IntelliSense status');
154+
statusItem.command = undefined;
155+
break;
156+
}
150157

151158
case IntellisenseState.Type.Resolved:
152-
const rootPath = this._client.getWorkspaceRootForResource(this._state.resource);
153-
if (!rootPath) {
154-
return;
159+
{
160+
const rootPath = this._client.getWorkspaceRootForResource(this._state.resource);
161+
if (!rootPath) {
162+
return;
163+
}
164+
165+
const statusItem = this.ensureStatusItem();
166+
statusItem.severity = vscode.LanguageStatusSeverity.Information;
167+
if (isImplicitProjectConfigFile(this._state.configFile)) {
168+
statusItem.text = this._state.projectType === ProjectType.TypeScript
169+
? localize('resolved.detail.noTsConfig', "No tsconfig")
170+
: localize('resolved.detail.noJsConfig', "No jsconfig");
171+
172+
statusItem.detail = undefined;
173+
statusItem.command = {
174+
command: this.createConfigCommandId,
175+
title: this._state.projectType === ProjectType.TypeScript
176+
? localize('resolved.command.title.createTsconfig', "Create tsconfig")
177+
: localize('resolved.command.title.createJsconfig', "Create jsconfig"),
178+
arguments: [rootPath],
179+
};
180+
} else {
181+
statusItem.text = vscode.workspace.asRelativePath(this._state.configFile);
182+
statusItem.detail = undefined;
183+
statusItem.command = {
184+
command: this.openOpenConfigCommandId,
185+
title: localize('resolved.command.title.open', "Open config file"),
186+
arguments: [rootPath],
187+
};
188+
}
155189
}
190+
break;
156191

157-
if (isImplicitProjectConfigFile(this._state.configFile)) {
158-
this._statusItem.text = this._state.projectType === ProjectType.TypeScript
159-
? localize('resolved.detail.noTsConfig', "No tsconfig")
160-
: localize('resolved.detail.noJsConfig', "No jsconfig");
161-
162-
this._statusItem.detail = undefined;
163-
this._statusItem.command = {
164-
command: this.createConfigCommandId,
165-
title: this._state.projectType === ProjectType.TypeScript
166-
? localize('resolved.command.title.createTsconfig', "Create tsconfig")
167-
: localize('resolved.command.title.createJsconfig', "Create jsconfig"),
168-
arguments: [rootPath],
169-
};
170-
} else {
171-
this._statusItem.text = vscode.workspace.asRelativePath(this._state.configFile);
172-
this._statusItem.detail = undefined;
173-
this._statusItem.command = {
174-
command: this.openOpenConfigCommandId,
175-
title: localize('resolved.command.title.open', "Open config file"),
176-
arguments: [rootPath],
192+
case IntellisenseState.Type.SyntaxOnly:
193+
{
194+
const statusItem = this.ensureStatusItem();
195+
statusItem.severity = vscode.LanguageStatusSeverity.Warning;
196+
statusItem.text = localize('syntaxOnly.text', 'Partial Mode');
197+
statusItem.detail = localize('syntaxOnly.detail', 'Project Wide IntelliSense not available');
198+
statusItem.command = {
199+
title: localize('syntaxOnly.command.title.learnMore', "Learn More"),
200+
command: 'vscode.open',
201+
arguments: [
202+
vscode.Uri.parse('https://aka.ms/vscode/jsts/partial-mode'),
203+
]
177204
};
205+
break;
178206
}
179-
break;
207+
}
208+
}
180209

181-
case IntellisenseState.Type.SyntaxOnly:
182-
this._statusItem.text = localize('syntaxOnly.text', 'Partial Mode');
183-
this._statusItem.detail = localize('syntaxOnly.detail', 'Project Wide IntelliSense not available');
184-
this._statusItem.command = {
185-
title: localize('syntaxOnly.command.title.learnMore', "Learn More"),
186-
command: 'vscode.open',
187-
arguments: [
188-
vscode.Uri.parse('https://aka.ms/vscode/jsts/partial-mode'),
189-
]
190-
};
191-
break;
210+
private ensureStatusItem(): vscode.LanguageStatusItem {
211+
if (!this._statusItem) {
212+
this._statusItem = vscode.languages.createLanguageStatusItem('typescript.projectStatus', jsTsLanguageModes);
213+
this._statusItem.name = localize('statusItem.name', "JS/TS IntelliSense Status");
192214
}
215+
return this._statusItem;
193216
}
194217
}

0 commit comments

Comments
 (0)