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

add lsp format operator mapping #546

Merged
merged 3 commits into from
Sep 21, 2024
Merged

add lsp format operator mapping #546

merged 3 commits into from
Sep 21, 2024

Conversation

Konfekt
Copy link
Contributor

@Konfekt Konfekt commented Aug 10, 2024

As convenience complementing, say xnoremap gw :LspFormat<cr>

Comment on lines +79 to +87
def LspFormatFunc(type: string, visual_mode = v:false)
if visual_mode
exe "normal! gv:LspFormat\<cr>"
elseif type ==# 'line'
exe "normal! '[V']:LspFormat\<cr>"
elseif type ==# 'char'
exe "normal! `[v`]:LspFormat\<cr>"
endif
enddef
Copy link
Contributor

Choose a reason for hiding this comment

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

seems a bit mess, are you sure the logic was correct?
btw: the range format normally required lsp server gave it.
vs to local, not sure if it was ok, or if you made it really work, maybe ok too? 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Works for me and is a suggestion. Feel free to improve, I am stuck with Legacy Vim script for the moment in view of the divergent eco system. Likely the function has to go into autoload, if ever accepted.

Copy link
Contributor

Choose a reason for hiding this comment

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

there is lsp#lsp#FormatExpr() already, though req lsp server gave the range format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, I am not sure if the lsp server understands the range correctly yet; for example, formatting a single line of a comment with clangd formats the whole comment

@yegappan yegappan merged commit c813516 into yegappan:main Sep 21, 2024
2 checks passed
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.

3 participants