mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-01 22:12:26 +01:00
Simplify _onDidChangeInlayHints firing
This commit is contained in:
@@ -10,7 +10,6 @@ import API from '../utils/api';
|
||||
import { Condition, conditionalRegistration, requireMinVersion, requireSomeCapability } from '../utils/dependentRegistration';
|
||||
import { Disposable } from '../utils/dispose';
|
||||
import { DocumentSelector } from '../utils/documentSelector';
|
||||
import { isSupportedLanguageMode } from '../utils/languageModeIds';
|
||||
import { Position } from '../utils/typeConverters';
|
||||
import FileConfigurationManager, { getInlayHintsPreferences, InlayHintSettingNames } from './fileConfigurationManager';
|
||||
|
||||
@@ -33,6 +32,7 @@ class TypeScriptInlayHintsProvider extends Disposable implements vscode.InlayHin
|
||||
|
||||
constructor(
|
||||
modeId: string,
|
||||
languageIds: readonly string[],
|
||||
private readonly client: ITypeScriptServiceClient,
|
||||
private readonly fileConfigurationManager: FileConfigurationManager
|
||||
) {
|
||||
@@ -43,6 +43,14 @@ class TypeScriptInlayHintsProvider extends Disposable implements vscode.InlayHin
|
||||
this._onDidChangeInlayHints.fire();
|
||||
}
|
||||
}));
|
||||
|
||||
// When a JS/TS file changes, change inlay hints for all visible editors
|
||||
// since changes in one file can effect the hints the others.
|
||||
this._register(vscode.workspace.onDidChangeTextDocument(e => {
|
||||
if (languageIds.includes(e.document.languageId)) {
|
||||
this._onDidChangeInlayHints.fire();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
async provideInlayHints(model: vscode.TextDocument, range: vscode.Range, token: vscode.CancellationToken): Promise<vscode.InlayHint[]> {
|
||||
@@ -51,18 +59,6 @@ class TypeScriptInlayHintsProvider extends Disposable implements vscode.InlayHin
|
||||
return [];
|
||||
}
|
||||
|
||||
// If triggered for the active editor, then also trigger for all other visible editors since
|
||||
// changes in the active editor may effect their hints too.
|
||||
const modelUri = model.uri.toString();
|
||||
if (modelUri === vscode.window.activeTextEditor?.document.uri.toString()) {
|
||||
for (const visibleEditor of vscode.window.visibleTextEditors) {
|
||||
if (isSupportedLanguageMode(visibleEditor.document) && visibleEditor.document.uri.toString() !== modelUri) {
|
||||
this._onDidChangeInlayHints.fire();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const start = model.offsetAt(range.start);
|
||||
const length = model.offsetAt(range.end) - start;
|
||||
|
||||
@@ -119,6 +115,7 @@ export function requireInlayHintsConfiguration(
|
||||
export function register(
|
||||
selector: DocumentSelector,
|
||||
modeId: string,
|
||||
languageIds: readonly string[],
|
||||
client: ITypeScriptServiceClient,
|
||||
fileConfigurationManager: FileConfigurationManager
|
||||
) {
|
||||
@@ -127,7 +124,7 @@ export function register(
|
||||
requireMinVersion(client, TypeScriptInlayHintsProvider.minVersion),
|
||||
requireSomeCapability(client, ClientCapability.Semantic),
|
||||
], () => {
|
||||
const provider = new TypeScriptInlayHintsProvider(modeId, client, fileConfigurationManager);
|
||||
const provider = new TypeScriptInlayHintsProvider(modeId, languageIds, client, fileConfigurationManager);
|
||||
return vscode.languages.registerInlayHintsProvider(selector.semantic, provider);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user