Hey, i'm doing a follow up after initial review of my semantic token highlighting implementation here : https://github.com/apple/sourcekit-lsp/pull/279.
I'm going to use now response captured in
handleDocumentUpdate to extract semantic tokens, but the issue is that
textDocument/semanticTokens request is, well, a request while
notification_documentupdate is a notification, this generates a lot of asynchronicity to handle, and can lead to desynchronization of what is used to generate semantic tokens and current document state. For now i'm using simple caching mechanism by storing semantic tokens whenever
handleDocumentUpdate is triggered, and then getting those results when
textDocument/semanticTokens is requested to populate full semantic tokens request response (i've noticed that
notification_documentupdate came before
textDocument/semanticTokens request [except for the first one] - is that always a rule?). It seems to work well for now, but I've got few questions, as this solution seems suboptimal and error prone:
notification_documentupdateguaranteed to trigger before
textDocument/semanticTokensrequest from client?
- Is there any better way to synchronize
textDocument/semanticTokensrequest? I was thinking about partial results, but I'm not sure if this is a case for that (https://microsoft.github.io/language-server-protocol/specification#partialResults)
- Any other ways to handle that? Ideally, there could be a way to capture all needed data (syntax & semantic tokens) with single ad-hoc, sourcekit query whenever