-
Notifications
You must be signed in to change notification settings - Fork 85
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
base: master
Are you sure you want to change the base?
Conversation
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.
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() |
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 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') |
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 probably shouldn't have these log lines (there's a few more of them)?
This is an RFC for potential
textDocument/rangeFormatting
andtextDocument/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)