From 80cf9083d3d38ce2e6e37c9da77e5ed87de3cb35 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Salinas Date: Tue, 18 Apr 2023 01:46:22 -0400 Subject: [PATCH] lsp: lua_ls --- init.lua | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/init.lua b/init.lua index bc6a03e..ee3bfbb 100644 --- a/init.lua +++ b/init.lua @@ -153,6 +153,18 @@ local servers = { gopls = {}, jsonls = {}, kotlin_language_server = {}, + lua_ls = { + settings = { + Lua = { + runtime = { version = "LuaJIT" }, + diagnostics = { globals = { "vim" } }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true), + }, + telemetry = { enable = false }, + }, + }, + }, marksman = {}, pylsp = {}, rust_analyzer = {}, @@ -166,10 +178,17 @@ local servers = { -- Auto format on save vim.api.nvim_create_autocmd({ "BufWritePre" }, { callback = function() - if next(vim.lsp.get_active_clients()) == nil then - cmd("Format") - else + local lsp_format = false + for _, client in pairs(vim.lsp.get_active_clients({ bufnr = 0 })) do + if client.server_capabilities.documentFormattingProvider then + lsp_format = true + break + end + end + if lsp_format then vim.lsp.buf.format({ async = false }) + else + cmd("Format") end end, }) @@ -181,13 +200,13 @@ g.ale_go_golangci_lint_package = 1 ---- nvim-lint ---- local lint = require("lint") local clippy_format = "%E%f:%l:%c: %\\d%#:%\\d%# %.%\\{-}" - .. "error:%.%\\{-} %m,%W%f:%l:%c: %\\d%#:%\\d%# %.%\\{-}" - .. "warning:%.%\\{-} %m,%C%f:%l %m,%-G,%-G" - .. "error: aborting %.%#,%-G" - .. "error: Could not compile %.%#,%E" - .. "error: %m,%Eerror[E%n]: %m,%-G" - .. "warning: the option `Z` is unstable %.%#,%W" - .. "warning: %m,%Inote: %m,%C %#--> %f:%l:%c" + .. "error:%.%\\{-} %m,%W%f:%l:%c: %\\d%#:%\\d%# %.%\\{-}" + .. "warning:%.%\\{-} %m,%C%f:%l %m,%-G,%-G" + .. "error: aborting %.%#,%-G" + .. "error: Could not compile %.%#,%E" + .. "error: %m,%Eerror[E%n]: %m,%-G" + .. "warning: the option `Z` is unstable %.%#,%W" + .. "warning: %m,%Inote: %m,%C %#--> %f:%l:%c" -- clippy -- lint.linters.clippy = { @@ -215,7 +234,7 @@ lint.linters.yamllint.args = { args = { "--format=parsable", "-d relaxed" }, } -linters = { +local linters = { bash = { "shellcheck" }, dockerfile = { "hadolint" }, go = { "golangcilint" },