Skip to content

Commit c9f447f

Browse files
committed
fix: span of the call struct
built-in `Span` of the `simplicityhl::parse::Call` calculated as full call, with parameters and generics, so we use custom calculation of call using length of the representing string
1 parent c305d3d commit c9f447f

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

src/backend.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use ropey::Rope;
22
use serde_json::Value;
3+
34
use std::collections::HashMap;
5+
use std::num::NonZeroUsize;
46
use std::str::FromStr;
57
use std::sync::Arc;
68
use tokio::sync::RwLock;
@@ -19,6 +21,7 @@ use tower_lsp_server::lsp_types::{
1921
};
2022
use tower_lsp_server::{Client, LanguageServer};
2123

24+
use simplicityhl::error::Position;
2225
use simplicityhl::{
2326
ast,
2427
error::{RichError, WithFile},
@@ -304,7 +307,7 @@ impl Backend {
304307
let token_span = positions_to_span((token_position, token_position)).ok()?;
305308

306309
let call = find_related_call(&document.functions, token_span)?;
307-
let (start, end) = span_to_positions(call.span()).ok()?;
310+
let (start, end) = span_to_positions(&get_call_span(call)?).ok()?;
308311

309312
let description = match call.name() {
310313
parse::CallName::Jet(jet) => {
@@ -473,11 +476,26 @@ fn find_related_call(
473476
.pre_order_iter()
474477
.filter_map(|expr| {
475478
if let parse::ExprTree::Call(call) = expr {
476-
Some(call)
479+
Some((call, get_call_span(call)?))
477480
} else {
478481
None
479482
}
480483
})
481-
.filter(|c| span_contains(c.span(), &token_span))
484+
.filter(|(_, span)| span_contains(span, &token_span))
485+
.map(|pair| pair.0)
482486
.last()
483487
}
488+
489+
fn get_call_span(call: &simplicityhl::parse::Call) -> Option<simplicityhl::error::Span> {
490+
let length = call.name().to_string().len();
491+
492+
let end_column = usize::from(call.span().start.col) + length;
493+
494+
Some(simplicityhl::error::Span {
495+
start: call.span().start,
496+
end: Position {
497+
line: call.span().start.line,
498+
col: NonZeroUsize::try_from(end_column).ok()?,
499+
},
500+
})
501+
}

0 commit comments

Comments
 (0)