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

format with rnix-lsp leaves selection #2655

Closed
farwyler opened this issue Jun 3, 2022 · 6 comments
Closed

format with rnix-lsp leaves selection #2655

farwyler opened this issue Jun 3, 2022 · 6 comments
Labels
C-bug Category: This is a bug upstream

Comments

@farwyler
Copy link
Contributor

farwyler commented Jun 3, 2022

Summary

when using format with rnix-lsp the whole buffer remains selected after formatting. this does not happen with other lsps (tested with rust-analyzer and typescript ls)

Reproduction Steps

  1. setup rnix-lsp
  2. open .nix file
{
  description = "bug";
}
  1. use format command or write with auto-format
  2. the text is formated correctly
  3. whole buffer remains in selection

Helix log

2022-06-03T08:39:34.329 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[],"uri":"file:///Users/xxx/projects/helix/test.nix"}}
2022-06-03T08:39:39.975 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/formatting","params":{"options":{"insertSpaces":true,"tabSize":2},"textDocument":{"uri":"file:///Users/xxx/projects/helix/test.nix"}},"id":1}
2022-06-03T08:39:39.976 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","id":1,"result":[{"newText":"{\n  description = \"bug\";\n}\n","range":{"end":{"character":0,"line":3},"start":{"character":0,"line":0}}}]}
2022-06-03T08:39:39.976 helix_lsp::transport [INFO] <- [{"newText":"{\n  description = \"bug\";\n}\n","range":{"end":{"character":0,"line":3},"start":{"character":0,"line":0}}}]
2022-06-03T08:39:39.978 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":0,"line":3},"start":{"character":0,"line":0}},"text":"{\n  description = \"bug\";\n}\n"}],"textDocument":{"uri":"file:///Users/xxx/projects/helix/test.nix","version":3}}}
2022-06-03T08:39:39.978 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[],"uri":"file:///Users/xxx/projects/helix/test.nix"}}
2022-06-03T08:39:41.569 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"shutdown","params":null,"id":2}
2022-06-03T08:39:41.569 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","id":2,"result":null}
2022-06-03T08:39:41.570 helix_lsp::transport [INFO] <- null
2022-06-03T08:39:41.570 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"exit","params":null}
2022-06-03T08:39:41.571 helix_lsp::transport [ERROR] err: <- StreamClosed
2022-06-03T08:39:41.571 helix_lsp::transport [ERROR] err: <- StreamClosed

Platform

macOS

Terminal Emulator

kitty

Helix Version

22.05-24-gfd4858c0

@farwyler farwyler added the C-bug Category: This is a bug label Jun 3, 2022
@farwyler farwyler changed the title auto-format with rnix-lsp leaves selection format with rnix-lsp leaves selection Jun 3, 2022
@archseer
Copy link
Member

archseer commented Jun 5, 2022

The LSP sent back a whole document replacement rather than a bunch of changes, so we aren't able to figure out where the new location of the cursor is. Since this is sort of like deleting the whole document first, then appending into the selection you're left with a whole document selection.

@archseer
Copy link
Member

archseer commented Jun 5, 2022

I guess we'd need a workaround similar to emacs-lsp/lsp-mode#258

@mtoohey31
Copy link
Contributor

I have pull requests open that will fix this on rnix-lsp's end here and here.

@mtoohey31
Copy link
Contributor

While my pull request hasn't been merged yet, it looks like this has been worked-around by #4041. Does that solve your issue @farwyler?

@farwyler
Copy link
Contributor Author

farwyler commented Nov 4, 2022

@mtoohey31 thanks for your work on rnix-lsp and nixpkgs-fmt. nowadays i use nil + alejandra. i gave #4041 a quick try and it seems to work very well.

@farwyler farwyler closed this as completed Nov 4, 2022
@mtoohey31
Copy link
Contributor

You're welcome! I actually just switched to nil too 🙂 I came across #4041 because I was wondering why I wasn't running into the problem described in this issue, since nil also applies full-document edits.

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 upstream
Projects
None yet
Development

No branches or pull requests

4 participants