From 5e63a4d05d18e7529abcbd6f52ae71078e81f9ef Mon Sep 17 00:00:00 2001 From: kevinhwang91 Date: Tue, 1 Feb 2022 18:15:47 +0800 Subject: fix(semantic-tokens): limit comments range Client requests `textDocument/semanticTokens/range` service with a range parameter in order to get the tokens of the visible window, but server return the additional comments highlighting tokens may be out of range, we should keep the tokens requested by the client in range. --- script/core/semantic-tokens.lua | 44 +++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index afa1424b..6163cbbe 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -815,21 +815,29 @@ return function (uri, start, finish) end) for _, comm in ipairs(state.comms) do - if comm.type == 'comment.short' then - local head = comm.text:sub(1, 2) - if head == '-@' - or head == '-|' then - results[#results+1] = { - start = comm.start, - finish = comm.start + 3, - type = define.TokenTypes.comment, - } - results[#results+1] = { - start = comm.start + 3, - finish = comm.start + 2 + #comm.text:match '%S+', - type = define.TokenTypes.comment, - modifieres = define.TokenModifiers.documentation, - } + if start <= comm.start and comm.finish <= finish then + if comm.type == 'comment.short' then + local head = comm.text:sub(1, 2) + if head == '-@' + or head == '-|' then + results[#results+1] = { + start = comm.start, + finish = comm.start + 3, + type = define.TokenTypes.comment, + } + results[#results+1] = { + start = comm.start + 3, + finish = comm.start + 2 + #comm.text:match '%S+', + type = define.TokenTypes.comment, + modifieres = define.TokenModifiers.documentation, + } + else + results[#results+1] = { + start = comm.start, + finish = comm.finish, + type = define.TokenTypes.comment, + } + end else results[#results+1] = { start = comm.start, @@ -837,12 +845,6 @@ return function (uri, start, finish) type = define.TokenTypes.comment, } end - else - results[#results+1] = { - start = comm.start, - finish = comm.finish, - type = define.TokenTypes.comment, - } end end -- cgit v1.2.3