Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4806,8 +4806,10 @@ pub const PositionContext = union(enum) {
if (std.mem.endsWith(u8, string_literal_slice[1..], "\"")) {
location.end -= 1;
}
location.end = std.mem.findAnyPos(u8, source, location.start, &.{ '\n', '"' }) orelse source.len;
} else if (std.mem.startsWith(u8, string_literal_slice, "\\")) {
location.start += 2;
location.end = std.mem.findScalarPos(u8, source, location.start, '\n') orelse source.len;
}
return location;
}
Expand Down
9 changes: 4 additions & 5 deletions src/features/completions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ fn prepareCompletionLoc(tree: *const Ast, source_index: usize) offsets.Loc {
if (std.mem.startsWith(u8, tree.source[token_start..], "@\"")) {
break :start .{ token_start, token_start + 2 };
} else if (std.mem.startsWith(u8, tree.source[token_start..], "@") or std.mem.startsWith(u8, tree.source[token_start..], ".")) {
break :start .{ token_start + 1, token_start + 1 };
const start = @min(token_start + 1, source_index);
break :start .{ start, start };
Comment on lines +511 to +512
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const start = @min(token_start + 1, source_index);
break :start .{ start, start };
break :start .{ token_start + 1, token_start + 1 };

} else {
break :start .{ token_start, token_start };
}
Expand Down Expand Up @@ -810,10 +811,7 @@ fn completeFileSystemStringLiteral(builder: *Builder, pos_context: Analyser.Posi

if (pos_context == .string_literal and !DocumentStore.isBuildFile(builder.orig_handle.uri)) return;

var string_content_loc = pos_context.stringLiteralContentLoc(source);

// the position context is without lookahead so we have to do it ourself
string_content_loc.end = std.mem.findAnyPos(u8, source, string_content_loc.end, &.{ 0, '\n', '\r', '"' }) orelse source.len;
const string_content_loc = pos_context.stringLiteralContentLoc(source);

if (builder.source_index < string_content_loc.start or string_content_loc.end < builder.source_index) return;

Expand Down Expand Up @@ -1312,6 +1310,7 @@ fn getSwitchOrStructInitContext(
// The opening brace is preceded by a r_paren => evaluate
.r_paren => {
need_ret_type = true;
if (upper_index < 1) return null;
var token_index = upper_index - 1; // if `switch` we need the last token of the condition
parens_depth = even;
// Walk backwards counting parens until one_opening then check the preceding token's tag
Expand Down
28 changes: 28 additions & 0 deletions tests/lsp_features/completion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3485,6 +3485,9 @@ test "enum completion on out of bound token index" {
try testCompletion(
\\ = 1.<cursor>
, &.{});
try testCompletion(
\\) { .<cursor>
, &.{});
}

test "combine doc comments of declaration and definition" {
Expand Down Expand Up @@ -3571,6 +3574,13 @@ test "filesystem string literal ends with non ASCII symbol" {
});
}

test "filesystem unterminated string literal with newline" {
try testCompletion(
\\const foo = @import("
\\ <cursor>
, &.{});
}

test "label details disabled" {
try testCompletionWithOptions(
\\const S = struct {
Expand Down Expand Up @@ -3832,6 +3842,24 @@ test "insert replace behaviour - builtin with partial argument placeholders" {
});
}

test "insert replace behaviour - prepend on builtin or enum literal" {
try testCompletionTextEdit(.{
.source = "const foo = <cursor>@",
.label = "comptime_int",
.expected_insert_line = "const foo = comptime_int@",
.expected_replace_line = "const foo = comptime_int@",
});
try testCompletionTextEdit(.{
.source =
\\const E = enum{ A, B };
\\const foo: E = <cursor>.
,
.label = "comptime_int",
.expected_insert_line = "const foo: E = comptime_int.",
.expected_replace_line = "const foo: E = comptime_int.",
});
}

test "insert replace behaviour - function" {
try testCompletionTextEdit(.{
.source =
Expand Down