1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-26 17:19:06 -05:00

fix(repl): do not panic for import completions when the import specifier is empty (#15177)

This commit is contained in:
David Sherret 2022-07-12 21:56:48 -04:00 committed by GitHub
parent 0c87dd1e98
commit 3a4e95c431
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -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,

View file

@ -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]