Skip to content

Commit

Permalink
fix(repl): do not panic for import completions when the import specif…
Browse files Browse the repository at this point in the history
…ier is empty (#15177)
  • Loading branch information
dsherret authored Jul 13, 2022
1 parent 0c87dd1 commit 3a4e95c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cli/lsp/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,16 @@ fn to_narrow_lsp_range(
column_index: range.end.character,
})
.as_byte_index(text_info.range().start);
let start_byte_index = text_info
.loc_to_source_pos(LineAndColumnIndex {
line_index: range.start.line,
column_index: range.start.character,
})
.as_byte_index(text_info.range().start);
let text_bytes = text_info.text_str().as_bytes();
let is_empty = end_byte_index - 1 == start_byte_index;
let has_trailing_quote =
matches!(text_bytes[end_byte_index - 1], b'"' | b'\'');
!is_empty && matches!(text_bytes[end_byte_index - 1], b'"' | b'\'');
lsp::Range {
start: lsp::Position {
line: range.start.line as u32,
Expand Down
5 changes: 5 additions & 0 deletions cli/tests/integration/repl_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ fn pty_complete_imports() {
let output = console.read_all_output();
assert_contains!(output, "Hello World");
});

// does not panic when tabbing when empty
util::with_pty(&["repl"], |mut console| {
console.write_line("import '\t");
});
}

#[test]
Expand Down

0 comments on commit 3a4e95c

Please sign in to comment.