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

[draft] Add formatting support #471

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ldrumm
Copy link

@ldrumm ldrumm commented May 23, 2024

This is an RFC for potential textDocument/rangeFormatting and textDocument/formatting support (line ranges only in the present implementation).

I'm basing this off the 3.18 spec and have done basic testing with clangd-15 where things seem to be working well.

Since I'm not particularly familiar with the vim-lsc architecture and formatprg etc, I'm open to any ideas on how to hook up these new functions to formatprg (or not as might be the cleaner case) and how to handle the default formatting options (see FIXME comment in format.vim)

This is an RFC for textDocument/rangeFormatting (line ranges only at
present), and `textDocument/formatting`.

I'm basing this off the 3.18 spec and have done basic testing with
clangd.
@ldrumm
Copy link
Author

ldrumm commented Jul 26, 2024

I've been using this patch locally in my day-today (C/C++ with clangd as my LSP) and it seems stable well. Any comments you have on resolving the TODOs here would be appreciated.

Happy to receive comments from other LSP users in particular

@@ -44,6 +44,8 @@ command! LSClientDisable call lsc#server#disable()
command! LSClientEnable call lsc#server#enable()
command! LSClientDisableDiagnosticHighlights call <SID>DisableHighlights()
command! LSClientEnableDiagnosticHighlights call <SID>EnableHighlights()
command! LSClientFormat call lsc#format#formatFile()
command! -range LSClientFormat '<,'> call lsc#format#formatRange()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overrides the :LSClientFormat that calls formatFile(); running it doesn't work:

:100verbose LSClientFormat
Executing: '<,'> call lsc#format#formatRange()
E20: Mark not set

If I do use visual mode to set <' and '> I get:

[lsc:Error] JSON RPC method not found: "RangeFormatting" not yet implemented

I guess my LSP server doesn't implement that.

Anyway, if I comment out this line then it works. Probably need to be a bit smarter about the range being passed and what mode it's in.


"call lsc#message#error('onresult')
if a:textedit == v:null | return | endif
call lsc#message#log('got edits' . json_encode(a:textedit), 'Info')
Copy link
Contributor

@arp242 arp242 Oct 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably shouldn't have these log lines (there's a few more of them)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants