1- import { SemanticTokens , SemanticTokensParams , TextDocuments , Range } from 'vscode-languageserver'
1+ import { SemanticTokens , SemanticTokensParams , TextDocuments , Range , Connection } from 'vscode-languageserver'
22import MatlabLifecycleManager from '../../lifecycle/MatlabLifecycleManager'
33import { TextDocument } from 'vscode-languageserver-textdocument'
44import FileInfoIndex , { MatlabFunctionScopeInfo , MatlabGlobalScopeInfo } from '../../indexing/FileInfoIndex'
@@ -9,6 +9,9 @@ interface SemanticToken {
99 typeIndex : number
1010}
1111
12+ /**
13+ * Handles requests for semantic tokens for a document.
14+ */
1215class SemanticTokensProvider {
1316 constructor (
1417 protected readonly matlabLifecycleManager : MatlabLifecycleManager ,
@@ -28,8 +31,6 @@ class SemanticTokensProvider {
2831 const textDocument = documentManager . get ( params . textDocument . uri )
2932 if ( textDocument == null ) return null
3033
31- await this . documentIndexer . ensureDocumentIndexIsUpdated ( textDocument )
32-
3334 const codeInfo = this . fileInfoIndex . codeInfoCache . get ( params . textDocument . uri )
3435 if ( codeInfo == null ) return null
3536
@@ -112,3 +113,24 @@ class SemanticTokensProvider {
112113export const SEMANTIC_TOKEN_TYPES = [ 'function' , 'variable' ]
113114export const SEMANTIC_TOKEN_MODIFIERS : string [ ] = [ ]
114115export default SemanticTokensProvider
116+
117+ /**
118+ * Wires semantic token invalidation to document indexing.
119+ *
120+ * When indexing completes, this schedules a debounced refresh request
121+ * so the client re-requests semantic tokens and updates highlighting.
122+ */
123+ export function setupSemanticTokensRefresh (
124+ connection : Connection ,
125+ documentIndexer : DocumentIndexer
126+ ) : void {
127+ let refreshTimer : NodeJS . Timeout | undefined
128+
129+ documentIndexer . setOnIndexed ( ( ) => {
130+ if ( refreshTimer != null ) clearTimeout ( refreshTimer )
131+
132+ refreshTimer = setTimeout ( ( ) => {
133+ void connection . sendRequest ( 'workspace/semanticTokens/refresh' )
134+ } , 150 )
135+ } )
136+ }
0 commit comments