@@ -5,13 +5,13 @@ import { findRuntimes } from "jdk-utils";
55import * as net from 'net' ;
66import * as path from 'path' ;
77import { CancellationToken , CodeActionKind , commands , ConfigurationTarget , DocumentSelector , EventEmitter , ExtensionContext , extensions , languages , Location , ProgressLocation , TextEditor , Uri , ViewColumn , window , workspace } from "vscode" ;
8- import { ConfigurationParams , ConfigurationRequest , LanguageClientOptions , Location as LSLocation , MessageType , Position as LSPosition , TextDocumentPositionParams , WorkspaceEdit } from "vscode-languageclient" ;
8+ import { ConfigurationParams , ConfigurationRequest , LanguageClientOptions , Location as LSLocation , MessageType , Position as LSPosition , TextDocumentPositionParams , WorkspaceEdit , CompletionRequest } from "vscode-languageclient" ;
99import { LanguageClient , StreamInfo } from "vscode-languageclient/node" ;
1010import { apiManager } from "./apiManager" ;
1111import * as buildPath from './buildpath' ;
1212import { javaRefactorKinds , RefactorDocumentProvider } from "./codeActionProvider" ;
1313import { Commands } from "./commands" ;
14- import { ClientStatus } from "./extension.api" ;
14+ import { ClientStatus , TraceEvent } from "./extension.api" ;
1515import * as fileEventHandler from './fileEventHandler' ;
1616import { gradleCodeActionMetadata , GradleCodeActionProvider } from "./gradle/gradleCodeActionProvider" ;
1717import { awaitServerConnection , prepareExecutable , DEBUG } from "./javaServerStarter" ;
@@ -154,6 +154,7 @@ export class StandardLanguageClient {
154154 // Disable the client-side snippet provider since LS is ready.
155155 snippetCompletionProvider . dispose ( ) ;
156156 registerDocumentValidationListener ( context , this . languageClient ) ;
157+ registerCodeCompletionTelemetryListener ( ) ;
157158 break ;
158159 case 'Started' :
159160 this . status = ClientStatus . started ;
@@ -820,3 +821,20 @@ export async function applyWorkspaceEdit(workspaceEdit: WorkspaceEdit, languageC
820821 return Promise . resolve ( true ) ;
821822 }
822823}
824+
825+ export function registerCodeCompletionTelemetryListener ( ) {
826+ apiManager . getApiInstance ( ) . onDidRequestEnd ( ( traceEvent : TraceEvent ) => {
827+ if ( traceEvent . type === CompletionRequest . method ) {
828+ // Exclude the invalid completion requests.
829+ if ( ! traceEvent . resultLength ) {
830+ return ;
831+ }
832+ const props = {
833+ duration : Math . round ( traceEvent . duration * 100 ) / 100 ,
834+ resultLength : traceEvent . resultLength || 0 ,
835+ error : ! ! traceEvent . error ,
836+ } ;
837+ return Telemetry . sendTelemetry ( Telemetry . COMPLETION_EVENT , props ) ;
838+ }
839+ } ) ;
840+ }
0 commit comments