Skip to content

Commit 5e63a4d

Browse files
committed
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.
1 parent e9c319a commit 5e63a4d

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

script/core/semantic-tokens.lua

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -815,34 +815,36 @@ return function (uri, start, finish)
815815
end)
816816

817817
for _, comm in ipairs(state.comms) do
818-
if comm.type == 'comment.short' then
819-
local head = comm.text:sub(1, 2)
820-
if head == '-@'
821-
or head == '-|' then
822-
results[#results+1] = {
823-
start = comm.start,
824-
finish = comm.start + 3,
825-
type = define.TokenTypes.comment,
826-
}
827-
results[#results+1] = {
828-
start = comm.start + 3,
829-
finish = comm.start + 2 + #comm.text:match '%S+',
830-
type = define.TokenTypes.comment,
831-
modifieres = define.TokenModifiers.documentation,
832-
}
818+
if start <= comm.start and comm.finish <= finish then
819+
if comm.type == 'comment.short' then
820+
local head = comm.text:sub(1, 2)
821+
if head == '-@'
822+
or head == '-|' then
823+
results[#results+1] = {
824+
start = comm.start,
825+
finish = comm.start + 3,
826+
type = define.TokenTypes.comment,
827+
}
828+
results[#results+1] = {
829+
start = comm.start + 3,
830+
finish = comm.start + 2 + #comm.text:match '%S+',
831+
type = define.TokenTypes.comment,
832+
modifieres = define.TokenModifiers.documentation,
833+
}
834+
else
835+
results[#results+1] = {
836+
start = comm.start,
837+
finish = comm.finish,
838+
type = define.TokenTypes.comment,
839+
}
840+
end
833841
else
834842
results[#results+1] = {
835843
start = comm.start,
836844
finish = comm.finish,
837845
type = define.TokenTypes.comment,
838846
}
839847
end
840-
else
841-
results[#results+1] = {
842-
start = comm.start,
843-
finish = comm.finish,
844-
type = define.TokenTypes.comment,
845-
}
846848
end
847849
end
848850

0 commit comments

Comments
 (0)