Skip to content

Commit

Permalink
fix(semantic-tokens): limit comments range
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kevinhwang91 committed Feb 1, 2022
1 parent e9c319a commit 5e63a4d
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions script/core/semantic-tokens.lua
Original file line number Diff line number Diff line change
Expand Up @@ -815,34 +815,36 @@ 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,
finish = comm.finish,
type = define.TokenTypes.comment,
}
end
else
results[#results+1] = {
start = comm.start,
finish = comm.finish,
type = define.TokenTypes.comment,
}
end
end

Expand Down

0 comments on commit 5e63a4d

Please sign in to comment.