Skip to content

Commit ce94d13

Browse files
committed
Added telemetry for code refactoring
1 parent 6ccef3d commit ce94d13

2 files changed

Lines changed: 27 additions & 16 deletions

File tree

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
export namespace Debugger {
2-
export const Load = "DEBUGGER_LOAD";
3-
export const Attach = "DEBUGGER_ATTACH";
2+
export const Load = 'DEBUGGER_LOAD';
3+
export const Attach = 'DEBUGGER_ATTACH';
44
}
55
export namespace Commands {
6-
export const SortImports = "COMMAND_SORT_IMPORTS";
7-
export const UnitTests = "COMMAND_UNIT_TEST";
6+
export const SortImports = 'COMMAND_SORT_IMPORTS';
7+
export const UnitTests = 'COMMAND_UNIT_TEST';
88
}
99
export namespace IDE {
10-
export const Completion = "CODE_COMPLETION";
11-
export const Definition = "CODE_DEFINITION";
12-
export const Format = "CODE_FORMAT";
13-
export const HoverDefinition = "CODE_HOVER_DEFINITION";
14-
export const Reference = "CODE_REFERENCE";
15-
export const Rename = "CODE_RENAME";
16-
export const Symbol = "CODE_SYMBOL";
17-
export const Lint = "LINTING";
10+
export const Completion = 'CODE_COMPLETION';
11+
export const Definition = 'CODE_DEFINITION';
12+
export const Format = 'CODE_FORMAT';
13+
export const HoverDefinition = 'CODE_HOVER_DEFINITION';
14+
export const Reference = 'CODE_REFERENCE';
15+
export const Rename = 'CODE_RENAME';
16+
export const Symbol = 'CODE_SYMBOL';
17+
export const Lint = 'LINTING';
1818
}
19-
export const EVENT_LOAD = "IDE_LOAD";
19+
export namespace REFACTOR {
20+
export const ExtractVariable = 'REFACTOR_EXTRACT_VAR';
21+
export const ExtractMethod = 'REFACTOR_EXTRACT_METHOD';
22+
}
23+
export const EVENT_LOAD = 'IDE_LOAD';

src/client/refactor/proxy.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import * as child_process from 'child_process';
77
import {ExtractResult} from './contracts';
88
import {execPythonFile} from '../common/utils';
99
import {IPythonSettings} from '../common/configSettings';
10+
import {REFACTOR} from '../common/telemetryContracts';
11+
import {sendTelemetryEvent, Delays} from '../common/telemetry';
1012

1113
const ROPE_PYTHON_VERSION = 'Currently code refactoring is only supported in Python 2.x';
1214
const ERROR_PREFIX = '$ERROR';
@@ -39,13 +41,14 @@ export class RefactorProxy extends vscode.Disposable {
3941
}
4042
extractVariable<T>(document: vscode.TextDocument, name: string, filePath: string, range: vscode.Range): Promise<T> {
4143
let command = `{"lookup":"extract_variable", "file":"${filePath}", "start":"${document.offsetAt(range.start)}", "end":"${document.offsetAt(range.end)}", "id":"1", "name":"${name}"}`;
42-
return this.sendCommand<T>(command);
44+
return this.sendCommand<T>(command, REFACTOR.ExtractVariable);
4345
}
4446
extractMethod<T>(document: vscode.TextDocument, name: string, filePath: string, range: vscode.Range): Promise<T> {
4547
let command = `{"lookup":"extract_method", "file":"${filePath}", "start":"${document.offsetAt(range.start)}", "end":"${document.offsetAt(range.end)}", "id":"1","name":"${name}"}`;
46-
return this.sendCommand<T>(command);
48+
return this.sendCommand<T>(command, REFACTOR.ExtractVariable);
4749
}
48-
private sendCommand<T>(command: string): Promise<T> {
50+
private sendCommand<T>(command: string, telemetryEvent: string): Promise<T> {
51+
let timer = new Delays();
4952
return this.pickValidPythonPath().then(pythonPath => {
5053
return this.initialize(pythonPath);
5154
}).then(() => {
@@ -54,6 +57,10 @@ export class RefactorProxy extends vscode.Disposable {
5457
this._commandReject = reject;
5558
this._process.stdin.write(command + '\n');
5659
});
60+
}).then(value => {
61+
timer.stop();
62+
sendTelemetryEvent(telemetryEvent, null, timer.toMeasures());
63+
return value;
5764
});
5865
}
5966

0 commit comments

Comments
 (0)