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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Plan on supporting textDocument/rangeFormatting? #1815

Open
jcs090218 opened this issue Mar 4, 2024 · 4 comments
Open

[Question] Plan on supporting textDocument/rangeFormatting? #1815

jcs090218 opened this issue Mar 4, 2024 · 4 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@jcs090218
Copy link

I noticed this feature isn't supported. Is there a reason why this feature isn't implemented? 馃

@jcs090218 jcs090218 added the enhancement New feature or request label Mar 4, 2024
@Techatrix Techatrix added the question Further information is requested label Mar 4, 2024
@Techatrix
Copy link
Member

I don't think there is much reason to implement this feature since your entire document should just be formatted based on zig fmt. What is the use case?

@jcs090218
Copy link
Author

I used zls in Emacs through lsp-mode, but I couldn't get the formatting work by formatting the entire buffer. It makes sense since formatting the whole buffer still uses the textDocument/rangeFormatting and not textDocument/formatting. I opened up this issue and was hoping the UX could be improved (on the Emacs side). But feel free to close this if this is not planned, and sorry for the noise.

@Techatrix
Copy link
Member

It makes sense since formatting the whole buffer still uses the textDocument/rangeFormatting and not textDocument/formatting.

Could you show me how you performed formatting and checked that it used textDocument/rangeFormatting?

I was able to use lsp-mode to format a file. The default keybindings were documented here. The s-l = r keybinding which formatted only a range did not work as expected but s-l = = did.

The zig-mode plugin also has :zig-format-buffer which uses zig fmt direclty without needing ZLS. Keep in mind that zig-mode needs to find your Zig executable to perform formatting while lsp-mode with ZLS does not.

@jcs090218
Copy link
Author

jcs090218 commented Mar 5, 2024

A variable lsp-enable-indentation will allow formatting while doing the regular indent in Emacs.

See the source from lsp-mode.el:

      (when (and lsp-enable-indentation
                 (lsp-feature? "textDocument/rangeFormatting"))
        (add-function :override (local 'indent-region-function) #'lsp-format-region))

I know there is a command lsp-format-buffer; however, it won't work with the regular indent since it only uses the textDocument/rangeFormatting (see the code above).

It's not a big issue since we can always use lsp-format-buffer, but it's annoying because the regular indent functions are meaningless in Zig's buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants