Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/semanticTokenProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export function registerSemanticTokensProvider(context: vscode.ExtensionContext)

class SemanticTokensProvider implements vscode.DocumentSemanticTokensProvider {
async provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.SemanticTokens> {
const versionBeforeRequest: number = document.version;
const response = <any> await vscode.commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.PROVIDE_SEMANTIC_TOKENS, document.uri.toString());
const versionAfterRequest: number = document.version;

if (versionBeforeRequest !== versionAfterRequest) {
await waitForDocumentChangesToEnd(document);
throw new Error("busy");
}
if (token.isCancellationRequested) {
return undefined;
}
Expand All @@ -37,6 +44,19 @@ class SemanticTokensProvider implements vscode.DocumentSemanticTokensProvider {
}
}

function waitForDocumentChangesToEnd(document: vscode.TextDocument): Promise<void> {
let version = document.version;
return new Promise((resolve) => {
const iv = setInterval(() => {
if (document.version === version) {
clearInterval(iv);
resolve();
}
version = document.version;
}, 400);
});
}

const semanticTokensProvider = new SemanticTokensProvider();

async function getSemanticTokensLegend(): Promise<vscode.SemanticTokensLegend | undefined> {
Expand Down