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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to the Path Server will be documented in this file.

## Unrelease
Path Server is now published to Open VSX! You can now view it at https://open-vsx.org/extension/LKL/path-server
### Fixed
- **Core**: Fixed an error when generating completions in a directory without read permission.
- **Core**: Fixed tildes are not directly expanded on Windows platform.
- **Core**: Fixed `config.base_path` can only extend first placeholder.

## [1.4.1] - 2026-07-25
### Improved
- Reduced resource consumption by limiting the number of blocking threads in the tokio runtime to 4 in default.
Expand Down
48 changes: 48 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ codegen-units = 1

[dependencies]
config = "0.15.22"
dirs = "7.0.0"
futures = "0.3.32"
globset = "0.4.18"
hf = "0.6.0"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Run `zed: open settings file` from the command palette to edit user settings jso
## References
- [GitHub Repository](https://github.com/kunlinglio/path-server)
- [VS Code Extension](https://marketplace.visualstudio.com/items?itemName=LKL.path-server)
- [Open VSX](https://open-vsx.org/extension/LKL/path-server)
- [Download VSIX](https://github.com/kunlinglio/path-server/releases/latest)
- [Zed Extension](https://zed.dev/extensions/path-server-lsp)
- [Path Server Icon](https://pictogrammers.com/library/mdi/icon/slash-forward-box/)
Expand Down
95 changes: 62 additions & 33 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,44 +61,55 @@ impl Config {
pub fn base_paths(
&self,
workspace_folders: &[String],
document_parent: Option<&String>,
user_home: Option<&String>,
document_parent: Option<&str>,
user_home: Option<&str>,
) -> Vec<(PathBuf, String, usize)> {
self.base_path
.iter()
.enumerate()
.filter_map(|(index, path)| {
if path.contains("${workspaceFolder}") {
Some(
workspace_folders
.iter()
.map(|workspace_folder| {
let expanded = path.replace("${workspaceFolder}", workspace_folder);
(PathBuf::from(expanded), path.clone(), index)
})
.collect(),
)
} else if path.contains("${document}") {
match document_parent {
Some(parent) => {
let expanded = path.replace("${document}", parent);
Some(vec![(PathBuf::from(expanded), path.clone(), index)])
.flat_map(|(index, path)| {
let result = if path.contains("${workspaceFolder}") {
workspace_folders
.iter()
.map(|workspace_folder| {
let expanded = path.replace("${workspaceFolder}", workspace_folder);
(expanded, path.clone(), index)
})
.collect()
} else {
vec![(path.clone(), path.clone(), index)]
};
result
.into_iter()
.flat_map(|mut res| {
if res.0.contains("${document}") {
match document_parent {
Some(parent) => {
res.0 = res.0.replace("${document}", parent);
Some(res)
}
None => None,
}
} else {
Some(res)
}
None => None,
}
} else if path.contains("${userHome}") {
match user_home {
Some(home) => {
let expanded = path.replace("${userHome}", home);
Some(vec![(PathBuf::from(expanded), path.clone(), index)])
})
.flat_map(|mut res| {
if res.0.contains("${userHome}") {
match user_home {
Some(home) => {
res.0 = res.0.replace("${userHome}", home);
Some(res)
}
None => None,
}
} else {
Some(res)
}
None => None,
}
} else {
Some(vec![(PathBuf::from(path), path.clone(), index)])
}
})
.map(|res| (PathBuf::from(res.0), res.1, res.2))
.collect::<Vec<_>>()
})
.flatten()
.collect()
}

Expand Down Expand Up @@ -295,7 +306,7 @@ mod tests {
};

let workspace_folders = vec!["/ws1".to_string(), "/ws2".to_string()];
let document_parent = Some(&"/ws1/project".to_string());
let document_parent = Some("/ws1/project");
let user_home = None;

let result = config.base_paths(&workspace_folders, document_parent, user_home);
Expand Down Expand Up @@ -334,7 +345,7 @@ mod tests {

let workspace_folders = vec![];
let document_parent = None;
let user_home = Some(&"/home/user".to_string());
let user_home = Some("/home/user");

let result = config.base_paths(&workspace_folders, document_parent, user_home);

Expand Down Expand Up @@ -403,4 +414,22 @@ mod tests {
let cfg = res.unwrap();
assert_eq!(cfg, default);
}

#[test]
fn test_base_path_with_multi_placeholder() {
let mut config = Config::default();
config.base_path = vec!["${workspaceFolder}/${document}/${userHome}".to_owned()];
let workspace_folders = vec!["1".to_owned(), "2".to_owned(), "3".to_owned()];
let document = "a";
let user_home = "b";
let resolved = config.base_paths(&workspace_folders, Some(document), Some(user_home));
assert_eq!(resolved.len(), workspace_folders.len());
assert_eq!(
resolved
.iter()
.map(|resolved| resolved.0.to_str().unwrap().to_string())
.collect::<Vec<String>>(),
vec!["1/a/b".to_owned(), "2/a/b".to_owned(), "3/a/b".to_owned()]
)
}
}
44 changes: 44 additions & 0 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ pub fn path_to_url(path: &PathBuf) -> PathServerResult<ls_types::Uri> {
)))
}

/// Expand "~" to the user's home directory
pub fn expand_tilde(path: &str, home_dir: &str) -> String {
if path.starts_with("~/") || path.starts_with("~\\") {
format!("{}{}", home_dir, &path[1..])
} else {
path.to_string()
}
}

pub fn get_home_dir() -> Option<String> {
dirs::home_dir().map(|p| p.to_string_lossy().to_string())
}

#[cfg(test)]
mod tests {
use std::str::FromStr;
Expand All @@ -105,4 +118,35 @@ mod tests {
_ => assert!(false, "expected Unsupported error, got: {}", err),
}
}

#[test]
fn test_expand_tilde() {
let mock_home_dir = tempfile::tempdir().unwrap();
let mock_home_dir_str = mock_home_dir.path().to_string_lossy();

let result = expand_tilde("~/projects", &mock_home_dir_str);
assert_eq!(result, format!("{}/projects", mock_home_dir_str));
let result = expand_tilde("/path/without/tilde", &mock_home_dir_str);
assert_eq!(result, "/path/without/tilde".to_string());
}

#[test]
fn test_get_home_dir() {
let home_dir = get_home_dir().unwrap();
assert!(PathBuf::from(home_dir.clone()).exists());
assert!(PathBuf::from(home_dir.clone()).is_absolute());
expand_tilde("test_dir", &home_dir);
assert!(PathBuf::from(home_dir).is_absolute());
}

#[test]
fn test_windows_home_path() {
let mock_home_dir = tempfile::tempdir().unwrap();
let mock_home_dir_str = mock_home_dir.path().to_string_lossy();

let result = expand_tilde("~\\projects", &mock_home_dir_str);
assert_eq!(result, format!("{}\\projects", mock_home_dir_str));
let result = expand_tilde("\\path\\without\\tilde", &mock_home_dir_str);
assert_eq!(result, "\\path\\without\\tilde".to_string());
}
}
Loading