Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions crates/ty_server/src/document/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub(crate) trait ToLink {
impl ToLink for NavigationTarget {
fn to_location(&self, db: &dyn Db, encoding: PositionEncoding) -> Option<Location> {
FileRange::new(self.file(), self.focus_range())
.as_lsp_range(db, encoding)
.to_lsp_range(db, encoding)?
.to_location()
}

Expand All @@ -35,17 +35,17 @@ impl ToLink for NavigationTarget {
// Get target_range and URI together to ensure they're consistent (same cell for notebooks)
let target_location = self
.full_range()
.as_lsp_range(db, file, encoding)
.to_location()?;
.to_lsp_range(db, file, encoding)?
.into_location()?;
let target_range = target_location.range;

// For selection_range, we can use as_local_range since we know it's in the same document/cell
let selection_range = self
.focus_range()
.as_lsp_range(db, file, encoding)
.to_local_range();
.to_lsp_range(db, file, encoding)?
.local_range();

let src = src.map(|src| src.as_lsp_range(db, encoding).to_local_range());
let src = src.and_then(|src| Some(src.to_lsp_range(db, encoding)?.local_range()));

Some(lsp_types::LocationLink {
target_uri: target_location.uri,
Expand All @@ -58,7 +58,9 @@ impl ToLink for NavigationTarget {

impl ToLink for ReferenceTarget {
fn to_location(&self, db: &dyn Db, encoding: PositionEncoding) -> Option<Location> {
self.file_range().as_lsp_range(db, encoding).to_location()
self.file_range()
.to_lsp_range(db, encoding)?
.into_location()
}

fn to_link(
Expand All @@ -70,12 +72,12 @@ impl ToLink for ReferenceTarget {
// Get target_range and URI together to ensure they're consistent (same cell for notebooks)
let target_location = self
.range()
.as_lsp_range(db, self.file(), encoding)
.to_location()?;
.to_lsp_range(db, self.file(), encoding)?
.into_location()?;
let target_range = target_location.range;
let selection_range = target_range;

let src = src.map(|src| src.as_lsp_range(db, encoding).to_local_range());
let src = src.and_then(|src| Some(src.to_lsp_range(db, encoding)?.local_range()));

Some(lsp_types::LocationLink {
target_uri: target_location.uri,
Expand Down
Loading
Loading