diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-07-12 21:56:48 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-12 21:56:48 -0400 |
commit | 3a4e95c43191c02e54d5b002066df41fb7b4c750 (patch) | |
tree | 691f53da0534d6bc970092d7cc623097016b82e8 /cli | |
parent | 0c87dd1e9898d7ac93e274d3611ee491a107d47a (diff) |
fix(repl): do not panic for import completions when the import specifier is empty (#15177)
Diffstat (limited to 'cli')
-rw-r--r-- | cli/lsp/completions.rs | 9 | ||||
-rw-r--r-- | cli/tests/integration/repl_tests.rs | 5 |
2 files changed, 13 insertions, 1 deletions
diff --git a/cli/lsp/completions.rs b/cli/lsp/completions.rs index e69df8079..dfa2c612d 100644 --- a/cli/lsp/completions.rs +++ b/cli/lsp/completions.rs @@ -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, diff --git a/cli/tests/integration/repl_tests.rs b/cli/tests/integration/repl_tests.rs index 9731aa0aa..e24978876 100644 --- a/cli/tests/integration/repl_tests.rs +++ b/cli/tests/integration/repl_tests.rs @@ -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] |