helix icon indicating copy to clipboard operation
helix copied to clipboard

Let gf go to file with line number

Open Haxxflaxx opened this issue 1 year ago • 8 comments

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

Haxxflaxx avatar Jan 26 '24 19:01 Haxxflaxx

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?

scdailey avatar Jan 30 '24 19:01 scdailey

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.

Haxxflaxx avatar Jan 31 '24 21:01 Haxxflaxx

I was thinking the same but was hoping to get some feedback from the project members before I put any time into it.

scdailey avatar Jan 31 '24 21:01 scdailey

Yep I think it's reasonable for gf to act basically the same as :open

the-mikedavis avatar Feb 03 '24 19:02 the-mikedavis

added PR #9519

scdailey avatar Feb 04 '24 01:02 scdailey

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?

jba avatar Feb 17 '24 00:02 jba

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.

jba avatar Feb 17 '24 00:02 jba

: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

the-mikedavis avatar Feb 17 '24 01:02 the-mikedavis

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.

marc-thieme avatar Apr 09 '24 22:04 marc-thieme