Skip to content

Commit

Permalink
silently format lua file using stylua
Browse files Browse the repository at this point in the history
We need to disable the mapping set for LSP, otherwise the mapping set in
lua.vim will be overridden.
  • Loading branch information
jdhao committed Dec 19, 2024
1 parent 1d66475 commit 7e70651
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion after/ftplugin/lua.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set formatoptions-=r

nnoremap <buffer><silent> <F9> :luafile %<CR>
nnoremap <buffer><silent> <space>f <cmd>!stylua %<CR>
nnoremap <buffer><silent> <space>f <cmd>silent !stylua %<CR>
2 changes: 1 addition & 1 deletion lua/config/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ local custom_attach = function(client, bufnr)
end, { desc = "list workspace folder" })

-- Set some key bindings conditional on server capabilities
if client.server_capabilities.documentFormattingProvider then
if client.server_capabilities.documentFormattingProvider and client.name ~= "lua_ls" then
map({ "n", "x" }, "<space>f", vim.lsp.buf.format, { desc = "format code" })
end

Expand Down

0 comments on commit 7e70651

Please sign in to comment.