Skip to content

Add filepath completion#184

Open
rszyma wants to merge 7 commits into
oxalica:mainfrom
rszyma:filepath-completion
Open

Add filepath completion#184
rszyma wants to merge 7 commits into
oxalica:mainfrom
rszyma:filepath-completion

Conversation

@rszyma
Copy link
Copy Markdown
Contributor

@rszyma rszyma commented Nov 8, 2025

Closes #183

This PR adds completion for local file paths.

It works by suggesting only next possible segments in a path, not recursively all files. It's similar to gopls path suggestions of modules.

TODO

  • Fix completion for ./$0 not working, because it's being parsed as BinaryOp(BinaryOp(BINARY_OP@0..2)) (a division operation?), while I'd expect it to parse as literal, just like ./asdf/$0 parses as Literal(Literal(LITERAL@0..7)). This should either be fixed in in parser or though some hack. This also applies to ../$0 and ~/$0.
  • Paths with dynamic parts (with a variable) should never trigger completion, it's not handled explicitly currently.
  • Maybe replace glob lib with something native? Maybe std::fs::read_dir? We don't need full glob capability.
  • Add tests? (not sure how to test this...)

@rszyma rszyma force-pushed the filepath-completion branch 2 times, most recently from f9c7185 to 97cb525 Compare November 8, 2025 17:44
@rszyma rszyma force-pushed the filepath-completion branch from 97cb525 to 5183704 Compare November 8, 2025 17:53
> use of deprecated function `std::env::home_dir`: This function's
behavior may be unexpected on Windows. Consider using a crate from
crates.io instead.
@rszyma
Copy link
Copy Markdown
Contributor Author

rszyma commented Nov 8, 2025

This is good enough for review now.
I'm not sure how to handle unit tests for this, any ideas? Should I just skip writing them?

From some manual testing I did, it works in every case I could think of:

  • ./folder/$0, ../folder/$0, ~/folder/$0
  • ./$0, ../$0, ~/$0
  • all above, but in a .nix file placed in sub-directory of a workspace

edit: also tested for absolute paths

@rszyma rszyma marked this pull request as ready for review November 8, 2025 22:34
@oxalica oxalica added C-feature Catagory: feature A-parser Area: syntax parser A-complete Area: completion labels Dec 10, 2025
..instead of full token.
Every other completion works like this too.

For example:
  ./pa$0th/to/file
previously this would only show files starting with `./path/to/file`,
not `./pa` like expected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-complete Area: completion A-parser Area: syntax parser C-feature Catagory: feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Completion for paths

2 participants