@@ -7,6 +7,8 @@ import * as child_process from 'child_process';
77import { ExtractResult } from './contracts' ;
88import { execPythonFile } from '../common/utils' ;
99import { IPythonSettings } from '../common/configSettings' ;
10+ import { REFACTOR } from '../common/telemetryContracts' ;
11+ import { sendTelemetryEvent , Delays } from '../common/telemetry' ;
1012
1113const ROPE_PYTHON_VERSION = 'Currently code refactoring is only supported in Python 2.x' ;
1214const 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