Skip to content

Commit

Permalink
Store workspace root and search paths as paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
InsertCreativityHere committed Feb 14, 2024
1 parent 122db1c commit 21c540d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions server/src/configuration_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ impl ConfigurationSet {
}

/// Parses paths from a JSON value.
fn parse_paths(value: &serde_json::Value) -> Vec<String> {
fn parse_paths(value: &serde_json::Value) -> Vec<PathBuf> {
value
.get("paths")
.and_then(|v| v.as_array())
.map(|dirs_array| {
dirs_array
.iter()
.filter_map(|v| v.as_str())
.map(sanitize_path)
.map(|s| PathBuf::from(sanitize_path(s)))
.collect::<Vec<_>>()
})
.unwrap_or_default()
Expand Down
1 change: 0 additions & 1 deletion server/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ impl Session {
let workspace_root_path = params
.root_uri
.and_then(|uri| url_to_sanitized_file_path(&uri))
.map(|path| path.display().to_string())
.expect("`root_uri` was not sent by the client, or was malformed");

// This is the path to the built-in Slice files that are included with the extension. It should always
Expand Down
12 changes: 5 additions & 7 deletions server/src/slice_config.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) ZeroC, Inc.

use std::path::Path;
use std::path::PathBuf;

use slicec::slice_options::SliceOptions;

/// This struct holds configuration that affects the entire server.
#[derive(Debug, Default)]
pub struct ServerConfig {
/// This is the root path of the workspace, used to resolve relative paths. It must be an absolute path.
pub workspace_root_path: String,
pub workspace_root_path: PathBuf,
/// This is the path to the built-in Slice files that are included with the extension. It must be an absolute path.
pub built_in_slice_path: String,
}
Expand All @@ -17,7 +17,7 @@ pub struct ServerConfig {
#[derive(Debug)]
pub struct SliceConfig {
/// List of paths that will be passed to the compiler as reference files/directories.
pub slice_search_paths: Vec<String>,
pub slice_search_paths: Vec<PathBuf>,
/// Specifies whether to include the built-in Slice files that are bundled with the extension.
pub include_built_in_slice_files: bool,
}
Expand All @@ -32,14 +32,12 @@ impl Default for SliceConfig {
}

pub fn compute_slice_options(server_config: &ServerConfig, set_config: &SliceConfig) -> SliceOptions {
let root_path = Path::new(&server_config.workspace_root_path);
let root_path = &server_config.workspace_root_path;
let mut slice_options = SliceOptions::default();
let references = &mut slice_options.references;

// Add any user specified search paths at the front of the list.
for string_path in &set_config.slice_search_paths {
let path = Path::new(string_path);

for path in &set_config.slice_search_paths {
// If the path is absolute, add it as-is. Otherwise, preface it with the workspace root.
let absolute_path = match path.is_absolute() {
true => path.to_owned(),
Expand Down

0 comments on commit 21c540d

Please sign in to comment.