diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2021-11-17 09:23:25 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-17 09:23:25 +1100 |
commit | cc38580106095b1acf3c307dd6079076fec812e3 (patch) | |
tree | b9df178cbdbc23b94a8a42ee1fe942c0e763bea8 /cli/lsp/tsc.rs | |
parent | fd78953e1c241c8dd14686631a2509aec97f1167 (diff) |
fix(lsp): retain module dependencies when parse is invalid (#12782)
Fixes #12753
Diffstat (limited to 'cli/lsp/tsc.rs')
-rw-r--r-- | cli/lsp/tsc.rs | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index b5ce48fab..4a61d7403 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -38,6 +38,8 @@ use deno_core::OpFn; use deno_core::RuntimeOptions; use deno_runtime::tokio_util::create_basic_runtime; use log::warn; +use lspower::jsonrpc::Error as LspError; +use lspower::jsonrpc::Result as LspResult; use lspower::lsp; use regex::Captures; use regex::Regex; @@ -1122,7 +1124,7 @@ impl Classifications { pub fn to_semantic_tokens( &self, line_index: Arc<LineIndex>, - ) -> lsp::SemanticTokens { + ) -> LspResult<lsp::SemanticTokens> { let token_count = self.spans.len() / 3; let mut builder = SemanticTokensBuilder::new(); for i in 0..token_count { @@ -1141,16 +1143,26 @@ impl Classifications { let start_pos = line_index.position_tsc(offset.into()); let end_pos = line_index.position_tsc(TextSize::from(offset + length)); - // start_pos.line == end_pos.line is always true as there are no multiline tokens - builder.push( - start_pos.line, - start_pos.character, - end_pos.character - start_pos.character, - token_type, - token_modifiers, - ); + if start_pos.line == end_pos.line + && start_pos.character <= end_pos.character + { + builder.push( + start_pos.line, + start_pos.character, + end_pos.character - start_pos.character, + token_type, + token_modifiers, + ); + } else { + log::error!( + "unexpected positions\nstart_pos: {:?}\nend_pos: {:?}", + start_pos, + end_pos + ); + return Err(LspError::internal_error()); + } } - builder.build(None) + Ok(builder.build(None)) } fn get_token_type_from_classification(ts_classification: u32) -> u32 { |