mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-09-28 21:05:10 +00:00
reorganize server crate by moving workspace related code to submodule (#182)
Some checks failed
test / generate-matrix (push) Has been cancelled
zizmor 🌈 / zizmor latest via PyPI (push) Has been cancelled
lint / pre-commit (push) Has been cancelled
lint / rustfmt (push) Has been cancelled
lint / clippy (push) Has been cancelled
lint / cargo-check (push) Has been cancelled
release / build (push) Has been cancelled
release / test (push) Has been cancelled
test / Python , Django () (push) Has been cancelled
test / tests (push) Has been cancelled
release / release (push) Has been cancelled
Some checks failed
test / generate-matrix (push) Has been cancelled
zizmor 🌈 / zizmor latest via PyPI (push) Has been cancelled
lint / pre-commit (push) Has been cancelled
lint / rustfmt (push) Has been cancelled
lint / clippy (push) Has been cancelled
lint / cargo-check (push) Has been cancelled
release / build (push) Has been cancelled
release / test (push) Has been cancelled
test / Python , Django () (push) Has been cancelled
test / tests (push) Has been cancelled
release / release (push) Has been cancelled
This commit is contained in:
parent
d0c745ff2a
commit
2086f80cc0
6 changed files with 170 additions and 158 deletions
43
crates/djls-server/src/workspace/utils.rs
Normal file
43
crates/djls-server/src/workspace/utils.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use percent_encoding::percent_decode_str;
|
||||
use tower_lsp_server::lsp_types::InitializeParams;
|
||||
use tower_lsp_server::lsp_types::Uri;
|
||||
|
||||
/// Determines the project root path from initialization parameters.
|
||||
///
|
||||
/// Tries the current directory first, then falls back to the first workspace folder.
|
||||
pub fn get_project_path(params: &InitializeParams) -> Option<PathBuf> {
|
||||
// Try current directory first
|
||||
std::env::current_dir().ok().or_else(|| {
|
||||
// Fall back to the first workspace folder URI
|
||||
params
|
||||
.workspace_folders
|
||||
.as_ref()
|
||||
.and_then(|folders| folders.first())
|
||||
.and_then(|folder| uri_to_pathbuf(&folder.uri))
|
||||
})
|
||||
}
|
||||
|
||||
/// Converts a `file:` URI into an absolute `PathBuf`.
|
||||
fn uri_to_pathbuf(uri: &Uri) -> Option<PathBuf> {
|
||||
// Check if the scheme is "file"
|
||||
if uri.scheme().is_none_or(|s| s.as_str() != "file") {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Get the path part as a string
|
||||
let encoded_path_str = uri.path().as_str();
|
||||
|
||||
// Decode the percent-encoded path string
|
||||
let decoded_path_cow = percent_decode_str(encoded_path_str).decode_utf8_lossy();
|
||||
let path_str = decoded_path_cow.as_ref();
|
||||
|
||||
#[cfg(windows)]
|
||||
let path_str = {
|
||||
// Remove leading '/' for paths like /C:/...
|
||||
path_str.strip_prefix('/').unwrap_or(path_str)
|
||||
};
|
||||
|
||||
Some(PathBuf::from(path_str))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue