mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
know hover providers using command links, #29076
This commit is contained in:
@@ -18,10 +18,13 @@ import { ExtHostCommands, CommandsConverter } from 'vs/workbench/api/node/extHos
|
||||
import { ExtHostDiagnostics } from 'vs/workbench/api/node/extHostDiagnostics';
|
||||
import { IWorkspaceSymbolProvider } from 'vs/workbench/parts/search/common/search';
|
||||
import { asWinJsPromise } from 'vs/base/common/async';
|
||||
import { MainContext, MainThreadLanguageFeaturesShape, ExtHostLanguageFeaturesShape, ObjectIdentifier, IRawColorInfo, IRawColorFormatMap, IMainContext } from './extHost.protocol';
|
||||
import { MainContext, MainThreadTelemetryShape, MainThreadLanguageFeaturesShape, ExtHostLanguageFeaturesShape, ObjectIdentifier, IRawColorInfo, IRawColorFormatMap, IMainContext } from './extHost.protocol';
|
||||
import { regExpLeadsToEndlessLoop } from 'vs/base/common/strings';
|
||||
import { IPosition } from 'vs/editor/common/core/position';
|
||||
import { IRange } from 'vs/editor/common/core/range';
|
||||
import { containsCommandLink } from 'vs/base/common/htmlContent';
|
||||
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
|
||||
import { once } from 'vs/base/common/functional';
|
||||
|
||||
// --- adapter
|
||||
|
||||
@@ -173,12 +176,12 @@ class TypeDefinitionAdapter {
|
||||
|
||||
class HoverAdapter {
|
||||
|
||||
private _documents: ExtHostDocuments;
|
||||
private _provider: vscode.HoverProvider;
|
||||
|
||||
constructor(documents: ExtHostDocuments, provider: vscode.HoverProvider) {
|
||||
this._documents = documents;
|
||||
this._provider = provider;
|
||||
constructor(
|
||||
private readonly _documents: ExtHostDocuments,
|
||||
private readonly _provider: vscode.HoverProvider,
|
||||
private readonly _telemetryLog: (name: string, data: object) => void,
|
||||
) {
|
||||
//
|
||||
}
|
||||
|
||||
public provideHover(resource: URI, position: IPosition): TPromise<modes.Hover> {
|
||||
@@ -187,7 +190,7 @@ class HoverAdapter {
|
||||
let pos = TypeConverters.toPosition(position);
|
||||
|
||||
return asWinJsPromise(token => this._provider.provideHover(doc, pos, token)).then(value => {
|
||||
if (!value) {
|
||||
if (!value || isFalsyOrEmpty(value.contents)) {
|
||||
return undefined;
|
||||
}
|
||||
if (!value.range) {
|
||||
@@ -197,7 +200,14 @@ class HoverAdapter {
|
||||
value.range = new Range(pos, pos);
|
||||
}
|
||||
|
||||
return TypeConverters.fromHover(value);
|
||||
const result = TypeConverters.fromHover(value);
|
||||
|
||||
// we wanna know which extension uses command links
|
||||
// because that is a potential trick-attack on users
|
||||
if (result.contents.some(containsCommandLink)) {
|
||||
this._telemetryLog('usesCommandLink', { from: 'hover' });
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -744,6 +754,7 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
|
||||
private static _handlePool: number = 0;
|
||||
|
||||
private _proxy: MainThreadLanguageFeaturesShape;
|
||||
private _telemetry: MainThreadTelemetryShape;
|
||||
private _documents: ExtHostDocuments;
|
||||
private _commands: ExtHostCommands;
|
||||
private _heapService: ExtHostHeapService;
|
||||
@@ -759,6 +770,7 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
|
||||
diagnostics: ExtHostDiagnostics
|
||||
) {
|
||||
this._proxy = mainContext.get(MainContext.MainThreadLanguageFeatures);
|
||||
this._telemetry = mainContext.get(MainContext.MainThreadTelemetry);
|
||||
this._documents = documents;
|
||||
this._commands = commands;
|
||||
this._heapService = heapMonitor;
|
||||
@@ -860,9 +872,12 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
|
||||
|
||||
// --- extra info
|
||||
|
||||
registerHoverProvider(selector: vscode.DocumentSelector, provider: vscode.HoverProvider): vscode.Disposable {
|
||||
registerHoverProvider(selector: vscode.DocumentSelector, provider: vscode.HoverProvider, extensionId?: string): vscode.Disposable {
|
||||
const handle = this._nextHandle();
|
||||
this._adapter.set(handle, new HoverAdapter(this._documents, provider));
|
||||
this._adapter.set(handle, new HoverAdapter(this._documents, provider, once((name, data) => {
|
||||
data['extension'] = extensionId;
|
||||
this._telemetry.$publicLog(name, data);
|
||||
})));
|
||||
this._proxy.$registerHoverProvider(handle, selector);
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user