From d75fd3a880c5b605c86e32106f38e9840fa866c6 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Wed, 16 Nov 2022 23:34:36 +0100 Subject: [PATCH] detect comment position context (#756) --- src/analysis.zig | 3 +++ tests/utility/position_context.zig | 25 ++++++++++++------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index 7da2747..9f25a06 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -1469,6 +1469,9 @@ pub fn getPositionContext(allocator: std.mem.Allocator, text: []const u8, doc_in const line_loc = offsets.lineLocUntilIndex(text, doc_index); const line = offsets.locToSlice(text, line_loc); + const is_comment = std.mem.startsWith(u8, std.mem.trimLeft(u8, line, " \t"), "//"); + if (is_comment) return .comment; + var stack = try std.ArrayListUnmanaged(StackState).initCapacity(allocator, 8); defer stack.deinit(allocator); diff --git a/tests/utility/position_context.zig b/tests/utility/position_context.zig index 68c2947..2735061 100644 --- a/tests/utility/position_context.zig +++ b/tests/utility/position_context.zig @@ -103,19 +103,18 @@ test "position context - builtin" { } test "position context - comment" { - // TODO fix failing test! - // try testContext( - // \\// i am a test - // , - // .comment, - // "// i am", - // ); - // try testContext( - // \\/// i am a test - // , - // .comment, - // "/// i am", - // ); + try testContext( + \\// i am a test + , + .comment, + null, // report "// i am a test" + ); + try testContext( + \\/// i am a test + , + .comment, + null, // report /// i am a test + ); } test "position context - import/embedfile string literal" {