Skip to content

Commit

Permalink
Also track textCompletion for the syntax server.
Browse files Browse the repository at this point in the history
- Move registerCodeCompletionTelemetryListener just before language
  client is initialized

Signed-off-by: Roland Grunberg <[email protected]>
  • Loading branch information
rgrunber committed Oct 3, 2023
1 parent 3b1dd81 commit 658a41b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
23 changes: 21 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import * as fse from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
import { CodeActionContext, commands, ConfigurationTarget, Diagnostic, env, EventEmitter, ExtensionContext, extensions, IndentAction, InputBoxOptions, languages, RelativePattern, TextDocument, UIKind, Uri, ViewColumn, window, workspace, WorkspaceConfiguration, ProgressLocation, Position, Selection, Range } from 'vscode';
import { CancellationToken, CodeActionParams, CodeActionRequest, Command, DidChangeConfigurationNotification, ExecuteCommandParams, ExecuteCommandRequest, LanguageClientOptions, RevealOutputChannelOn } from 'vscode-languageclient';
import { CancellationToken, CodeActionParams, CodeActionRequest, Command, CompletionRequest, DidChangeConfigurationNotification, ExecuteCommandParams, ExecuteCommandRequest, LanguageClientOptions, RevealOutputChannelOn } from 'vscode-languageclient';
import { LanguageClient } from 'vscode-languageclient/node';
import { apiManager } from './apiManager';
import { ClientErrorHandler } from './clientErrorHandler';
import { Commands } from './commands';
import { ClientStatus, ExtensionAPI } from './extension.api';
import { ClientStatus, ExtensionAPI, TraceEvent } from './extension.api';
import * as fileEventHandler from './fileEventHandler';
import { getSharedIndexCache, HEAP_DUMP_LOCATION, prepareExecutable } from './javaServerStarter';
import { initializeLogFile, logger } from './log';
Expand Down Expand Up @@ -273,6 +273,7 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
};

apiManager.initialize(requirements, serverMode);
registerCodeCompletionTelemetryListener();
resolve(apiManager.getApiInstance());
// the promise is resolved
// no need to pass `resolve` into any code past this point,
Expand Down Expand Up @@ -983,6 +984,24 @@ async function cleanJavaWorkspaceStorage() {
}
}

export function registerCodeCompletionTelemetryListener() {
apiManager.getApiInstance().onDidRequestEnd((traceEvent: TraceEvent) => {
if (traceEvent.type === CompletionRequest.method) {
// Exclude the invalid completion requests.
if (!traceEvent.resultLength) {
return;
}
const props = {
duration: Math.round(traceEvent.duration * 100) / 100,
resultLength: traceEvent.resultLength || 0,
error: !!traceEvent.error,
fromSyntaxServer: !!traceEvent.fromSyntaxServer,
};
return Telemetry.sendTelemetry(Telemetry.COMPLETION_EVENT, props);
}
});
}

function registerOutOfMemoryDetection(storagePath: string) {
const heapDumpFolder = getHeapDumpFolderFromSettings() || storagePath;
chokidar.watch(`${heapDumpFolder}/java_*.hprof`, { ignoreInitial: true }).on('add', path => {
Expand Down
21 changes: 1 addition & 20 deletions src/standardLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { apiManager } from "./apiManager";
import * as buildPath from './buildpath';
import { javaRefactorKinds, RefactorDocumentProvider } from "./codeActionProvider";
import { Commands } from "./commands";
import { ClientStatus, TraceEvent } from "./extension.api";
import { ClientStatus } from "./extension.api";
import * as fileEventHandler from './fileEventHandler';
import { gradleCodeActionMetadata, GradleCodeActionProvider } from "./gradle/gradleCodeActionProvider";
import { awaitServerConnection, prepareExecutable, DEBUG } from "./javaServerStarter";
Expand Down Expand Up @@ -147,7 +147,6 @@ export class StandardLanguageClient {
// Disable the client-side snippet provider since LS is ready.
snippetCompletionProvider.dispose();
registerDocumentValidationListener(context, this.languageClient);
registerCodeCompletionTelemetryListener();
commands.executeCommand('setContext', 'javaLSReady', true);
break;
case 'Started':
Expand Down Expand Up @@ -814,22 +813,4 @@ export async function applyWorkspaceEdit(workspaceEdit: WorkspaceEdit, languageC
} else {
return Promise.resolve(true);
}
}

export function registerCodeCompletionTelemetryListener() {
apiManager.getApiInstance().onDidRequestEnd((traceEvent: TraceEvent) => {
if (traceEvent.type === CompletionRequest.method) {
// Exclude the invalid completion requests.
if (!traceEvent.resultLength) {
return;
}
const props = {
duration: Math.round(traceEvent.duration * 100) / 100,
resultLength: traceEvent.resultLength || 0,
error: !!traceEvent.error,
fromSyntaxServer: !!traceEvent.fromSyntaxServer,
};
return Telemetry.sendTelemetry(Telemetry.COMPLETION_EVENT, props);
}
});
}

0 comments on commit 658a41b

Please sign in to comment.