Skip to content

Commit

Permalink
Add support for telemetry from LS and remove obsolete LS option (micr…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Arkhipov authored and DonJayamanne committed Oct 23, 2018
1 parent dbe3652 commit c4074b9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 25 deletions.
34 changes: 23 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions src/client/activation/interpreterDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class InterpreterData {
// tslint:disable-next-line:no-shadowed-variable
public readonly path: string,
public readonly version: string,
public readonly prefix: string,
public readonly searchPaths: string,
public readonly hash: string
) { }
Expand Down Expand Up @@ -81,26 +80,23 @@ export class InterpreterDataService {
}

private async getInterpreterDataFromPython(execService: IPythonExecutionService, interpreterPath: string): Promise<InterpreterData> {
const result = await execService.exec(['-c', 'import sys; print(sys.version_info); print(sys.prefix)'], {});
// 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) <<SOMETIMES NEW LINE HERE>>
// [MSC v.1500 32 bit (Intel)]
// C:\Python27
const result = await execService.exec(['-c', 'import sys; print(sys.version_info)'], {});
// sys.version_info(major=3, minor=6, micro=6, releaselevel='final', serial=0)
if (!result.stdout) {
throw Error('Unable to determine Python interpreter version and system prefix.');
}
const output = result.stdout.splitLines({ removeEmptyEntries: true, trim: true });
if (!output || output.length < 2) {
if (!output || output.length < 1) {
throw Error('Unable to parse version and and system prefix from the Python interpreter output.');
}
const majorMatches = output[0].match(/major=(\d*?),/);
const minorMatches = output[0].match(/minor=(\d*?),/);
if (!majorMatches || majorMatches.length < 2 || !minorMatches || minorMatches.length < 2) {
throw Error('Unable to parse interpreter version.');
}
const prefix = output[output.length - 1];
const hash = await this.getInterpreterHash(interpreterPath);
const searchPaths = await this.getSearchPaths(execService);
return new InterpreterData(DataVersion, interpreterPath, `${majorMatches[1]}.${minorMatches[1]}`, prefix, searchPaths, hash);
return new InterpreterData(DataVersion, interpreterPath, `${majorMatches[1]}.${minorMatches[1]}`, searchPaths, hash);
}

private async getSearchPaths(execService: IPythonExecutionService): Promise<string> {
Expand Down
12 changes: 7 additions & 5 deletions src/client/activation/languageServer/languageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import { LanguageServerSymbolProvider } from '../../providers/symbolProvider';
import { sendTelemetryEvent } from '../../telemetry';
import {
PYTHON_LANGUAGE_SERVER_ENABLED,
PYTHON_LANGUAGE_SERVER_ERROR
PYTHON_LANGUAGE_SERVER_ERROR,
PYTHON_LANGUAGE_SERVER_TELEMETRY
} from '../../telemetry/constants';
import { IUnitTestManagementService } from '../../unittests/types';
import { LanguageServerDownloader } from '../downloader';
Expand Down Expand Up @@ -164,6 +165,10 @@ export class LanguageServerExtensionActivator implements IExtensionActivator {
this.languageClient = this.createSelfContainedLanguageClient(serverModule, clientOptions);
try {
await this.startLanguageClient();
this.languageClient.onTelemetry(telemetryEvent => {
const eventName = telemetryEvent.Name ? telemetryEvent.Name : PYTHON_LANGUAGE_SERVER_TELEMETRY;
sendTelemetryEvent(eventName, telemetryEvent.Measurements, telemetryEvent.Properties);
});
return true;
} catch (ex) {
this.appShell.showErrorMessage(`Language server failed to start. Error ${ex}`);
Expand Down Expand Up @@ -212,8 +217,7 @@ export class LanguageServerExtensionActivator implements IExtensionActivator {

// tslint:disable-next-line:member-ordering
public async getAnalysisOptions(): Promise<LanguageClientOptions | undefined> {
// tslint:disable-next-line:no-any
const properties = new Map<string, any>();
const properties = new Map<string, {}>();
let interpreterData: InterpreterData | undefined;
let pythonPath = '';

Expand All @@ -231,8 +235,6 @@ export class LanguageServerExtensionActivator implements IExtensionActivator {
properties['InterpreterPath'] = interpreterData.path;
// tslint:disable-next-line:no-string-literal
properties['Version'] = interpreterData.version;
// tslint:disable-next-line:no-string-literal
properties['PrefixPath'] = interpreterData.prefix;
}

// tslint:disable-next-line:no-string-literal
Expand Down
1 change: 1 addition & 0 deletions src/client/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const PYTHON_LANGUAGE_SERVER_DOWNLOADED = 'PYTHON_LANGUAGE_SERVER.DOWNLOA
export const PYTHON_LANGUAGE_SERVER_ERROR = 'PYTHON_LANGUAGE_SERVER.ERROR';
export const PYTHON_LANGUAGE_SERVER_STARTUP = 'PYTHON_LANGUAGE_SERVER.STARTUP';
export const PYTHON_LANGUAGE_SERVER_PLATFORM_NOT_SUPPORTED = 'PYTHON_LANGUAGE_SERVER.PLATFORM_NOT_SUPPORTED';
export const PYTHON_LANGUAGE_SERVER_TELEMETRY = 'PYTHON_LANGUAGE_SERVER.EVENT';

export const TERMINAL_CREATE = 'TERMINAL.CREATE';
export const PYTHON_LANGUAGE_SERVER_LIST_BLOB_STORE_PACKAGES = 'PYTHON_LANGUAGE_SERVER.LIST_BLOB_PACKAGES';
7 changes: 6 additions & 1 deletion src/client/telemetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type FormatTelemetry = {
formatSelection: boolean;
};

export type LanguageServerTelemetry = {
export type LanguageServerVersionTelemetry = {
success: boolean;
lsVersion?: string;
};
Expand All @@ -24,6 +24,10 @@ export type LanguageServerErrorTelemetry = {
error: string;
};

export type LanguageServerTelemetry = {
[key: string]: string;
};

export type LinterTrigger = 'auto' | 'save';

export type LintingTelemetry = {
Expand Down Expand Up @@ -86,6 +90,7 @@ export type TerminalTelemetry = {
};
export type TelemetryProperties = FormatTelemetry
| LanguageServerTelemetry
| LanguageServerVersionTelemetry
| LanguageServerErrorTelemetry
| LintingTelemetry
| EditorLoadTelemetry
Expand Down

0 comments on commit c4074b9

Please sign in to comment.