Skip to content

Commit

Permalink
Fix import completion filtering.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcorre committed Nov 2, 2024
1 parent 883244a commit 2e76069
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pbls"
version = "1.0.5"
version = "1.0.6"
edition = "2021"
license = "MIT"
description = "Protobuf Language Server"
Expand Down
13 changes: 6 additions & 7 deletions src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,10 @@ impl Workspace {
let items = self
.proto_paths
.iter()
.map(|p| find_protos(p.as_path(), &existing))
.map(|p| find_protos(p.as_path()))
.flat_map(|p| {
p.iter()
.filter(|s| !existing.contains(&s.as_str()))
.map(|s| lsp_types::CompletionItem {
insert_text: Some(format!("{}\";", s)),
label: s.to_owned(),
Expand All @@ -493,7 +494,7 @@ impl Workspace {
}
}

fn find_protos(dir: &std::path::Path, excludes: &Vec<&str>) -> Vec<String> {
fn find_protos(dir: &std::path::Path) -> Vec<String> {
let mut res = vec![];
let entries = match std::fs::read_dir(dir) {
Ok(ok) => ok,
Expand Down Expand Up @@ -522,7 +523,7 @@ fn find_protos(dir: &std::path::Path, excludes: &Vec<&str>) -> Vec<String> {

if meta.is_dir() {
let dir = dir.join(path.path());
let protos = find_protos(dir.as_path(), excludes);
let protos = find_protos(dir.as_path());
let root = &path.file_name();
let root = std::path::PathBuf::from(root);
res.extend(
Expand All @@ -546,10 +547,8 @@ fn find_protos(dir: &std::path::Path, excludes: &Vec<&str>) -> Vec<String> {
continue;
}

if !excludes.contains(&name) {
log::trace!("Found import {name:?}");
res.push(name.to_string())
}
log::trace!("Found import {name:?}");
res.push(name.to_string())
}
res
}
Expand Down
10 changes: 10 additions & 0 deletions testdata/folder/what.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";

package folder.what;

import "folder/stuff.proto";

message What{
stuff.Stuff stuff = 1;
}

5 changes: 2 additions & 3 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,11 +749,10 @@ fn test_complete_import() -> pbls::Result<()> {
insert_text: Some("error.proto\";".into()),
..Default::default()
},
// BUG: Should be excluded
CompletionItem {
label: "folder/stuff.proto".into(),
label: "folder/what.proto".into(),
kind: Some(CompletionItemKind::FILE),
insert_text: Some("folder/stuff.proto\";".into()),
insert_text: Some("folder/what.proto\";".into()),
..Default::default()
},
],
Expand Down

0 comments on commit 2e76069

Please sign in to comment.