diff options
Diffstat (limited to 'lua/alpha')
| -rw-r--r-- | lua/alpha/lsp/attach.lua | 1 | ||||
| -rw-r--r-- | lua/alpha/lsp/default.lua | 26 | ||||
| -rw-r--r-- | lua/alpha/lsp/flags.lua | 3 | ||||
| -rw-r--r-- | lua/alpha/lsp/init.lua | 68 | ||||
| -rw-r--r-- | lua/alpha/lsp/servers.lua | 173 | ||||
| -rw-r--r-- | lua/alpha/lsp/servers/emmet_ls.lua | 12 | ||||
| -rw-r--r-- | lua/alpha/lsp/servers/html.lua | 14 | ||||
| -rw-r--r-- | lua/alpha/lsp/servers/jsonls.lua | 14 | ||||
| -rw-r--r-- | lua/alpha/lsp/servers/lua_ls.lua | 29 | ||||
| -rw-r--r-- | lua/alpha/lsp/servers/phpactor.lua | 28 | ||||
| -rw-r--r-- | lua/alpha/lsp/servers/rust_analyzer.lua | 24 | ||||
| -rw-r--r-- | lua/alpha/lsp/servers/tsserver.lua | 33 | ||||
| -rw-r--r-- | lua/alpha/telescope/init.lua | 8 |
13 files changed, 247 insertions, 186 deletions
diff --git a/lua/alpha/lsp/attach.lua b/lua/alpha/lsp/attach.lua index 6fc415c..a6d5257 100644 --- a/lua/alpha/lsp/attach.lua +++ b/lua/alpha/lsp/attach.lua @@ -56,6 +56,7 @@ local filetype_attach = setmetatable({ return function() end end, }) + return function(client, bufnr) local filetype = vim.api.nvim_buf_get_option(0, "filetype") -- keymaps for lsp diff --git a/lua/alpha/lsp/default.lua b/lua/alpha/lsp/default.lua new file mode 100644 index 0000000..a1b1e25 --- /dev/null +++ b/lua/alpha/lsp/default.lua @@ -0,0 +1,26 @@ +return { + mason = { + enable = true, + auto_install = false, + }, + servers = { + emmet_ls = { enable = true }, + gopls = { enable = true }, + html = { enable = true }, + jsonls = { enable = true }, + lua_ls = { enable = true }, + nil_ls = { enable = true }, + phpactor = {enable = true }, + rust_analyzer = { enable = true }, + svelte = { enable = true }, + tailwindcss = { enable = true, filetypes = {"blade", "html", "svelte"} }, + tsserver = { enable = true }, + volar = { enable = true }, + }, + default_options = function (options) + return vim.tbl_deep_extend("force", { + on_attach = require"alpha.lsp.attach", + flags = require "alpha.lsp.flags", + }, options) + end, +} diff --git a/lua/alpha/lsp/flags.lua b/lua/alpha/lsp/flags.lua new file mode 100644 index 0000000..f70b467 --- /dev/null +++ b/lua/alpha/lsp/flags.lua @@ -0,0 +1,3 @@ +return { + debounce_text_changes = 150, +} diff --git a/lua/alpha/lsp/init.lua b/lua/alpha/lsp/init.lua index 03bd61d..0d4a85d 100644 --- a/lua/alpha/lsp/init.lua +++ b/lua/alpha/lsp/init.lua @@ -1,12 +1,62 @@ --- LSP configuration +return { + setup = function(ops) + ops = vim.tbl_deep_extend("force", require "alpha.lsp.default", ops) -local lspconfig = require "lspconfig" -local servers = require "alpha.lsp.servers" + local lspconfig = require "lspconfig" -for server, setup in pairs(servers) do - lspconfig[server].setup(setup()) -end + local mason_servers = {} + for server, options in pairs(ops.servers) do + if options.enable == true then + local ok, definition = pcall(require, "alpha.lsp.servers." .. server) + local server_options + if not ok then + server_options = ops.default_options(options) + else + server_options = definition(options) + end + lspconfig[server].setup(server_options) + table.insert(mason_servers, server) + end + end --- install servers and tools -require "alpha.lsp.mason" -require "alpha.lsp.null-ls" + -- Mason + if ops.mason.enable then + local mason_ops = {} + if ops.mason.auto_install == true then + mason_ops.ensure_installed = mason_servers + end + local mason_lspconfig = require "mason-lspconfig" + mason_lspconfig.setup(mason_ops) + end + + -- TODO: implement null ls with options + require "alpha.lsp.null-ls" + + local servers = {} + for server, options in pairs(ops.servers) do + table.insert(servers, string.format("%s <%s>", server, options.enable)) + end + + vim.api.nvim_create_user_command("AlphaLSP", function() + vim.ui.select(servers, { prompt = "LSP Servers" }, function(server) + if server == nil then + return + end + + server = string.match(server, "^(.+) <") + local path = string.format("%s/lua/alpha/lsp/servers/%s.lua", vim.fn.stdpath "config", server) + if vim.fn.filereadable(path) == 0 then + local create = vim.fn.confirm("Server Does Not exist. Create new server?", "&Yes\n&No\n&Cancel") + if create ~= 1 then + return + end + end + + local uri = vim.uri_from_fname(path) + local buffer = vim.uri_to_bufnr(uri) + + vim.api.nvim_win_set_buf(0, buffer) + end) + end, {}) + end, +} diff --git a/lua/alpha/lsp/servers.lua b/lua/alpha/lsp/servers.lua deleted file mode 100644 index e9acc4b..0000000 --- a/lua/alpha/lsp/servers.lua +++ /dev/null @@ -1,173 +0,0 @@ -local lsp_attach = require "alpha.lsp.attach" - -local lsp_flags = { - debounce_text_changes = 150, -} - -local default = function() - return { - on_attach = lsp_attach, - flags = lsp_flags, - } -end - -return { - ["emmet_ls"] = function() - local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) - - return { - on_attach = lsp_attach, - flags = lsp_flags, - capabilities = capabilities, - filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "blade", "vue" }, - } - end, - ["gopls"] = function() - return { - on_attach = lsp_attach, - flags = lsp_flags, - } - end, - ["html"] = function() - local config = { - on_attach = lsp_attach, - flags = lsp_flags, - } - if vim.fn.executable "html-languageserver" == 1 then - config.cmd = { "html-languageserver", "--stdio" } - end - - return config - end, - ["jsonls"] = function() - local config = { - on_attach = lsp_attach, - flags = lsp_flags, - } - if vim.fn.executable "json-languageserver" == 1 then - config.cmd = { "json-languageserver", "--stdio" } - end - - return config - end, - ["lua_ls"] = function() - return { - on_attach = lsp_attach, - flags = lsp_flags, - settings = { - Lua = { - runtime = { - version = "LuaJIT", - }, - diagnostics = { - globals = { "vim" }, - }, - workspace = { - library = vim.api.nvim_get_runtime_file("", true), - checkThirdParty = false, - }, - telemetry = { - enable = false, - }, - hint = { - enable = true, - }, - }, - }, - } - end, - ["omnisharp"] = function() - return { - cmd = { "OmniSharp" }, - on_attach = lsp_attach, - flags = lsp_flags, - } - end, - ["nil_ls"] = default, - ["phpactor"] = function() - return { - on_attach = lsp_attach, - flags = lsp_flags, - filetypes = { "php" }, - init_options = { - ["language_server_worse_reflection.inlay_hints.enable"] = true, - ["language_server_worse_reflection.inlay_hints.params"] = true, - -- ["language_server_worse_reflection.inlay_hints.types"] = true, - ["language_server_configuration.auto_config"] = false, - ["code_transform.import_globals"] = true, - ["language_server_phpstan.enabled"] = true, - ["language_server_phpstan.level"] = 7, - ["language_server_phpstan.bin"] = "phpstan", - }, - handlers = { - ["textDocument/inlayHint"] = function(err, result, ...) - for _, res in ipairs(result) do - res.label = res.label .. ": " - end - vim.lsp.handlers["textDocument/inlayHint"](err, result, ...) - end, - }, - } - end, - ["pyright"] = default, - ["rust_analyzer"] = function() - return { - on_attach = lsp_attach, - flags = lsp_flags, - settings = { - ["rust-analyzer"] = { - checkOnSave = { - allFeatures = true, - overrideCommand = { - "cargo", - "clippy", - "--workspace", - "--message-format=json", - "--all-targets", - "--all-features", - }, - }, - }, - }, - } - end, - ["svelte"] = default, - ["tailwindcss"] = function() - return { - on_attach = lsp_attach, - flags = lsp_flags, - filetypes = { "blade", "html", "svelte" }, - } - end, - ["tsserver"] = function() - return { - on_attach = lsp_attach, - flags = lsp_flags, - settings = { - typescript = { - inlayHints = { - includeInlayParameterNameHints = "all", - includeInlayParameterNameHintsWhenArgumentMatchesName = false, - includeInlayFunctionParameterTypeHints = true, - includeInlayVariableTypeHints = true, - includeInlayPropertyDeclarationTypeHints = true, - includeInlayFunctionLikeReturnTypeHints = true, - includeInlayEnumMemberValueHints = true, - }, - }, - javascript = { - inlayHints = { - includeInlayParameterNameHints = "all", - includeInlayParameterNameHintsWhenArgumentMatchesName = false, - includeInlayFunctionParameterTypeHints = true, - includeInlayVariableTypeHints = true, - includeInlayPropertyDeclarationTypeHints = true, - includeInlayFunctionLikeReturnTypeHints = true, - includeInlayEnumMemberValueHints = true, - }, - }, - }, - } - end, - ["volar"] = default, -} diff --git a/lua/alpha/lsp/servers/emmet_ls.lua b/lua/alpha/lsp/servers/emmet_ls.lua new file mode 100644 index 0000000..c4f1cb6 --- /dev/null +++ b/lua/alpha/lsp/servers/emmet_ls.lua @@ -0,0 +1,12 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + capabilities = capabilities, + filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "blade", "vue" }, + }, ops) +end diff --git a/lua/alpha/lsp/servers/html.lua b/lua/alpha/lsp/servers/html.lua new file mode 100644 index 0000000..7b8ef54 --- /dev/null +++ b/lua/alpha/lsp/servers/html.lua @@ -0,0 +1,14 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + local config = { + on_attach = lsp_attach, + flags = lsp_flags, + } + if vim.fn.executable "html-languageserver" == 1 then + config.cmd = { "html-languageserver", "--stdio" } + end + + return vim.tbl_extend("force", config, ops) +end diff --git a/lua/alpha/lsp/servers/jsonls.lua b/lua/alpha/lsp/servers/jsonls.lua new file mode 100644 index 0000000..9c731ab --- /dev/null +++ b/lua/alpha/lsp/servers/jsonls.lua @@ -0,0 +1,14 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + local config = { + on_attach = lsp_attach, + flags = lsp_flags, + } + if vim.fn.executable "json-languageserver" == 1 then + config.cmd = { "json-languageserver", "--stdio" } + end + + return vim.tbl_extend("force", config, ops) +end diff --git a/lua/alpha/lsp/servers/lua_ls.lua b/lua/alpha/lsp/servers/lua_ls.lua new file mode 100644 index 0000000..64f012c --- /dev/null +++ b/lua/alpha/lsp/servers/lua_ls.lua @@ -0,0 +1,29 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require("alpha.lsp.flags") + +return function(ops) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + Lua = { + runtime = { + version = "LuaJIT", + }, + diagnostics = { + globals = { "vim" }, + }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true), + checkThirdParty = false, + }, + telemetry = { + enable = false, + }, + hint = { + enable = true, + }, + }, + }, + }, ops) +end diff --git a/lua/alpha/lsp/servers/phpactor.lua b/lua/alpha/lsp/servers/phpactor.lua new file mode 100644 index 0000000..fd25568 --- /dev/null +++ b/lua/alpha/lsp/servers/phpactor.lua @@ -0,0 +1,28 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + filetypes = { "php", "blade" }, + init_options = { + ["language_server_worse_reflection.inlay_hints.enable"] = true, + ["language_server_worse_reflection.inlay_hints.params"] = true, + -- ["language_server_worse_reflection.inlay_hints.types"] = true, + ["language_server_configuration.auto_config"] = false, + ["code_transform.import_globals"] = true, + ["language_server_phpstan.enabled"] = true, + ["language_server_phpstan.level"] = 7, + ["language_server_phpstan.bin"] = "phpstan", + }, + handlers = { + ["textDocument/inlayHint"] = function(err, result, ...) + for _, res in ipairs(result) do + res.label = res.label .. ": " + end + vim.lsp.handlers["textDocument/inlayHint"](err, result, ...) + end, + }, + }, ops) +end diff --git a/lua/alpha/lsp/servers/rust_analyzer.lua b/lua/alpha/lsp/servers/rust_analyzer.lua new file mode 100644 index 0000000..c0db321 --- /dev/null +++ b/lua/alpha/lsp/servers/rust_analyzer.lua @@ -0,0 +1,24 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + ["rust-analyzer"] = { + checkOnSave = { + allFeatures = true, + overrideCommand = { + "cargo", + "clippy", + "--workspace", + "--message-format=json", + "--all-targets", + "--all-features", + }, + }, + }, + }, + }, ops) +end diff --git a/lua/alpha/lsp/servers/tsserver.lua b/lua/alpha/lsp/servers/tsserver.lua new file mode 100644 index 0000000..e27d94a --- /dev/null +++ b/lua/alpha/lsp/servers/tsserver.lua @@ -0,0 +1,33 @@ +local lsp_attach = require "alpha.lsp.attach" +local lsp_flags = require "alpha.lsp.flags" + +return function(ops) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + typescript = { + inlayHints = { + includeInlayParameterNameHints = "all", + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, + }, + javascript = { + inlayHints = { + includeInlayParameterNameHints = "all", + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, + }, + }, + }, ops) +end diff --git a/lua/alpha/telescope/init.lua b/lua/alpha/telescope/init.lua index c67b074..c4daf6c 100644 --- a/lua/alpha/telescope/init.lua +++ b/lua/alpha/telescope/init.lua @@ -137,10 +137,6 @@ function M.refactor() return require("telescope").extensions.refactoring.refactors() end -function M.file_browser_relative() - return M.file_browser { path = "%:p:h" } -end - function M.gateway() return require("alpha.php.gateway").graphql_definitions { layout_config = { @@ -153,6 +149,10 @@ function M.gateway() } end +function M.file_browser_relative() + return M.file_browser { path = "%:p:h" } +end + function M.file_browser(opts) opts = opts or {} |