diff --git a/lua/configs/lsp-installer.lua b/archive/lua/configs/lsp-installer.lua similarity index 92% rename from lua/configs/lsp-installer.lua rename to archive/lua/configs/lsp-installer.lua index 069dcde..b6c13aa 100644 --- a/lua/configs/lsp-installer.lua +++ b/archive/lua/configs/lsp-installer.lua @@ -1,5 +1,14 @@ local M = {} +-- From plugins.lua +-- LSP EZ Installer +-- use { +-- 'williamboman/nvim-lsp-installer', +-- after = { 'cmp-nvim-lsp', 'nvim-lspconfig' }, +-- event = 'BufRead', +-- config = function() require'configs.lsp-installer'.config() end +-- } + function M.config() local status_lsp_installer_ok, lsp_installer = pcall(require, "nvim-lsp-installer") if not status_lsp_installer_ok then diff --git a/lua/configs/lsp.lua b/lua/configs/lsp.lua deleted file mode 100644 index ebc33c5..0000000 --- a/lua/configs/lsp.lua +++ /dev/null @@ -1,48 +0,0 @@ -local M = {} - -function M.config() - local signs = { - { name = "DiagnosticSignError", text = "" }, - { name = "DiagnosticSignWarn", text = "" }, - { name = "DiagnosticSignHint", text = "" }, - { name = "DiagnosticSignInfo", text = "" }, - } - - for _, sign in ipairs(signs) do - vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) - end - - local config = { - virtual_text = false, - signs = { - active = signs, - }, - update_in_insert = true, - underline = true, - severity_sort = true, - float = { - focusable = false, - style = "minimal", - border = "rounded", - source = "always", - header = "", - prefix = "", - }, - } - - vim.diagnostic.config(config) - - vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { - border = "rounded", - }) - - vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { - border = "rounded", - }) - - vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - virtual_text = false, - }) -end - -return M diff --git a/lua/configs/lspconfig.lua b/lua/configs/lspconfig.lua new file mode 100644 index 0000000..4d1e956 --- /dev/null +++ b/lua/configs/lspconfig.lua @@ -0,0 +1,104 @@ +local M = {} + +function M.config() + local signs = { + { name = "DiagnosticSignError", text = "" }, + { name = "DiagnosticSignWarn", text = "" }, + { name = "DiagnosticSignHint", text = "" }, + { name = "DiagnosticSignInfo", text = "" }, + } + + for _, sign in ipairs(signs) do + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) + end + + local config = { + virtual_text = false, + signs = { + active = signs, + }, + update_in_insert = true, + underline = true, + severity_sort = true, + float = { + focusable = false, + style = "minimal", + border = "rounded", + source = "always", + header = "", + prefix = "", + }, + } + + vim.diagnostic.config(config) + + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { + border = "rounded", + }) + + vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { + border = "rounded", + }) + + vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + virtual_text = false, + }) + + local status_ok, lspconfig = pcall(require, "lspconfig") + if not status_ok then + return + end + + -- Highlight under current selection + local function lsp_highlight_document(client) + if client.resolved_capabilities.document_highlight then + vim.api.nvim_exec( + [[ + augroup lsp_document_highlight + autocmd! * + autocmd CursorHold lua vim.lsp.buf.document_highlight() + autocmd CursorMoved lua vim.lsp.buf.clear_references() + augroup END + ]], + false + ) + end + end + + local function lsp_keymaps(bufnr) + local opts = { noremap = true, silent = true } + vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gl", "lua vim.diagnostic.open_float({ source = false, prefix = function(d, i, ttl) return string.rep(' ', #tostring(ttl) - #tostring(i)) .. tostring(i) .. ': ', nil end })", opts) + 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", "gi", "lua vim.lsp.buf.implementation()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "go", "lua vim.diagnostic.open_float()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", 'lua vim.diagnostic.goto_prev({ border = "rounded" })', opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", 'lua vim.diagnostic.goto_next({ border = "rounded" })', opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "ll", "lua vim.diagnostic.setloclist()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "lf", "lua vim.lsp.buf.formatting_sync()", opts) + --vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]] + end + + local on_attach = function(client, bufnr) + lsp_keymaps(bufnr) + lsp_highlight_document(client) + end + + lspconfig.sumneko_lua.setup { + on_attach = on_attach, + settings = { + Lua = { + format = { + enable = false + }, + diagnostics = { + globals = { 'vim' }, + }, + } + } + } + +end + +return M diff --git a/lua/configs/mason-lspconfig.lua b/lua/configs/mason-lspconfig.lua new file mode 100644 index 0000000..94e2dec --- /dev/null +++ b/lua/configs/mason-lspconfig.lua @@ -0,0 +1,16 @@ +local M = {} + +function M.config() + local status_ok, mason_lspconfig = pcall(require, "mason-lspconfig") + if not status_ok then + return + end + + mason_lspconfig.setup({ + ensure_installed = { + }, + automatic_installation = false, + }) +end + +return M diff --git a/lua/configs/mason.lua b/lua/configs/mason.lua new file mode 100644 index 0000000..9eedada --- /dev/null +++ b/lua/configs/mason.lua @@ -0,0 +1,13 @@ +local M = {} + +function M.config() + local status_ok, mason = pcall(require, "mason") + if not status_ok then + return + end + + mason.setup {} + +end + +return M diff --git a/lua/configs/null-ls.lua b/lua/configs/null-ls.lua index 4df6010..14eeb9d 100644 --- a/lua/configs/null-ls.lua +++ b/lua/configs/null-ls.lua @@ -19,10 +19,11 @@ function M.config() sources = { -- Set a formatter formatting.prettierd, - --formatting.black, + --TODO: formatting.black, -- Set a linter diagnostics.eslint_d, + --TODO: pylint }, -- Format before save on_attach = function(client) diff --git a/lua/configs/nvim-tree.lua b/lua/configs/nvim-tree.lua index 6d5e596..806c613 100644 --- a/lua/configs/nvim-tree.lua +++ b/lua/configs/nvim-tree.lua @@ -16,8 +16,7 @@ function M.config() }, }, view = { - width = 30, - height = 30, + width = 40, side = "left", hide_root_folder = true, number = false, diff --git a/lua/plugins.lua b/lua/plugins.lua index 3d2e770..caa444a 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -89,25 +89,28 @@ packer.startup { -- LSP -- - -- -- Cursorhold fix + -- Cursorhold fix use { "antoinemadec/FixCursorHold.nvim", config = function() vim.g.cursorhold_updatetime = 300 end, } + -- LSP EZ Installer + -- :LspInstall + use { + 'williamboman/mason.nvim', + config = function() require'configs.mason'.config() end + } + use { + 'williamboman/mason-lspconfig', + config = function() require'configs.mason-lspconfig'.config() end + } + -- Built-In LSP Config use { 'neovim/nvim-lspconfig', event = 'BufRead', - config = function() require'configs.lsp'.config() end - } - - -- LSP EZ Installer - use { - 'williamboman/nvim-lsp-installer', - after = { 'cmp-nvim-lsp', 'nvim-lspconfig' }, - event = 'BufRead', - config = function() require'configs.lsp-installer'.config() end + config = function() require'configs.lspconfig'.config() end } -- Formatting + Linting