Absolutize LSP and DAP paths more conservatively (#42482)

Fixes a regression caused by #42135 where LSP and DAP binaries weren't
being used from `PATH` env var

Now we absolutize the path if (path is relative AND (path has multiple
components OR path exists in worktree)).

- Relative paths with multiple components might not exist in the
worktree because they are ignored. Paths with a single component will at
least have an entry saying that they exist and are ignored.
- Relative paths with multiple components will never use the `PATH` env
var, so they can be safely absolutized

Release Notes:

- N/A
This commit is contained in:
Andrew Farkas
2025-11-12 01:36:22 +00:00
committed by GitHub
parent cf6ae01d07
commit 2bcfc12951
5 changed files with 52 additions and 10 deletions
+21
View File
@@ -2384,6 +2384,27 @@ impl Snapshot {
})
}
/// Resolves a path to an executable using the following heuristics:
///
/// 1. If the path is relative and contains more than one component,
/// it is joined to the worktree root path.
/// 2. If the path is relative and exists in the worktree
/// (even if falls under an exclusion filter),
/// it is joined to the worktree root path.
/// 3. Otherwise the path is returned unmodified.
///
/// Relative paths that do not exist in the worktree may
/// still be found using the `PATH` environment variable.
pub fn resolve_executable_path(&self, path: PathBuf) -> PathBuf {
if let Ok(rel_path) = RelPath::new(&path, self.path_style)
&& (path.components().count() > 1 || self.entry_for_path(&rel_path).is_some())
{
self.abs_path().join(path)
} else {
path
}
}
pub fn entry_for_id(&self, id: ProjectEntryId) -> Option<&Entry> {
let entry = self.entries_by_id.get(&id, ())?;
self.entry_for_path(&entry.path)