Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/features/completions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ fn prepareCompletionLoc(tree: *const Ast, source_index: usize) offsets.Loc {
std.debug.assert(token_loc.start <= source_index and source_index <= token_loc.end);
return offsets.identifierIndexToLoc(tree.source, token_loc.start, if (tag == .builtin) .name else .full);
},
.colon => return fallback_loc,
else => {
const token_start = tree.tokenStart(token);

Expand All @@ -498,6 +497,8 @@ fn prepareCompletionLoc(tree: *const Ast, source_index: usize) offsets.Loc {
if (token_start + 1 < source_index) return fallback_loc;
break :start .{ token_start + 1, token_start + 1 };
} else {
if (!offsets.isSymbolChar(tree.source[token_start]))
return fallback_loc;
break :start .{ token_start, token_start };
}
};
Expand Down
30 changes: 30 additions & 0 deletions tests/lsp_features/completion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4348,6 +4348,36 @@ test "doctest name" {
});
}

test "completions don't replace punctuation" {
try testCompletionTextEdit(.{
.source =
\\const foo = 0;
\\const bar = foo[<cursor>];
,
.label = "foo",
.expected_insert_line = "const bar = foo[foo];",
.expected_replace_line = "const bar = foo[foo];",
});
try testCompletionTextEdit(.{
.source =
\\const foo = 0;
\\const bar = foo(<cursor>);
,
.label = "foo",
.expected_insert_line = "const bar = foo(foo);",
.expected_replace_line = "const bar = foo(foo);",
});
try testCompletionTextEdit(.{
.source =
\\const foo = 0;
\\const bar = foo{<cursor>};
,
.label = "foo",
.expected_insert_line = "const bar = foo{foo};",
.expected_replace_line = "const bar = foo{foo};",
});
}

fn testCompletion(source: []const u8, expected_completions: []const Completion) !void {
try testCompletionWithOptions(source, expected_completions, .{});
}
Expand Down