diff options
author | kevinhwang91 <kevin.hwang@live.com> | 2022-02-01 18:15:47 +0800 |
---|---|---|
committer | kevinhwang91 <kevin.hwang@live.com> | 2022-02-01 18:57:45 +0800 |
commit | 5e63a4d05d18e7529abcbd6f52ae71078e81f9ef (patch) | |
tree | 6cc542934d283067793eb5650f0466c7dc378075 /script/core | |
parent | e9c319ac7c512b3563101c87d73d959931e1554a (diff) | |
download | lua-language-server-5e63a4d05d18e7529abcbd6f52ae71078e81f9ef.zip |
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.
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/semantic-tokens.lua | 44 |
1 files 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 |