detect comment position context (#756)

This commit is contained in:
Techatrix 2022-11-16 23:34:36 +01:00 committed by GitHub
parent 662b560861
commit d75fd3a880
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 13 deletions

View File

@ -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_loc = offsets.lineLocUntilIndex(text, doc_index);
const line = offsets.locToSlice(text, line_loc); 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); var stack = try std.ArrayListUnmanaged(StackState).initCapacity(allocator, 8);
defer stack.deinit(allocator); defer stack.deinit(allocator);

View File

@ -103,19 +103,18 @@ test "position context - builtin" {
} }
test "position context - comment" { test "position context - comment" {
// TODO fix failing test! try testContext(
// try testContext( \\// i am<cursor> a test
// \\// i am<cursor> a test ,
// , .comment,
// .comment, null, // report "// i am a test"
// "// i am", );
// ); try testContext(
// try testContext( \\/// i am<cursor> a test
// \\/// i am<cursor> a test ,
// , .comment,
// .comment, null, // report /// i am a test
// "/// i am", );
// );
} }
test "position context - import/embedfile string literal" { test "position context - import/embedfile string literal" {