Use toOpenedFilePath to ensure we don't ask TS server for projectInfo if a file is not open

This commit is contained in:
Matt Bierner 2020-11-11 15:50:21 -08:00
parent fb93010aa2
commit 7c6994d1b5
3 changed files with 7 additions and 6 deletions

View file

@ -58,7 +58,6 @@ class ProjectStatusCommand implements Command {
public async execute(): Promise<void> {
const info = this._delegate();
const result = await vscode.window.showQuickPick<QuickPickItem>(coalesce([
this.getProjectItem(info),
this.getVersionItem(),
@ -169,7 +168,7 @@ export default class VersionStatus extends Disposable {
const doc = vscode.window.activeTextEditor.document;
if (isTypeScriptDocument(doc)) {
const file = this._client.normalizedPath(doc.uri);
const file = this._client.toOpenedFilePath(doc, { suppressAlertOnFailure: true });
if (file) {
this._statusBarEntry.show();
if (!this._ready) {

View file

@ -147,7 +147,9 @@ export interface ITypeScriptServiceClient {
*
* @return The normalized path or `undefined` if the document is not open on the server.
*/
toOpenedFilePath(document: vscode.TextDocument): string | undefined;
toOpenedFilePath(document: vscode.TextDocument, options?: {
suppressAlertOnFailure?: boolean
}): string | undefined;
/**
* Checks if `resource` has a given capability.

View file

@ -661,14 +661,14 @@ export default class TypeScriptServiceClient extends Disposable implements IType
return this.normalizedPath(resource);
}
public toOpenedFilePath(document: vscode.TextDocument): string | undefined {
public toOpenedFilePath(document: vscode.TextDocument, options: { suppressAlertOnFailure?: boolean } = {}): string | undefined {
if (!this.bufferSyncSupport.ensureHasBuffer(document.uri)) {
if (!fileSchemes.disabledSchemes.has(document.uri.scheme)) {
if (!options.suppressAlertOnFailure && !fileSchemes.disabledSchemes.has(document.uri.scheme)) {
console.error(`Unexpected resource ${document.uri}`);
}
return undefined;
}
return this.toPath(document.uri) || undefined;
return this.toPath(document.uri);
}
public hasCapabilityForResource(resource: vscode.Uri, capability: ClientCapability): boolean {