helix
helix copied to clipboard
Let gf go to file with line number
The goto_file function doesn't handle file paths with line numbers unlike :open On a path: 'path/to/file.txt:55' goto_file will open an empty buffer path/to/file.txt:55, which is somewhat nonsensical. (shouldn't this just error out?)
:open path/to/file.txt:55 will instead open the correct file on the expected line. This is the behavior I would expect from marking a path and pressing gf
Id like to pick this one up, just need some clarity on the expected behavior. Should the line number be added to the goto command, or should it error out? If it should be added, but its provided an invalid line number should it still open the file?
A reasonable expectation would be a similar behavior as :o, where if a line number larger than the length of the file is provided, it just goes to the last line of that file. Further :o will correctly open a file at some line even if the file doesn't exist. As apposed to the current behavior of gf that adds the line number to the file name created.
Is it desired behavior that gf creates new files when the file doesn't already exist? It feels a bit weird to me, but maybe there are some use cases for it.
I was thinking the same but was hoping to get some feedback from the project members before I put any time into it.
Yep I think it's reasonable for gf
to act basically the same as :open
added PR #9519
I'd argue that gf
should not behave like :open
if the file doesn't exist.
Isn't the main use case for gf
to visit the location of errors produced by some external tool, like a compiler or linter?
That tool might print relative paths that are not relative to helix's current directory.
It would be better to signal an error on such a path so the user can :cd
, instead of creating a new file.
Is there a use for gf
where creating a file is the right thing to do?
I see that PR #9519 will check the current file's directory as well as the helix working directory. But if the file doesn't exist in either case it will still create it. I still don't see when creating it would be the right thing.
:open
doesn't actually create the file - it's just opening a new buffer with that path set. You can use :buffer-close
(:bc
) to close that buffer
My favored behavior would be to open the file picker either with all files with the name under cursor. Here, the user could type in the path that he needs. Whenever there is only one file in the picker, we could choose this immediately.