提交 3b4cea2a 编写于 作者: J Johannes Rieken

add telemetry to know how often multiple formatter situation occur, #41882

上级 409293d5
...@@ -27,6 +27,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati ...@@ -27,6 +27,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { CancellationToken } from 'vs/base/common/cancellation'; import { CancellationToken } from 'vs/base/common/cancellation';
import { sequence } from 'vs/base/common/async'; import { sequence } from 'vs/base/common/async';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
function alertFormattingEdits(edits: ISingleEditOperation[]): void { function alertFormattingEdits(edits: ISingleEditOperation[]): void {
...@@ -60,13 +61,31 @@ export const enum FormatRangeType { ...@@ -60,13 +61,31 @@ export const enum FormatRangeType {
Selection, Selection,
} }
export function formatDocumentRange(workerService: IEditorWorkerService, editor: IActiveCodeEditor, rangeOrRangeType: Range | FormatRangeType, options: FormattingOptions, token: CancellationToken): Promise<void> { export function formatDocumentRange(telemetryService: ITelemetryService, workerService: IEditorWorkerService, editor: IActiveCodeEditor, rangeOrRangeType: Range | FormatRangeType, options: FormattingOptions, token: CancellationToken): Promise<void> {
const provider = DocumentRangeFormattingEditProviderRegistry.ordered(editor.getModel()).slice(0, 1); const provider = DocumentRangeFormattingEditProviderRegistry.ordered(editor.getModel());
if (provider.length === 0) { if (provider.length === 0) {
return Promise.reject(new NoProviderError()); return Promise.reject(new NoProviderError());
} }
// Know how often multiple providers clash and (for now)
// continue picking the 'first' provider
if (provider.length !== 1) {
/* __GDPR__
"manyformatters" : {
"type" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
"language" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
"count" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
}
*/
telemetryService.publicLog('manyformatters', {
type: 'range',
language: editor.getModel().getLanguageIdentifier().language,
count: provider.length,
});
provider.length = 1;
}
let allEdits: ISingleEditOperation[] = []; let allEdits: ISingleEditOperation[] = [];
editor.pushUndoStop(); editor.pushUndoStop();
...@@ -112,10 +131,28 @@ export function formatDocumentRange(workerService: IEditorWorkerService, editor: ...@@ -112,10 +131,28 @@ export function formatDocumentRange(workerService: IEditorWorkerService, editor:
}); });
} }
export function formatDocument(workerService: IEditorWorkerService, editor: IActiveCodeEditor, options: FormattingOptions, token: CancellationToken): Promise<void> { export function formatDocument(telemetryService: ITelemetryService, workerService: IEditorWorkerService, editor: IActiveCodeEditor, options: FormattingOptions, token: CancellationToken): Promise<void> {
const provider = DocumentFormattingEditProviderRegistry.ordered(editor.getModel()).slice(0); const provider = DocumentFormattingEditProviderRegistry.ordered(editor.getModel());
if (provider.length === 0) { if (provider.length === 0) {
return formatDocumentRange(workerService, editor, FormatRangeType.Full, options, token); return formatDocumentRange(telemetryService, workerService, editor, FormatRangeType.Full, options, token);
}
// Know how often multiple providers clash and (for now)
// continue picking the 'first' provider
if (provider.length !== 1) {
/* __GDPR__
"manyformatters" : {
"type" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
"language" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
"count" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
}
*/
telemetryService.publicLog('manyformatters', {
type: 'document',
language: editor.getModel().getLanguageIdentifier().language,
count: provider.length,
});
provider.length = 1;
} }
let allEdits: ISingleEditOperation[] = []; let allEdits: ISingleEditOperation[] = [];
...@@ -281,14 +318,14 @@ class FormatOnPaste implements editorCommon.IEditorContribution { ...@@ -281,14 +318,14 @@ class FormatOnPaste implements editorCommon.IEditorContribution {
private static readonly ID = 'editor.contrib.formatOnPaste'; private static readonly ID = 'editor.contrib.formatOnPaste';
private editor: ICodeEditor;
private workerService: IEditorWorkerService;
private callOnDispose: IDisposable[]; private callOnDispose: IDisposable[];
private callOnModel: IDisposable[]; private callOnModel: IDisposable[];
constructor(editor: ICodeEditor, @IEditorWorkerService workerService: IEditorWorkerService) { constructor(
this.editor = editor; private readonly editor: ICodeEditor,
this.workerService = workerService; @IEditorWorkerService private readonly workerService: IEditorWorkerService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
) {
this.callOnDispose = []; this.callOnDispose = [];
this.callOnModel = []; this.callOnModel = [];
...@@ -336,7 +373,7 @@ class FormatOnPaste implements editorCommon.IEditorContribution { ...@@ -336,7 +373,7 @@ class FormatOnPaste implements editorCommon.IEditorContribution {
const model = this.editor.getModel(); const model = this.editor.getModel();
const { tabSize, insertSpaces } = model.getOptions(); const { tabSize, insertSpaces } = model.getOptions();
formatDocumentRange(this.workerService, this.editor, range, { tabSize, insertSpaces }, CancellationToken.None); formatDocumentRange(this.telemetryService, this.workerService, this.editor, range, { tabSize, insertSpaces }, CancellationToken.None);
} }
public getId(): string { public getId(): string {
...@@ -378,8 +415,9 @@ export class FormatDocumentAction extends EditorAction { ...@@ -378,8 +415,9 @@ export class FormatDocumentAction extends EditorAction {
} }
const notificationService = accessor.get(INotificationService); const notificationService = accessor.get(INotificationService);
const workerService = accessor.get(IEditorWorkerService); const workerService = accessor.get(IEditorWorkerService);
const telemetryService = accessor.get(ITelemetryService);
const { tabSize, insertSpaces } = editor.getModel().getOptions(); const { tabSize, insertSpaces } = editor.getModel().getOptions();
return formatDocument(workerService, editor, { tabSize, insertSpaces }, CancellationToken.None).catch(err => { return formatDocument(telemetryService, workerService, editor, { tabSize, insertSpaces }, CancellationToken.None).catch(err => {
if (NoProviderError.is(err)) { if (NoProviderError.is(err)) {
notificationService.info(nls.localize('no.documentprovider', "There is no document formatter for '{0}'-files installed.", editor.getModel().getLanguageIdentifier().language)); notificationService.info(nls.localize('no.documentprovider', "There is no document formatter for '{0}'-files installed.", editor.getModel().getLanguageIdentifier().language));
} }
...@@ -414,8 +452,9 @@ export class FormatSelectionAction extends EditorAction { ...@@ -414,8 +452,9 @@ export class FormatSelectionAction extends EditorAction {
} }
const notificationService = accessor.get(INotificationService); const notificationService = accessor.get(INotificationService);
const workerService = accessor.get(IEditorWorkerService); const workerService = accessor.get(IEditorWorkerService);
const telemetryService = accessor.get(ITelemetryService);
const { tabSize, insertSpaces } = editor.getModel().getOptions(); const { tabSize, insertSpaces } = editor.getModel().getOptions();
return formatDocumentRange(workerService, editor, FormatRangeType.Selection, { tabSize, insertSpaces }, CancellationToken.None).catch(err => { return formatDocumentRange(telemetryService, workerService, editor, FormatRangeType.Selection, { tabSize, insertSpaces }, CancellationToken.None).catch(err => {
if (NoProviderError.is(err)) { if (NoProviderError.is(err)) {
notificationService.info(nls.localize('no.selectionprovider', "There is no selection formatter for '{0}'-files installed.", editor.getModel().getLanguageIdentifier().language)); notificationService.info(nls.localize('no.selectionprovider', "There is no selection formatter for '{0}'-files installed.", editor.getModel().getLanguageIdentifier().language));
} }
...@@ -437,10 +476,11 @@ CommandsRegistry.registerCommand('editor.action.format', accessor => { ...@@ -437,10 +476,11 @@ CommandsRegistry.registerCommand('editor.action.format', accessor => {
} }
const { tabSize, insertSpaces } = editor.getModel().getOptions(); const { tabSize, insertSpaces } = editor.getModel().getOptions();
const workerService = accessor.get(IEditorWorkerService); const workerService = accessor.get(IEditorWorkerService);
const telemetryService = accessor.get(ITelemetryService);
if (editor.getSelection().isEmpty()) { if (editor.getSelection().isEmpty()) {
return formatDocument(workerService, editor, { tabSize, insertSpaces }, CancellationToken.None); return formatDocument(telemetryService, workerService, editor, { tabSize, insertSpaces }, CancellationToken.None);
} else { } else {
return formatDocumentRange(workerService, editor, FormatRangeType.Selection, { tabSize, insertSpaces }, CancellationToken.None); return formatDocumentRange(telemetryService, workerService, editor, FormatRangeType.Selection, { tabSize, insertSpaces }, CancellationToken.None);
} }
}); });
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册