semantic_tokens: Fix handleComments not evaluating the last byte (#844)

Fixes #842
This commit is contained in:
Ryan Liptak 2022-12-22 19:27:38 -08:00 committed by GitHub
parent 4d7b95e1e2
commit f6c15ac10c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View File

@ -141,16 +141,16 @@ const Builder = struct {
const source = self.handle.tree.source; const source = self.handle.tree.source;
var i: usize = from; var i: usize = from;
while (i < to - 1) : (i += 1) { while (i < to) : (i += 1) {
// Skip multi-line string literals // Skip multi-line string literals
if (source[i] == '\\' and source[i + 1] == '\\') { if (source[i] == '\\' and source[i + 1] == '\\') {
while (i < to - 1 and source[i] != '\n') : (i += 1) {} while (i < to and source[i] != '\n') : (i += 1) {}
continue; continue;
} }
// Skip normal string literals // Skip normal string literals
if (source[i] == '"') { if (source[i] == '"') {
i += 1; i += 1;
while (i < to - 1 and while (i < to and
source[i] != '\n' and source[i] != '\n' and
!(source[i] == '"' and source[i - 1] != '\\')) : (i += 1) !(source[i] == '"' and source[i - 1] != '\\')) : (i += 1)
{} {}
@ -159,7 +159,7 @@ const Builder = struct {
// Skip char literals // Skip char literals
if (source[i] == '\'') { if (source[i] == '\'') {
i += 1; i += 1;
while (i < to - 1 and while (i < to and
source[i] != '\n' and source[i] != '\n' and
!(source[i] == '\'' and source[i - 1] != '\\')) : (i += 1) !(source[i] == '\'' and source[i - 1] != '\\')) : (i += 1)
{} {}
@ -174,7 +174,7 @@ const Builder = struct {
if (i + 2 < to and (source[i + 2] == '!' or source[i + 2] == '/')) if (i + 2 < to and (source[i + 2] == '!' or source[i + 2] == '/'))
mods.documentation = true; mods.documentation = true;
while (i < to - 1 and source[i] != '\n') : (i += 1) {} while (i < to and source[i] != '\n') : (i += 1) {}
const length = offsets.locLength(self.handle.tree.source, .{ .start = comment_start, .end = i }, self.encoding); const length = offsets.locLength(self.handle.tree.source, .{ .start = comment_start, .end = i }, self.encoding);
try self.addDirect(TokenType.comment, mods, comment_start, length); try self.addDirect(TokenType.comment, mods, comment_start, length);

View File

@ -22,6 +22,16 @@ test "semantic tokens" {
// TODO more tests // TODO more tests
} }
test "semantic tokens - comments" {
try testSemanticTokens(
\\//!─
,
&.{ 0, 0, 4, 8, 128 },
);
// TODO more tests
}
const file_uri = switch (builtin.os.tag) { const file_uri = switch (builtin.os.tag) {
.windows => "file:///C:/test.zig", .windows => "file:///C:/test.zig",
else => "file:///test.zig", else => "file:///test.zig",