Skip to content

Commit

Permalink
Snippet instrumentation (microsoft#146874)
Browse files Browse the repository at this point in the history
  • Loading branch information
digitarald authored Apr 11, 2022
1 parent 497a035 commit b84feec
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/vs/editor/common/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,10 @@ export interface CompletionItem {
* A command that should be run upon acceptance of this item.
*/
command?: Command;
/**
* @internal
*/
extensionId?: ExtensionIdentifier;

/**
* @internal
Expand Down
6 changes: 6 additions & 0 deletions src/vs/editor/contrib/suggest/browser/suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { LanguageFeatureRegistry } from 'vs/editor/common/languageFeatureRegistr
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
import { historyNavigationVisible } from 'vs/platform/history/browser/contextScopedHistoryWidget';
import { InternalQuickSuggestionsOptions, QuickSuggestionsValue } from 'vs/editor/common/config/editorOptions';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';

export const Context = {
Visible: historyNavigationVisible,
Expand Down Expand Up @@ -66,6 +67,9 @@ export class CompletionItem {
idx?: number;
word?: string;

// instrumentation
readonly extensionId?: ExtensionIdentifier;

// resolving
private _isResolved?: boolean;
private _resolveCache?: Promise<void>;
Expand All @@ -89,6 +93,8 @@ export class CompletionItem {
this.sortTextLow = completion.sortText && completion.sortText.toLowerCase();
this.filterTextLow = completion.filterText && completion.filterText.toLowerCase();

this.extensionId = completion.extensionId;

// normalize ranges
if (Range.isIRange(completion.range)) {
this.editStart = new Position(completion.range.startLineNumber, completion.range.startColumn);
Expand Down
10 changes: 6 additions & 4 deletions src/vs/editor/contrib/suggest/browser/suggestController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,31 +434,33 @@ export class SuggestController implements IEditorContribution {

// clear only now - after all tasks are done
Promise.all(tasks).finally(() => {
this._reportSuggestionAcceptedTelemetry(model, event);
this._reportSuggestionAcceptedTelemetry(item, model, event);

this.model.clear();
cts.dispose();
});
}

private _telemetryGate: number = 0;
private _reportSuggestionAcceptedTelemetry(model: ITextModel, acceptedSuggestion: ISelectedSuggestion) {
private _reportSuggestionAcceptedTelemetry(item: CompletionItem, model: ITextModel, acceptedSuggestion: ISelectedSuggestion) {
if (this._telemetryGate++ % 100 !== 0) {
return;
}

type AcceptedSuggestion = { providerId: string; fileExtension: string; languageId: string; basenameHash: string };
type AcceptedSuggestion = { providerId: string; fileExtension: string; languageId: string; basenameHash: string; kind: number };
type AcceptedSuggestionClassification = {
providerId: { classification: 'PublicNonPersonalData'; purpose: 'FeatureInsight' };
basenameHash: { classification: 'PublicNonPersonalData'; purpose: 'FeatureInsight' };
fileExtension: { classification: 'SystemMetaData'; purpose: 'FeatureInsight' };
languageId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight' };
kind: { classification: 'SystemMetaData'; purpose: 'FeatureInsight' };
};
// _debugDisplayName looks like `vscode.css-language-features(/-:)`, where the last bit is the trigger chars
// normalize it to just the extension ID and lowercase
const providerId = (acceptedSuggestion.item.provider._debugDisplayName ?? 'unknown').split('(', 1)[0].toLowerCase();
const providerId = item.extensionId ? item.extensionId.value : (acceptedSuggestion.item.provider._debugDisplayName ?? 'unknown').split('(', 1)[0].toLowerCase();
this._telemetryService.publicLog2<AcceptedSuggestion, AcceptedSuggestionClassification>('suggest.acceptedSuggestion', {
providerId,
kind: item.completion.kind,
basenameHash: hash(basename(model.uri)).toString(16),
languageId: model.getLanguageId(),
fileExtension: extname(model.uri),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { isPatternInWord } from 'vs/base/common/filters';
import { StopWatch } from 'vs/base/common/stopwatch';
import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry';
import { getWordAtText } from 'vs/editor/common/core/wordHelper';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';

export class SnippetCompletion implements CompletionItem {

Expand All @@ -29,6 +30,7 @@ export class SnippetCompletion implements CompletionItem {
sortText: string;
kind: CompletionItemKind;
insertTextRules: CompletionItemInsertTextRule;
extensionId?: ExtensionIdentifier;

constructor(
readonly snippet: Snippet,
Expand All @@ -37,6 +39,7 @@ export class SnippetCompletion implements CompletionItem {
this.label = { label: snippet.prefix, description: snippet.name };
this.detail = localize('detail.snippet', "{0} ({1})", snippet.description || snippet.name, snippet.source);
this.insertText = snippet.codeSnippet;
this.extensionId = snippet.extensionId;
this.range = range;
this.sortText = `${snippet.snippetSource === SnippetSource.Extension ? 'z' : 'a'}-${snippet.prefix}`;
this.kind = CompletionItemKind.Snippet;
Expand Down
8 changes: 5 additions & 3 deletions src/vs/workbench/contrib/snippets/browser/snippetsFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { KnownSnippetVariableNames } from 'vs/editor/contrib/snippet/browser/sni
import { isFalsyOrWhitespace } from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
import { IFileService } from 'vs/platform/files/common/files';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { IdleValue } from 'vs/base/common/async';
import { IExtensionResourceLoaderService } from 'vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader';
import { relativePath } from 'vs/base/common/resources';
Expand Down Expand Up @@ -114,7 +114,8 @@ export class Snippet {
readonly body: string,
readonly source: string,
readonly snippetSource: SnippetSource,
readonly snippetIdentifier?: string
readonly snippetIdentifier?: string,
readonly extensionId?: ExtensionIdentifier,
) {
this.prefixLow = prefix.toLowerCase();
this._bodyInsights = new IdleValue(() => new SnippetBodyInsights(this.body));
Expand Down Expand Up @@ -332,7 +333,8 @@ export class SnippetFile {
body,
source,
this.source,
this._extension && `${relativePath(this._extension.extensionLocation, this.location)}/${name}`
this._extension && `${relativePath(this._extension.extensionLocation, this.location)}/${name}`,
this._extension?.identifier,
));
}
}
Expand Down

0 comments on commit b84feec

Please sign in to comment.