Skip to content

Commit

Permalink
Fix to_lsp_location to handle relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Jul 30, 2024
1 parent 8fb4ba9 commit c2aaba5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tooling/lsp/src/requests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::path::PathBuf;
use std::{collections::HashMap, future::Future};

use crate::insert_all_files_for_workspace_into_file_manager;
Expand Down Expand Up @@ -324,7 +325,12 @@ where
let file_name = files.name(file_id).ok()?;

let path = file_name.to_string();
let uri = Url::from_file_path(path).ok()?;

// `path` might be a relative path so we canonicalize it to get an absolute path
let path_buf = PathBuf::from(path);
let path_buf = path_buf.canonicalize().unwrap_or(path_buf);

let uri = Url::from_file_path(path_buf.to_str()?).ok()?;

Some(Location { uri, range })
}
Expand Down

0 comments on commit c2aaba5

Please sign in to comment.