Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added an map api for pathCompleter #5940

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Gmin2
Copy link

@Gmin2 Gmin2 commented Mar 7, 2025

A map API to PathCompleter and added its test, the map method allows customization of completion candidates after filtering, enabling use cases like highlighting directories, labeling etc

@Gmin2 Gmin2 force-pushed the map-api-PathCompleter branch 2 times, most recently from f547e3c to 51a319c Compare March 7, 2025 12:34
Comment on lines 1213 to 1226
.map(|candidate| {
let path = Path::new(candidate.get_value());
let cargo_toml_path = path.join("Cargo.toml");
let has_cargo_toml = cargo_toml_path.exists();

if has_cargo_toml {
candidate
.help(Some("Addable cargo package".into()))
.display_order(Some(0))
} else {
candidate.display_order(Some(1))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please demonstrate this feature when there is a user-provided directory filter and a map is used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And/or PathCompleter::file is being used with map

@Gmin2 Gmin2 force-pushed the map-api-PathCompleter branch from 51a319c to d946106 Compare March 8, 2025 07:16
@Gmin2 Gmin2 requested a review from epage March 8, 2025 07:16
@Gmin2 Gmin2 force-pushed the map-api-PathCompleter branch 2 times, most recently from 036b441 to aea7818 Compare March 8, 2025 08:25
Comment on lines +1232 to +1196
#[test]
fn suggest_value_path_with_filter_and_mapper() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention of the split commits was for this test to overwrite the suggest_value_path_without_mapper, showing the change in behavior. Only the call to map and output should change in this commit.

Copy link
Author

@Gmin2 Gmin2 Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in this and added an additional test mentioned here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All test additions should be done in the first commit

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So @epage, i should do that same as i did for suggest_value_path_with_mapper (in the first commit showing the behaviour without mapper and then showing the behaviour with mapper right ?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@Gmin2 Gmin2 force-pushed the map-api-PathCompleter branch 2 times, most recently from 8bb3c50 to cce8d49 Compare March 12, 2025 07:15
@Gmin2 Gmin2 force-pushed the map-api-PathCompleter branch from cce8d49 to d3ef660 Compare March 12, 2025 07:23
@Gmin2 Gmin2 requested a review from epage March 12, 2025 07:59
.filter(|path| {
path.file_name()
.and_then(|n| n.to_str())
.map_or(false, |name| name.starts_with('c'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you ran clippy on this, it would complain about the use of map_or. CI isn't catching it because we aren't running it on unstable features from non-default packages.

Comment on lines 1217 to 1220
.map_or(false, |name| name.starts_with('c'))
})
.map(|candidate| {
if candidate.get_value().to_string_lossy().contains("c_dir") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. These two are filtering under different conditions
  2. Logically, it feels odd that we're mapping on something that was filtered out. We shouldn't have to re-filter inside the map.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... so i am thinking of filtering first if its a directory and then the mapping if it contains c_dir
thats seem correct right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map should only applied to content that matched filter.

Comment on lines +1224 to +1225
} else {
candidate.display_order(Some(1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this this being done? display order should be taken care of

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the display_order in the else branch ensures that c_dir comes first, if i dont include display_order() in the else branch it does not sort it properly

---- expected: tests/testsuite/engine.rs:1232:9
++++ actual:   In-memory
   1      - c_dir/      Addable cargo package
   2      - d_dir/∅
        1 + .
        2 + d_dir/
        3 + c_dir/      Addable cargo package∅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we filtered out d_dir, then it should be last. If it isn't, something else is going on and should be investigated and fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants