-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: master
Are you sure you want to change the base?
Conversation
f547e3c
to
51a319c
Compare
.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)) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
51a319c
to
d946106
Compare
036b441
to
aea7818
Compare
#[test] | ||
fn suggest_value_path_with_filter_and_mapper() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
8bb3c50
to
cce8d49
Compare
cce8d49
to
d3ef660
Compare
.filter(|path| { | ||
path.file_name() | ||
.and_then(|n| n.to_str()) | ||
.map_or(false, |name| name.starts_with('c')) |
There was a problem hiding this comment.
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.
.map_or(false, |name| name.starts_with('c')) | ||
}) | ||
.map(|candidate| { | ||
if candidate.get_value().to_string_lossy().contains("c_dir") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- These two are filtering under different conditions
- Logically, it feels odd that we're mapping on something that was filtered out. We shouldn't have to re-
filter
inside themap
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
} else { | ||
candidate.display_order(Some(1)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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∅
There was a problem hiding this comment.
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.
A
map
API toPathCompleter
and added its test, themap
method allows customization of completion candidates after filtering, enabling use cases like highlighting directories, labeling etc