settings: Add tilde expansion support for LSP binary path (#41715)

Closes #38227

Release Notes:

- Added tilde expansion support for LSP binary path in `settings.json`
This commit is contained in:
Mayank Verma
2025-11-13 09:14:18 -05:00
committed by GitHub
parent f318bb5fd7
commit 92e64f9cf0
2 changed files with 73 additions and 3 deletions
+12 -3
View File
@@ -2386,16 +2386,25 @@ impl Snapshot {
/// Resolves a path to an executable using the following heuristics:
///
/// 1. If the path is relative and contains more than one component,
/// 1. If the path starts with `~`, it is expanded to the user's home directory.
/// 2. 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
/// 3. 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.
/// 4. 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 Some(path_str) = path.to_str() {
if let Some(remaining_path) = path_str.strip_prefix("~/") {
return home_dir().join(remaining_path);
} else if path_str == "~" {
return home_dir().to_path_buf();
}
}
if let Ok(rel_path) = RelPath::new(&path, self.path_style)
&& (path.components().count() > 1 || self.entry_for_path(&rel_path).is_some())
{