Skip to content

Commit

Permalink
Fix race on 'projectInfo' requests
Browse files Browse the repository at this point in the history
Fixes #101076

Make sure we fully start the TS Server (including uploading files) before sending the 'projectInfo' request for the status bar item
  • Loading branch information
mjbvz committed Jun 25, 2020
1 parent c149311 commit 32e6693
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
Expand Up @@ -50,7 +50,6 @@ export default class TypeScriptServiceClientHost extends Disposable {
private readonly languagePerId = new Map<string, LanguageProvider>();

private readonly typingsStatus: TypingsStatus;
private readonly versionStatus: VersionStatus;

private readonly fileConfigurationManager: FileConfigurationManager;

Expand All @@ -69,7 +68,6 @@ export default class TypeScriptServiceClientHost extends Disposable {
const allModeIds = this.getAllModeIds(descriptions, pluginManager);
this.client = this._register(new TypeScriptServiceClient(
workspaceState,
version => this.versionStatus.onDidChangeTypeScriptVersion(version),
pluginManager,
logDirectoryProvider,
allModeIds));
Expand All @@ -81,8 +79,7 @@ export default class TypeScriptServiceClientHost extends Disposable {
this.client.onConfigDiagnosticsReceived(diag => this.configFileDiagnosticsReceived(diag), null, this._disposables);
this.client.onResendModelsRequested(() => this.populateService(), null, this._disposables);

this.versionStatus = this._register(new VersionStatus(this.client, commandManager));

this._register(new VersionStatus(this.client, commandManager));
this._register(new AtaProgressReporter(this.client));
this.typingsStatus = this._register(new TypingsStatus(this.client));
this.fileConfigurationManager = this._register(new FileConfigurationManager(this.client));
Expand Down
Expand Up @@ -9,6 +9,7 @@ import * as Proto from './protocol';
import API from './utils/api';
import { TypeScriptServiceConfiguration } from './utils/configuration';
import { PluginManager } from './utils/plugins';
import { TypeScriptVersion } from './utils/versionProvider';

export namespace ServerResponse {

Expand Down Expand Up @@ -113,7 +114,7 @@ export interface ITypeScriptServiceClient {

getWorkspaceRootForResource(resource: vscode.Uri): string | undefined;

readonly onTsServerStarted: vscode.Event<API>;
readonly onTsServerStarted: vscode.Event<{ version: TypeScriptVersion, usedApiVersion: API }>;
readonly onProjectLanguageServiceStateChanged: vscode.Event<Proto.ProjectLanguageServiceStateEventBody>;
readonly onDidBeginInstallTypings: vscode.Event<Proto.BeginInstallTypesEventBody>;
readonly onDidEndInstallTypings: vscode.Event<Proto.EndInstallTypesEventBody>;
Expand Down
Expand Up @@ -121,7 +121,6 @@ export default class TypeScriptServiceClient extends Disposable implements IType

constructor(
private readonly workspaceState: vscode.Memento,
private readonly onDidChangeTypeScriptVersion: (version: TypeScriptVersion) => void,
public readonly pluginManager: PluginManager,
private readonly logDirectoryProvider: LogDirectoryProvider,
allModeIds: readonly string[]
Expand Down Expand Up @@ -239,7 +238,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
this.serverState = this.startService(true);
}

private readonly _onTsServerStarted = this._register(new vscode.EventEmitter<API>());
private readonly _onTsServerStarted = this._register(new vscode.EventEmitter<{ version: TypeScriptVersion, usedApiVersion: API }>());
public readonly onTsServerStarted = this._onTsServerStarted.event;

private readonly _onDiagnosticsReceived = this._register(new vscode.EventEmitter<TsDiagnostics>());
Expand Down Expand Up @@ -339,7 +338,6 @@ export default class TypeScriptServiceClient extends Disposable implements IType
onFatalError: (command, err) => this.fatalError(command, err),
});
this.serverState = new ServerState.Running(handle, apiVersion, undefined, true);
this.onDidChangeTypeScriptVersion(version);
this.lastStart = Date.now();

/* __GDPR__
Expand Down Expand Up @@ -416,15 +414,15 @@ export default class TypeScriptServiceClient extends Disposable implements IType
handle.onReaderError(error => this.error('ReaderError', error));
handle.onEvent(event => this.dispatchEvent(event));

this._onReady!.resolve();
this._onTsServerStarted.fire(apiVersion);

if (apiVersion.gte(API.v300)) {
this.loadingIndicator.startedLoadingProject(undefined /* projectName */);
}

this.serviceStarted(resendModels);

this._onReady!.resolve();
this._onTsServerStarted.fire({ version: version, usedApiVersion: apiVersion });

return this.serverState;
}

Expand Down
Expand Up @@ -151,9 +151,11 @@ export default class VersionStatus extends Disposable {
this._ready = true;
this.updateStatus();
});

this._register(this._client.onTsServerStarted(({ version }) => this.onDidChangeTypeScriptVersion(version)));
}

public onDidChangeTypeScriptVersion(version: TypeScriptVersion) {
private onDidChangeTypeScriptVersion(version: TypeScriptVersion) {
this._statusBarEntry.text = version.displayName;
this._statusBarEntry.tooltip = version.path;
this.updateStatus();
Expand Down

0 comments on commit 32e6693

Please sign in to comment.