mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
fix(lsp): retain module dependencies when parse is invalid (#12782)
Fixes #12753
This commit is contained in:
parent
fd78953e1c
commit
cc38580106
5 changed files with 109 additions and 80 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue