Log where the typescript version is coming from

This commit is contained in:
Matt Bierner
2019-10-22 11:24:21 -07:00
parent 802d09f5f2
commit 07f1939ba2
2 changed files with 26 additions and 15 deletions

View File

@@ -299,11 +299,13 @@ export default class TypeScriptServiceClient extends Disposable implements IType
"${include}": [
"${TypeScriptCommonProperties}"
],
"localTypeScriptVersion": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
"localTypeScriptVersion": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"typeScriptVersionSource": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this.logTelemetry('tsserver.spawned', {
localTypeScriptVersion: this.versionProvider.localVersion ? this.versionProvider.localVersion.displayName : '',
typeScriptVersionSource: currentVersion.source,
});
handle.onError((err: Error) => {

View File

@@ -12,8 +12,17 @@ import { RelativeWorkspacePathResolver } from './relativePathResolver';
const localize = nls.loadMessageBundle();
export const enum TypeScriptVersionSource {
Bundled = 'bundled',
TsNightlyExtension = 'ts-nightly-extension',
NodeModules = 'node-modules',
UserSetting = 'user-setting',
WorkspaceSetting = 'workspace-setting',
}
export class TypeScriptVersion {
constructor(
public readonly source: TypeScriptVersionSource,
public readonly path: string,
private readonly _pathLabel?: string
) { }
@@ -23,7 +32,7 @@ export class TypeScriptVersion {
}
public get pathLabel(): string {
return typeof this._pathLabel === 'undefined' ? this.path : this._pathLabel;
return this._pathLabel ?? this.path;
}
public get isValid(): boolean {
@@ -103,7 +112,7 @@ export class TypeScriptVersionProvider {
public get globalVersion(): TypeScriptVersion | undefined {
if (this.configuration.globalTsdk) {
const globals = this.loadVersionsFromSetting(this.configuration.globalTsdk);
const globals = this.loadVersionsFromSetting(TypeScriptVersionSource.UserSetting, this.configuration.globalTsdk);
if (globals && globals.length) {
return globals[0];
}
@@ -137,7 +146,7 @@ export class TypeScriptVersionProvider {
}
public get bundledVersion(): TypeScriptVersion {
const version = this.getContributedVersion('vscode.typescript-language-features', ['..', 'node_modules']);
const version = this.getContributedVersion(TypeScriptVersionSource.Bundled, 'vscode.typescript-language-features', ['..', 'node_modules']);
if (version) {
return version;
}
@@ -149,15 +158,15 @@ export class TypeScriptVersionProvider {
}
private get contributedTsNextVersion(): TypeScriptVersion | undefined {
return this.getContributedVersion('ms-vscode.vscode-typescript-next', ['node_modules']);
return this.getContributedVersion(TypeScriptVersionSource.TsNightlyExtension, 'ms-vscode.vscode-typescript-next', ['node_modules']);
}
private getContributedVersion(extensionId: string, pathToTs: readonly string[]): TypeScriptVersion | undefined {
private getContributedVersion(source: TypeScriptVersionSource, extensionId: string, pathToTs: readonly string[]): TypeScriptVersion | undefined {
try {
const extension = vscode.extensions.getExtension(extensionId);
if (extension) {
const typescriptPath = path.join(extension.extensionPath, ...pathToTs, 'typescript', 'lib');
const bundledVersion = new TypeScriptVersion(typescriptPath, '');
const bundledVersion = new TypeScriptVersion(source, typescriptPath, '');
if (bundledVersion.isValid) {
return bundledVersion;
}
@@ -170,28 +179,28 @@ export class TypeScriptVersionProvider {
private get localTsdkVersions(): TypeScriptVersion[] {
const localTsdk = this.configuration.localTsdk;
return localTsdk ? this.loadVersionsFromSetting(localTsdk) : [];
return localTsdk ? this.loadVersionsFromSetting(TypeScriptVersionSource.WorkspaceSetting, localTsdk) : [];
}
private loadVersionsFromSetting(tsdkPathSetting: string): TypeScriptVersion[] {
private loadVersionsFromSetting(source: TypeScriptVersionSource, tsdkPathSetting: string): TypeScriptVersion[] {
if (path.isAbsolute(tsdkPathSetting)) {
return [new TypeScriptVersion(tsdkPathSetting)];
return [new TypeScriptVersion(source, tsdkPathSetting)];
}
const workspacePath = RelativeWorkspacePathResolver.asAbsoluteWorkspacePath(tsdkPathSetting);
if (workspacePath !== undefined) {
return [new TypeScriptVersion(workspacePath, tsdkPathSetting)];
return [new TypeScriptVersion(source, workspacePath, tsdkPathSetting)];
}
return this.loadTypeScriptVersionsFromPath(tsdkPathSetting);
return this.loadTypeScriptVersionsFromPath(source, tsdkPathSetting);
}
private get localNodeModulesVersions(): TypeScriptVersion[] {
return this.loadTypeScriptVersionsFromPath(path.join('node_modules', 'typescript', 'lib'))
return this.loadTypeScriptVersionsFromPath(TypeScriptVersionSource.NodeModules, path.join('node_modules', 'typescript', 'lib'))
.filter(x => x.isValid);
}
private loadTypeScriptVersionsFromPath(relativePath: string): TypeScriptVersion[] {
private loadTypeScriptVersionsFromPath(source: TypeScriptVersionSource, relativePath: string): TypeScriptVersion[] {
if (!vscode.workspace.workspaceFolders) {
return [];
}
@@ -203,7 +212,7 @@ export class TypeScriptVersionProvider {
label = path.join(root.name, relativePath);
}
versions.push(new TypeScriptVersion(path.join(root.uri.fsPath, relativePath), label));
versions.push(new TypeScriptVersion(source, path.join(root.uri.fsPath, relativePath), label));
}
return versions;
}