provideDocumentSemanticTokensEdits

abstract var provideDocumentSemanticTokensEdits: (document: TextDocument, previousResultId: String, token: CancellationToken) -> ProviderResult<JsAny>?(source)

Instead of always returning all the tokens in a file, it is possible for a DocumentSemanticTokensProvider to implement this method (provideDocumentSemanticTokensEdits) and then return incremental updates to the previously provided semantic tokens.

How tokens change when the document changes

Suppose that provideDocumentSemanticTokens has previously returned the following semantic tokens:

    // 1st token,  2nd token,  3rd token
[ 2,5,3,0,3, 0,5,4,1,0, 3,2,7,2,0 ]

Also suppose that after some edits, the new semantic tokens in a file are:

    // 1st token,  2nd token,  3rd token
[ 3,5,3,0,3, 0,5,4,1,0, 3,2,7,2,0 ]

It is possible to express these new tokens in terms of an edit applied to the previous tokens:

    [  2,5,3,0,3,  0,5,4,1,0,  3,2,7,2,0 ] // old tokens
[ 3,5,3,0,3, 0,5,4,1,0, 3,2,7,2,0 ] // new tokens

edit: { start: 0, deleteCount: 1, data: [3] } // replace integer at offset 0 with 3

NOTE: If the provider cannot compute SemanticTokensEdits, it can "give up" and return all the tokens in the document again. NOTE: All edits in SemanticTokensEdits contain indices in the old integers array, so they all refer to the previous result state.

Online Documentation