Skip to content
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

:w selects the whole file, thus losing caret placement. #2752

Closed
LollipopFt opened this issue Jun 11, 2022 · 14 comments
Closed

:w selects the whole file, thus losing caret placement. #2752

LollipopFt opened this issue Jun 11, 2022 · 14 comments
Labels
C-bug Category: This is a bug

Comments

@LollipopFt
Copy link
Contributor

Summary

2022-06-12_01-23-27.mp4

as seen in the video above, when keying in :w, the entire file gets selected, and my caret always returns to the start when i exit it.

settings:

theme='onedark'
[keys.normal]
't'='move_line_down'
'n'='move_line_up'
's'='move_char_right'
'j'='find_till_char'
'k'='search_next'
'l'='select_regex'
[keys.insert]
','={'.'='normal_mode'}
[editor]
scrolloff=255
mouse=false
auto-completion=true
idle-timeout=0
completion-trigger-len=2
rulers=[80,100,120]
[editor.cursor-shape]
insert='bar'
[editor.whitespace]
render='all'
[editor.lsp]
display-messages=true

thank you!

Reproduction Steps

I tried this:

  1. :w

I expected this to happen:
no selections made.
Instead, this happened:
above video.

Helix log

~/.cache/helix/helix.log
none

Platform

Windows

Terminal Emulator

Windows Terminal Preview 1.14.1451.0

Helix Version

helix 22.05 (27609f5)

@LollipopFt LollipopFt added the C-bug Category: This is a bug label Jun 11, 2022
@LollipopFt
Copy link
Contributor Author

LollipopFt commented Jun 11, 2022

strangely enough, it only happens to one file:

2022-06-12_01-28-14.mp4

any ideas what might be happening?

more info: the file that has :w problems is the only file with lsp linter warnings. this didn't matter. put #![allow(dead_code)] at the top of the file, removing the linter warnings, and still got this problem.

@sudormrfbin
Copy link
Member

Could be due to line endings? (from #2404):

I encountered this with rust-analyzer before. The line endings were different from what the LSP expected, and so formatting it would basically delete the entire document and send the new one with the correct line endings.

@RalfNorthman
Copy link

This happens to me too, after I upgraded to 22.05. Unfortunately I don't remember what my previous helix version was.

I've only seen it in rust-files when auto-format is on. I use rust-analyzer.

Running helix with the same configuration on a remote ubuntu machine works fine, so it seems to be windows-related.

Platform

Windows 10

Terminal Emulator

alacritty 0.10.0 (8a26dee)

Helix Version

helix 22.05 (27609f5)

@LollipopFt
Copy link
Contributor Author

@sudormrfbin possibly, i actually tried rewriting the entire file but it still caused the same problem. like i recreated it from scratch. so i have no idea what is happening...

@the-mikedavis
Copy link
Member

I think that's consistent with the line-endings theory. IIRC, if you're on windows you'll use crlf line-endings by default. You could try using :line-ending lf before formatting to see if it's just the line-endings.

@RalfNorthman
Copy link

Yeah, when using :line-ending lf auto-format on :w works as expected!

Thanks!

@LollipopFt
Copy link
Contributor Author

LollipopFt commented Jun 13, 2022

yep, can confirm this works. why does it only happen on crlf?
additional things: is there a way to see what line ending a file has like on windows notepad?
notepad:
image

@the-mikedavis
Copy link
Member

Yeah, showing the current line-endings could be a good addition after #2434.

I think this happens because rust-analyzer wants to use only lf line-endings. When it sees crlf, it reformats them all to lf.

@kirawi
Copy link
Member

kirawi commented Jun 13, 2022

Perhaps it would also be possible to ask for rust-analyzer to be smarter about files with different line endings? I also wonder if other text editors have this issue with CRLF, and how they retain cursor position (if they do).

@farwyler
Copy link
Contributor

For reference, this is the behaviour @the-mikedavis mentioned.
rust-analyzer sends the whole document if line-endings changed during formatting.

But that would mean we only get this behaviour once. Currently it happens again, even after rust-analyzer changed the line endings. Presumably because helix changes the line endings right back?!

Looks like Document::detect_indent_and_line_ending is not called in this case. Maybe it should be called in general when LS sends a whole doc? Just like when the document is reloaded from disk?

@the-mikedavis
Copy link
Member

Ah good catch @farwyler! Yes let's call detect_indent_and_line_ending when the LSP sends the whole document. Would you like to make a PR?

@farwyler
Copy link
Contributor

@the-mikedavis will do

@farwyler
Copy link
Contributor

Additionally...

i found a bug in rust-analyzer as well. When it sends the whole document because it wants to change the line endings, the replacement document actually uses the old line endings. This results in helix always receiving the whole document, because the endings never actually change.

I have created an issue here
rust-lang/rust-analyzer#12540

@sudormrfbin
Copy link
Member

Closed by #2778.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug
Projects
None yet
Development

No branches or pull requests

6 participants