Skip to content

Commit d9ec56e

Browse files
committed
remove: initParam comma separated list and add toolchain.toml file
1 parent 74cdb92 commit d9ec56e

File tree

4 files changed

+35
-54
lines changed

4 files changed

+35
-54
lines changed

rust-toolchain.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[toolchain]
2+
channel = "stable"

src/config/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ pub struct ProtolsConfig {
1616
pub config: Config,
1717
}
1818

19-
#[derive(Serialize, Deserialize, Debug, Clone)]
20-
pub struct FormatterConfig {}
21-
2219
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
2320
#[serde(default)]
2421
pub struct Config {

src/config/workspace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ mod test {
304304
PathBuf::from("/init/path1"),
305305
PathBuf::from("relative/init/path"),
306306
];
307-
307+
308308
let mut ws = WorkspaceProtoConfigs::new(cli_paths);
309309
ws.set_init_include_paths(init_paths);
310310
ws.add_workspace(&WorkspaceFolder {
@@ -317,7 +317,7 @@ mod test {
317317

318318
// Check that initialization paths are included
319319
assert!(include_paths.contains(&PathBuf::from("/init/path1")));
320-
320+
321321
// The relative path should be resolved relative to the workspace
322322
let resolved_relative_path = tmpdir.path().join("relative/init/path");
323323
assert!(include_paths.contains(&resolved_relative_path));

src/lsp.rs

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ impl ProtoLanguageServer {
4040
info!("Connected with client {cname} {cversion}");
4141

4242
// Parse initialization options for include paths
43-
if let Some(init_options) = &params.initialization_options {
44-
if let Some(include_paths) = parse_init_include_paths(init_options) {
45-
info!("Setting include paths from initialization options: {:?}", include_paths);
46-
self.configs.set_init_include_paths(include_paths);
47-
}
43+
if let Some(init_options) = &params.initialization_options
44+
&& let Some(include_paths) = parse_init_include_paths(init_options)
45+
{
46+
info!(
47+
"Setting include paths from initialization options: {:?}",
48+
include_paths
49+
);
50+
self.configs.set_init_include_paths(include_paths);
4851
}
4952

5053
let file_operation_filers = vec![FileOperationFilter {
@@ -535,36 +538,25 @@ impl ProtoLanguageServer {
535538

536539
/// Parse include_paths from initialization options
537540
fn parse_init_include_paths(init_options: &Value) -> Option<Vec<PathBuf>> {
538-
match init_options {
539-
Value::Object(obj) => {
540-
if let Some(Value::Array(paths)) = obj.get("include_paths") {
541-
let mut result = Vec::new();
542-
for path_value in paths {
543-
if let Value::String(path) = path_value {
544-
result.push(PathBuf::from(path));
545-
} else {
546-
warn!("Invalid include path in initialization options: {:?}", path_value);
547-
}
548-
}
549-
if !result.is_empty() {
550-
return Some(result);
551-
}
552-
} else if let Some(Value::String(paths_str)) = obj.get("include_paths") {
553-
// Support comma-separated string format like CLI
554-
let result: Vec<PathBuf> = paths_str
555-
.split(',')
556-
.map(|s| PathBuf::from(s.trim()))
557-
.collect();
558-
if !result.is_empty() {
559-
return Some(result);
560-
}
561-
}
562-
}
563-
_ => {
564-
warn!("initialization_options is not an object: {:?}", init_options);
541+
let mut result = vec![];
542+
let paths = init_options["include_paths"].as_array()?;
543+
544+
for path_value in paths {
545+
if let Some(path) = path_value.as_str() {
546+
result.push(PathBuf::from(path));
547+
} else {
548+
warn!(
549+
"Invalid include path in initialization options: {:?}",
550+
path_value
551+
);
565552
}
566553
}
567-
None
554+
555+
if result.is_empty() {
556+
None
557+
} else {
558+
Some(result)
559+
}
568560
}
569561

570562
#[cfg(test)]
@@ -584,19 +576,6 @@ mod tests {
584576
assert_eq!(result[1], PathBuf::from("relative/path"));
585577
}
586578

587-
#[test]
588-
fn test_parse_init_include_paths_string() {
589-
let init_options = json!({
590-
"include_paths": "/path1,/path2,relative/path"
591-
});
592-
593-
let result = parse_init_include_paths(&init_options).unwrap();
594-
assert_eq!(result.len(), 3);
595-
assert_eq!(result[0], PathBuf::from("/path1"));
596-
assert_eq!(result[1], PathBuf::from("/path2"));
597-
assert_eq!(result[2], PathBuf::from("relative/path"));
598-
}
599-
600579
#[test]
601580
fn test_parse_init_include_paths_missing() {
602581
let init_options = json!({
@@ -639,11 +618,14 @@ mod tests {
639618
"../shared-protos"
640619
]
641620
});
642-
621+
643622
let include_paths = parse_init_include_paths(&neovim_style_init_options).unwrap();
644-
623+
645624
assert_eq!(include_paths.len(), 3);
646-
assert_eq!(include_paths[0], PathBuf::from("/usr/local/include/protobuf"));
625+
assert_eq!(
626+
include_paths[0],
627+
PathBuf::from("/usr/local/include/protobuf")
628+
);
647629
assert_eq!(include_paths[1], PathBuf::from("vendor/protos"));
648630
assert_eq!(include_paths[2], PathBuf::from("../shared-protos"));
649631
}

0 commit comments

Comments
 (0)