Skip to content

Commit 19b6567

Browse files
committed
Implement syncCacheAndRenderHints on the VSCode side
1 parent 350789a commit 19b6567

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Editors/vscode/src/extension.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import * as vscode from 'vscode';
33
import * as langclient from 'vscode-languageclient/node';
44
import { activateInlayHints } from './inlayHints';
55

6-
export function activate(context: vscode.ExtensionContext) {
7-
6+
export async function activate(context: vscode.ExtensionContext): Promise<void> {
87
const config = vscode.workspace.getConfiguration('sourcekit-lsp');
98

109
const sourcekit: langclient.Executable = {
@@ -33,10 +32,12 @@ export function activate(context: vscode.ExtensionContext) {
3332

3433
const client = new langclient.LanguageClient('sourcekit-lsp', 'SourceKit Language Server', serverOptions, clientOptions);
3534

36-
activateInlayHints(context, client);
3735
context.subscriptions.push(client.start());
3836

3937
console.log('SourceKit-LSP is now active!');
38+
39+
await client.onReady();
40+
activateInlayHints(context, client);
4041
}
4142

4243
export function deactivate() {

Editors/vscode/src/inlayHints.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,19 @@ class HintsUpdater implements vscode.Disposable {
139139
}
140140

141141
private syncCacheAndRenderHints(): void {
142-
142+
this.sourceFiles.forEach(async (file, uri) => {
143+
const hints = await this.fetchHints(file);
144+
if (!hints) return;
145+
146+
const decorations = this.hintsToDecorations(hints);
147+
file.cachedDecorations = decorations;
148+
149+
this.visibleSourceKitLSPEditors.forEach(editor => {
150+
if (editor.document.uri.toString() === uri) {
151+
this.renderDecorations(editor, decorations);
152+
}
153+
});
154+
});
143155
}
144156

145157
private get visibleSourceKitLSPEditors(): vscode.TextEditor[] {
@@ -175,6 +187,7 @@ class HintsUpdater implements vscode.Disposable {
175187
try {
176188
return await this.client.sendRequest(inlayHintsRequest, params, tokenSource.token);
177189
} catch (e) {
190+
this.client.outputChannel.appendLine(`Could not fetch inlay hints: ${e}`);
178191
return [];
179192
} finally {
180193
if (file.inFlightInlayHints.token === tokenSource.token) {

0 commit comments

Comments
 (0)