From 38e46c9a4d688eb27c8a0696bec16a6bc8c0384a Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 22 Oct 2020 13:58:38 +0000 Subject: [PATCH] duration for word based suggestions, Perf telemetry for completions #109167 --- src/vs/editor/common/services/editorSimpleWorker.ts | 7 ++++--- .../editor/common/services/editorWorkerServiceImpl.ts | 11 ++++++----- .../test/common/services/editorSimpleWorker.test.ts | 5 +++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/vs/editor/common/services/editorSimpleWorker.ts b/src/vs/editor/common/services/editorSimpleWorker.ts index 5a8391e91af..69592e735c6 100644 --- a/src/vs/editor/common/services/editorSimpleWorker.ts +++ b/src/vs/editor/common/services/editorSimpleWorker.ts @@ -23,6 +23,7 @@ import { IDiffComputationResult } from 'vs/editor/common/services/editorWorkerSe import { createMonacoBaseAPI } from 'vs/editor/common/standalone/standaloneBase'; import * as types from 'vs/base/common/types'; import { EditorWorkerHost } from 'vs/editor/common/services/editorWorkerServiceImpl'; +import { StopWatch } from 'vs/base/common/stopwatch'; export interface IMirrorModel { readonly uri: URI; @@ -529,13 +530,13 @@ export class EditorSimpleWorker implements IRequestHandler, IDisposable { private static readonly _suggestionsLimit = 10000; - public async textualSuggest(modelUrl: string, position: IPosition, wordDef: string, wordDefFlags: string): Promise { + public async textualSuggest(modelUrl: string, position: IPosition, wordDef: string, wordDefFlags: string): Promise<{ words: string[], duration: number } | null> { const model = this._getModel(modelUrl); if (!model) { return null; } - + const sw = new StopWatch(true); const words: string[] = []; const seen = new Set(); const wordDefRegExp = new RegExp(wordDef, wordDefFlags); @@ -558,7 +559,7 @@ export class EditorSimpleWorker implements IRequestHandler, IDisposable { break; } } - return words; + return { words, duration: sw.elapsed() }; } diff --git a/src/vs/editor/common/services/editorWorkerServiceImpl.ts b/src/vs/editor/common/services/editorWorkerServiceImpl.ts index 3ee2f5ad182..5976df3c226 100644 --- a/src/vs/editor/common/services/editorWorkerServiceImpl.ts +++ b/src/vs/editor/common/services/editorWorkerServiceImpl.ts @@ -161,20 +161,21 @@ class WordBasedCompletionItemProvider implements modes.CompletionItemProvider { const insert = replace.setEndPosition(position.lineNumber, position.column); const client = await this._workerManager.withWorker(); - const words = await client.textualSuggest(model.uri, position); - if (!words) { + const data = await client.textualSuggest(model.uri, position); + if (!data) { return undefined; } return { - suggestions: words.map((word): modes.CompletionItem => { + duration: data.duration, + suggestions: data.words.map((word): modes.CompletionItem => { return { kind: modes.CompletionItemKind.Text, label: word, insertText: word, range: { insert, replace } }; - }) + }), }; } } @@ -462,7 +463,7 @@ export class EditorWorkerClient extends Disposable { }); } - public textualSuggest(resource: URI, position: IPosition): Promise { + public textualSuggest(resource: URI, position: IPosition): Promise<{ words: string[], duration: number } | null> { return this._withSyncedResources([resource]).then(proxy => { let model = this._modelService.getModel(resource); if (!model) { diff --git a/src/vs/editor/test/common/services/editorSimpleWorker.test.ts b/src/vs/editor/test/common/services/editorSimpleWorker.test.ts index da25cab90cb..2b2a748c662 100644 --- a/src/vs/editor/test/common/services/editorSimpleWorker.test.ts +++ b/src/vs/editor/test/common/services/editorSimpleWorker.test.ts @@ -167,8 +167,9 @@ suite('EditorSimpleWorker', () => { assert.ok(false); return; } - assert.equal(result.length, 1); - assert.equal(result, 'foobar'); + assert.equal(result.words.length, 1); + assert.equal(typeof result.duration, 'number'); + assert.equal(result.words[0], 'foobar'); }); }); -- GitLab