-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Support going to specific positions in file #5260
base: master
Are you sure you want to change the base?
Conversation
helix-term/src/commands.rs
Outdated
@@ -1057,11 +1062,81 @@ fn goto_file_impl(cx: &mut Context, action: Action) { | |||
.to_string(), | |||
); | |||
} | |||
|
|||
// Clippy output format. | |||
let regex_file_row_col = Regex::new("(?P<path>.[^:]+):(?P<row>\\d+):(?P<col>\\d+)").unwrap(); |
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.
This is too specific to Rust, and so we probably want to use a more generic way of detecting this information. Ideally, I'd imagine that you could do something like cargo clippy | regex_query | hx
.
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.
I think ideally we should support all common formats so that Helix always works out of the box.
In fact, I'd argue PATH:ROW:COL
and PATH:ROW
are not very Rust specific. A lot of compilers print paths in this way. For example, webpack prints in this exact format as well.
Also, one more argument for not relying on terminal piping has been specified in the linked issue (#5259): this feature would be very useful once integrated terminal is implemented, where you can't do any text transformation at all, so this workaround doesn't apply anymore.
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.
Actually, now that I think about it, we should support the absence of :COL
as well. PATH:ROW:COL
and PATH:ROW
are very commonly used so I think also support it in this PR makes sense.
I just checked and clang
also prints in this format. I guess most compilers just use this format.
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.
Added support for just PATH:ROW
too (without :COL
). Also updated the comment itself to be not Rust-specific.
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.
It can also be turned into a lazy static.
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.
Lines 90 to 100 in df1830e
pub(crate) fn parse_file(s: &str) -> (PathBuf, Position) { | |
let def = || (PathBuf::from(s), Position::default()); | |
if Path::new(s).exists() { | |
return def(); | |
} | |
split_path_row_col(s) | |
.or_else(|| split_path_row(s)) | |
.unwrap_or_else(def) | |
} | |
/// Split file.rs:10:2 into [`PathBuf`], row and col. |
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.
@archseer Ah I was actually referring to the file path detector used in vscode pointed out by @pascalkuthe:
The simple case of PATH:ROW:COL
already works pretty well in this PR with no additional dependency needed. Thefancy-regex
crate is needed to port the whole vscode detector over (which allows us to have to same file linking capability as vscode, which works pretty awesome imo).
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.
Sorry. I studied the vscode detector regexs deeper and it turns out that those are not meant to be backreferences. \0
there actually intends to mean the unicode char \u0000
if I'm not mistaken. In that case, we actually don't need fancy-regex
. The existing regex
crate should work just fine.
Looks like regex101 is wrong. It says in the JavaScript regex engine \0
means backreference, but it seems to actually mean the \u0000
char based on my test in node
.
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.
Yeah I don't think you need to backtrack for the so.ole cases. I wanted to take a look at the regexes to confirm but didn't get the chance. I don't think we want to lull in fancy regex
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.
@pascalkuthe Yeah I was also wondering why they even needed backreferences at all. I guess I just trusted regex101 too much :/
483a62f
to
28bcbf4
Compare
The reason I coded my own char index calculation is that the LSP impl is not forgiving enough: I want to allow "clamping" the designated position into the actual doc range in a predictable and reasonable way, whereas such a mismatch in the context of LSP would be considered a bug. Actually, maybe I should refactor this into an option when calling |
You can provide line/cols already with CLI args: Also see Lines 90 to 98 in 8347139
goto_file_impl ?
|
I also ran into that function and taught the same thing. I was under the impression that @xJonathanLEI implemented support for those captures but looking at the PR it does look like currently only Regardless the current implementation can not just use I think the best solution here would be to have a regex set of all possible file regexes (taken from vscode) and select the first regex capture that contains the current cursor. We could factor that regex out into a function tough and reuse it in On a sidenote: Currently |
This sounds like a good way to improve the smart detection in this block: helix/helix-term/src/commands.rs Lines 1037 to 1058 in 2b58ff4
But the automatic detection of whether surrounding text is a file/row/column should be separate from the parsing of the contents of the selection: when there is a selection (i.e. >1 width) goto-file should just parse the contents of the selection without trying to be smart about the surrounding text.
I believe it's the other way around: the automatic detection was implemented on top of the parsing of the current selections. Kakoune only parses the contents of the selections since that fits the select-then-act paradigm (also see the original discussion in #1102 (comment)). The smart detection is a sort of separate feature that should only kick in if there's a single 1-width cursor. |
Thanks for the additional context. I was sort of coming from the standpoint of looking at In that case it probably works best to separate as a a |
Yep I was actually going to suggest replacing the "waiting-on-review" tag with "waiting-on-author" since I haven't implemented the vscode detector. Regarding the behavior when a selection is used, here's my 2 cents after thinking about it more. The way I think about it is: do we lose support for any use case if we implement it one way over another? Since you can always collapse the selection into a single-char one with Here's one missing use case if Imagine you generated the console logs containing the relative file path from the parent folder of CWD. Say you're in Oops, the editor is too smart, it finds out the "complete" path is This is something vscode doesn't have to even think about since it's mouse-oriented. |
Update: I shifted focus to Git related stuff as I personally don't need the full-fledged detector and am happy with the current implementation here. Anyone interested in taking this PR across the finish line please feel free to do so :) |
28bcbf4
to
02a68c8
Compare
vim-fetch also has some patterns that I think aren't in vscode's matcher: https://github.com/wsdjeg/vim-fetch/blob/master/autoload/fetch.vim#L12-L75 |
02a68c8
to
3ad8159
Compare
3ad8159
to
3a1c732
Compare
Resolves #5259.
Now you can pipe clippy output into a file, open the file in Helix, and easily navigate to the exact locations of the warnings/errors.