diff options
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 { |