From 615413d6e25dd5118a18942d673499d74138328a Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Thu, 22 Dec 2022 20:41:30 +0000 Subject: [PATCH] style(vim): add lua style and luacheck and format lsp config again --- .luacheckrc | 12 ++++ .stylua.toml | 6 ++ site-modules/core/files/vim/plugin/lsp.lua | 82 +++++++++++----------- 3 files changed, 59 insertions(+), 41 deletions(-) create mode 100644 .luacheckrc create mode 100644 .stylua.toml diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..768a8ec --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,12 @@ +-- Rerun tests only if their modification time changed. +cache = true + +std = luajit +codes = true + +self = false + +-- Global objects defined by the C code +read_globals = { + "vim", +} diff --git a/.stylua.toml b/.stylua.toml new file mode 100644 index 0000000..ecb6dca --- /dev/null +++ b/.stylua.toml @@ -0,0 +1,6 @@ +column_width = 120 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferDouble" +call_parentheses = "None" diff --git a/site-modules/core/files/vim/plugin/lsp.lua b/site-modules/core/files/vim/plugin/lsp.lua index ab50880..ef0e07d 100644 --- a/site-modules/core/files/vim/plugin/lsp.lua +++ b/site-modules/core/files/vim/plugin/lsp.lua @@ -1,57 +1,57 @@ -local lspconfig = require("lspconfig") +local lspconfig = require "lspconfig" local servers = { - -- Language servers for the day to day web development, could probably think - -- about loosing the html and css one and living with typescript and emmet - tsserver = {}, - html = {}, - cssls = {}, - emmet_ls = { - filetypes = { "html", "typescriptreact", "javascriptreact", "css", "scss", "eruby" }, - }, - -- Ruby - solargraph = {}, - -- Rust - rust_analyzer = {}, - -- Lua for the vim config and plugin dev - sumneko_lua = { - settings = { - Lua = { - runtime = { version = "LuaJIT" }, - diagnostics = { globals = { "vim" } }, - workspace = { library = vim.api.nvim_get_runtime_file("", true) }, - telemetry = { enable = false }, - }, - }, - }, + -- Language servers for the day to day web development, could probably think + -- about loosing the html and css one and living with typescript and emmet + tsserver = {}, + html = {}, + cssls = {}, + emmet_ls = { + filetypes = { "html", "typescriptreact", "javascriptreact", "css", "scss", "eruby" }, + }, + -- Ruby + solargraph = {}, + -- Rust + rust_analyzer = {}, + -- Lua for the vim config and plugin dev + sumneko_lua = { + settings = { + Lua = { + runtime = { version = "LuaJIT" }, + diagnostics = { globals = { "vim" } }, + workspace = { library = vim.api.nvim_get_runtime_file("", true) }, + telemetry = { enable = false }, + }, + }, + }, } local on_attach = function(_, bufnr) - vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") + vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") - local opts = { noremap = true, silent = true } + local opts = { noremap = true, silent = true } - -- Mappings. - -- See `:help vim.lsp.*` for documentation on any of the below functions - vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "lua vim.lsp.buf.implementation()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "lua vim.lsp.buf.implementation()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "rn", "lua vim.lsp.buf.rename()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "ca", "lua vim.lsp.buf.code_action()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "rn", "lua vim.lsp.buf.rename()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "ca", "lua vim.lsp.buf.code_action()", opts) end local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) capabilities.textDocument.completion.completionItem.snippetSupport = true for lsp, config in pairs(servers) do - config["on_attach"] = on_attach - config["capabilities"] = capabilities - config["init_options"] = { usePlaceholders = true } + config["on_attach"] = on_attach + config["capabilities"] = capabilities + config["init_options"] = { usePlaceholders = true } - lspconfig[lsp].setup(config) + lspconfig[lsp].setup(config) end -- Change the diagnostic signs @@ -59,6 +59,6 @@ vim.fn.sign_define("DiagnosticSignHint", { text = "➤", texthl = "DiagnosticSig vim.fn.sign_define("DiagnosticSignInfo", { text = "ℹ", texthl = "DiagnosticSignInfo", numhl = "DiagnosticSignInfo" }) vim.fn.sign_define("DiagnosticSignWarn", { text = "⚠", texthl = "DiagnosticSignWarn", numhl = "DiagnosticSignWarn" }) vim.fn.sign_define( - "DiagnosticSignError", - { text = "✖", texthl = "DiagnosticSignError", numhl = "DiagnosticSignError" } + "DiagnosticSignError", + { text = "✖", texthl = "DiagnosticSignError", numhl = "DiagnosticSignError" } )