From 59a3d274c7634180765e6de2aa9c6dd36db2a8c0 Mon Sep 17 00:00:00 2001 From: Solomon Laing Date: Fri, 19 Aug 2022 18:31:18 +0930 Subject: [PATCH] added some new nvim related files --- .config/nvim/lua/user/functions.lua | 117 +++++++++++++ .config/nvim/lua/user/lsp-inlayhints.lua | 50 ++++++ .config/nvim/lua/user/lsp/handlers.lua | 165 ++++++++++++++++++ .config/nvim/lua/user/lsp/init.lua | 40 +++++ .config/nvim/lua/user/lsp/lsp-signature.lua | 59 +++++++ .config/nvim/lua/user/lsp/mason.lua | 145 +++++++++++++++ .config/nvim/lua/user/lsp/null-ls.lua | 57 ++++++ .../nvim/lua/user/lsp/settings/emmet_ls.lua | 25 +++ .config/nvim/lua/user/lsp/settings/jsonls.lua | 24 +++ .../nvim/lua/user/lsp/settings/pyright.lua | 15 ++ .config/nvim/lua/user/lsp/settings/rust.lua | 126 +++++++++++++ .config/nvim/lua/user/lsp/settings/solang.lua | 4 + .config/nvim/lua/user/lsp/settings/solc.lua | 5 + .../lua/user/lsp/settings/sumneko_lua.lua | 43 +++++ .../nvim/lua/user/lsp/settings/tsserver.lua | 15 ++ .config/nvim/lua/user/lsp/settings/yamlls.lua | 8 + .config/nvim/lua/user/lsp/settings/zk.lua | 5 + .config/nvim/lua/user/winbar.lua | 165 ++++++++++++++++++ 18 files changed, 1068 insertions(+) create mode 100644 .config/nvim/lua/user/functions.lua create mode 100644 .config/nvim/lua/user/lsp-inlayhints.lua create mode 100644 .config/nvim/lua/user/lsp/handlers.lua create mode 100644 .config/nvim/lua/user/lsp/init.lua create mode 100644 .config/nvim/lua/user/lsp/lsp-signature.lua create mode 100644 .config/nvim/lua/user/lsp/mason.lua create mode 100644 .config/nvim/lua/user/lsp/null-ls.lua create mode 100644 .config/nvim/lua/user/lsp/settings/emmet_ls.lua create mode 100644 .config/nvim/lua/user/lsp/settings/jsonls.lua create mode 100644 .config/nvim/lua/user/lsp/settings/pyright.lua create mode 100644 .config/nvim/lua/user/lsp/settings/rust.lua create mode 100644 .config/nvim/lua/user/lsp/settings/solang.lua create mode 100644 .config/nvim/lua/user/lsp/settings/solc.lua create mode 100644 .config/nvim/lua/user/lsp/settings/sumneko_lua.lua create mode 100644 .config/nvim/lua/user/lsp/settings/tsserver.lua create mode 100644 .config/nvim/lua/user/lsp/settings/yamlls.lua create mode 100644 .config/nvim/lua/user/lsp/settings/zk.lua create mode 100644 .config/nvim/lua/user/winbar.lua diff --git a/.config/nvim/lua/user/functions.lua b/.config/nvim/lua/user/functions.lua new file mode 100644 index 0000000..8785ee9 --- /dev/null +++ b/.config/nvim/lua/user/functions.lua @@ -0,0 +1,117 @@ +local M = {} + +vim.cmd [[ + function Test() + %SnipRun + call feedkeys("\`.") + endfunction + function TestI() + let b:caret = winsaveview() + %SnipRun + call winrestview(b:caret) + endfunction +]] + +function M.sniprun_enable() + vim.cmd [[ + %SnipRun + augroup _sniprun + autocmd! + autocmd TextChanged * call Test() + autocmd TextChangedI * call TestI() + augroup end + ]] + vim.notify "Enabled SnipRun" +end + +function M.disable_sniprun() + M.remove_augroup "_sniprun" + vim.cmd [[ + SnipClose + SnipTerminate + ]] + vim.notify "Disabled SnipRun" +end + +function M.toggle_sniprun() + if vim.fn.exists "#_sniprun#TextChanged" == 0 then + M.sniprun_enable() + else + M.disable_sniprun() + end +end + +function M.remove_augroup(name) + if vim.fn.exists("#" .. name) == 1 then + vim.cmd("au! " .. name) + end +end + +vim.cmd [[ command! SnipRunToggle execute 'lua require("user.functions").toggle_sniprun()' ]] + +-- get length of current word +function M.get_word_length() + local word = vim.fn.expand "" + return #word +end + +function M.toggle_option(option) + local value = not vim.api.nvim_get_option_value(option, {}) + vim.opt[option] = value + vim.notify(option .. " set to " .. tostring(value)) +end + +function M.toggle_tabline() + local value = vim.api.nvim_get_option_value("showtabline", {}) + + if value == 2 then + value = 0 + else + value = 2 + end + + vim.opt.showtabline = value + + vim.notify("showtabline" .. " set to " .. tostring(value)) +end + +local diagnostics_active = true +function M.toggle_diagnostics() + diagnostics_active = not diagnostics_active + if diagnostics_active then + vim.diagnostic.show() + else + vim.diagnostic.hide() + end +end + +function M.isempty(s) + return s == nil or s == "" +end + +function M.get_buf_option(opt) + local status_ok, buf_option = pcall(vim.api.nvim_buf_get_option, 0, opt) + if not status_ok then + return nil + else + return buf_option + end +end + +function M.smart_quit() + local bufnr = vim.api.nvim_get_current_buf() + local modified = vim.api.nvim_buf_get_option(bufnr, "modified") + if modified then + vim.ui.input({ + prompt = "You have unsaved changes. Quit anyway? (y/n) ", + }, function(input) + if input == "y" then + vim.cmd "q!" + end + end) + else + vim.cmd "q!" + end +end + +return M diff --git a/.config/nvim/lua/user/lsp-inlayhints.lua b/.config/nvim/lua/user/lsp-inlayhints.lua new file mode 100644 index 0000000..f506014 --- /dev/null +++ b/.config/nvim/lua/user/lsp-inlayhints.lua @@ -0,0 +1,50 @@ +local status_ok, hints = pcall(require, "lsp-inlayhints") +if not status_ok then + return +end + +local group = vim.api.nvim_create_augroup("LspAttach_inlayhints", {}) +-- Busted and not sure why. +--vim.api.nvim_create_autocmd("LspAttach", { +-- group = "LspAttach_inlayhints", +-- callback = function(args) +-- if not (args.data and args.data.client_id) then +-- return +-- end +-- +-- local client = vim.lsp.get_client_by_id(args.data.client_id) +-- require("lsp-inlayhints").on_attach(args.buf, client) +-- end, +--}) + +hints.setup { + inlay_hints = { + parameter_hints = { + show = false, + -- prefix = "<- ", + separator = ", ", + }, + type_hints = { + -- type and other hints + show = true, + prefix = "", + separator = ", ", + remove_colon_end = false, + remove_colon_start = false, + }, + -- separator between types and parameter hints. Note that type hints are + -- shown before parameter + labels_separator = " ", + -- whether to align to the length of the longest line in the file + max_len_align = false, + -- padding from the left if max_len_align is true + max_len_align_padding = 1, + -- whether to align to the extreme right or not + right_align = false, + -- padding from the right if right_align is true + right_align_padding = 7, + -- highlight group + highlight = "Comment", + }, + debug_mode = false, +} diff --git a/.config/nvim/lua/user/lsp/handlers.lua b/.config/nvim/lua/user/lsp/handlers.lua new file mode 100644 index 0000000..762ef04 --- /dev/null +++ b/.config/nvim/lua/user/lsp/handlers.lua @@ -0,0 +1,165 @@ +local M = {} + +M.capabilities = vim.lsp.protocol.make_client_capabilities() + +local status_cmp_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") +if not status_cmp_ok then + return +end +M.capabilities.textDocument.completion.completionItem.snippetSupport = true +M.capabilities = cmp_nvim_lsp.update_capabilities(M.capabilities) + +M.setup = function() + local icons = require "user.icons" + local signs = { + + { name = "DiagnosticSignError", text = icons.diagnostics.Error }, + { name = "DiagnosticSignWarn", text = icons.diagnostics.Warning }, + { name = "DiagnosticSignHint", text = icons.diagnostics.Hint }, + { name = "DiagnosticSignInfo", text = icons.diagnostics.Information }, + } + + for _, sign in ipairs(signs) do + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) + end + + local config = { + -- disable virtual text + virtual_lines = false, + virtual_text = false, + -- virtual_text = { + -- -- spacing = 7, + -- -- update_in_insert = false, + -- -- severity_sort = true, + -- -- prefix = "<-", + -- prefix = " ●", + -- source = "if_many", -- Or "always" + -- -- format = function(diag) + -- -- return diag.message .. "blah" + -- -- end, + -- }, + + -- show signs + signs = { + active = signs, + }, + update_in_insert = true, + underline = true, + severity_sort = true, + float = { + focusable = true, + style = "minimal", + border = "rounded", + -- border = {"▄","▄","▄","█","▀","▀","▀","█"}, + source = "if_many", -- Or "always" + header = "", + prefix = "", + -- width = 40, + }, + } + + vim.diagnostic.config(config) + + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { + border = "rounded", + -- width = 60, + -- height = 30, + }) + + vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { + border = "rounded", + -- width = 60, + -- height = 30, + }) +end + +local function lsp_highlight_document(client) + -- if client.server_capabilities.document_highlight then + local status_ok, illuminate = pcall(require, "illuminate") + if not status_ok then + return + end + illuminate.on_attach(client) + -- end +end + +local function attach_navic(client, bufnr) + vim.g.navic_silence = true + local status_ok, navic = pcall(require, "nvim-navic") + if not status_ok then + return + end + navic.attach(client, bufnr) +end + +local function lsp_keymaps(bufnr) + local opts = { noremap = true, silent = true } + vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "Telescope lsp_definitions", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "Telescope lsp_declarations", 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", "Telescope lsp_implementations", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "Telescope lsp_references", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gl", "lua vim.diagnostic.open_float()", opts) + vim.cmd [[ command! Format execute 'lua vim.lsp.buf.format({ async = true })' ]] + vim.api.nvim_buf_set_keymap(bufnr, "n", "gs", "lua vim.lsp.buf.signature_help()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "", "Format", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "", "lua vim.lsp.buf.code_action()", opts) + -- vim.api.nvim_buf_set_keymap(bufnr, "n", "", "lua vim.lsp.buf.signature_help()", 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", "f", "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", "q", "lua vim.diagnostic.setloclist()", opts) +end + +M.on_attach = function(client, bufnr) + lsp_keymaps(bufnr) + lsp_highlight_document(client) + attach_navic(client, bufnr) + + if client.name == "tsserver" then + require("lsp-inlayhints").on_attach(bufnr, client) + end + + if client.name == "jdt.ls" then + vim.lsp.codelens.refresh() + if JAVA_DAP_ACTIVE then + require("jdtls").setup_dap { hotcodereplace = "auto" } + require("jdtls.dap").setup_dap_main_class_configs() + end + end +end + +function M.enable_format_on_save() + vim.cmd [[ + augroup format_on_save + autocmd! + autocmd BufWritePre * lua vim.lsp.buf.format({ async = false }) + augroup end + ]] + vim.notify "Enabled format on save" +end + +function M.disable_format_on_save() + M.remove_augroup "format_on_save" + vim.notify "Disabled format on save" +end + +function M.toggle_format_on_save() + if vim.fn.exists "#format_on_save#BufWritePre" == 0 then + M.enable_format_on_save() + else + M.disable_format_on_save() + end +end + +function M.remove_augroup(name) + if vim.fn.exists("#" .. name) == 1 then + vim.cmd("au! " .. name) + end +end + +vim.cmd [[ command! LspToggleAutoFormat execute 'lua require("user.lsp.handlers").toggle_format_on_save()' ]] + +return M diff --git a/.config/nvim/lua/user/lsp/init.lua b/.config/nvim/lua/user/lsp/init.lua new file mode 100644 index 0000000..e919e76 --- /dev/null +++ b/.config/nvim/lua/user/lsp/init.lua @@ -0,0 +1,40 @@ +M = {} +local status_ok, _ = pcall(require, "lspconfig") +if not status_ok then + return +end + +M.server_capabilities = function() + local active_clients = vim.lsp.get_active_clients() + local active_client_map = {} + + for index, value in ipairs(active_clients) do + active_client_map[value.name] = index + end + + vim.ui.select(vim.tbl_keys(active_client_map), { + prompt = "Select client:", + format_item = function(item) + return "capabilites for: " .. item + end, + }, function(choice) + -- print(active_client_map[choice]) + print(vim.inspect(vim.lsp.get_active_clients()[active_client_map[choice]].server_capabilities.executeCommandProvider)) + vim.pretty_print(vim.lsp.get_active_clients()[active_client_map[choice]].server_capabilities) + end) +end + +require "user.lsp.lsp-signature" +-- require "user.lsp.lsp-installer" +require("user.lsp.mason") +require("user.lsp.handlers").setup() +require "user.lsp.null-ls" + +local l_status_ok, lsp_lines = pcall(require, "lsp_lines") +if not l_status_ok then + return +end + +lsp_lines.setup() + +return M diff --git a/.config/nvim/lua/user/lsp/lsp-signature.lua b/.config/nvim/lua/user/lsp/lsp-signature.lua new file mode 100644 index 0000000..a6d1e9c --- /dev/null +++ b/.config/nvim/lua/user/lsp/lsp-signature.lua @@ -0,0 +1,59 @@ +local status_ok, signature = pcall(require, "lsp_signature") +if not status_ok then + return +end + +local icons = require "user.icons" + +local cfg = { + debug = false, -- set to true to enable debug logging + log_path = "debug_log_file_path", -- debug log path + verbose = false, -- show debug line number + + bind = true, -- This is mandatory, otherwise border config won't get registered. + -- If you want to hook lspsaga or other signature handler, pls set to false + doc_lines = 0, -- will show two lines of comment/doc(if there are more than two lines in doc, will be truncated); + -- set to 0 if you DO NOT want any API comments be shown + -- This setting only take effect in insert mode, it does not affect signature help in normal + -- mode, 10 by default + + floating_window = false, -- show hint in a floating window, set to false for virtual text only mode + + floating_window_above_cur_line = false, -- try to place the floating above the current line when possible Note: + -- will set to true when fully tested, set to false will use whichever side has more space + -- this setting will be helpful if you do not want the PUM and floating win overlap + fix_pos = false, -- set to true, the floating window will not auto-close until finish all parameters + hint_enable = true, -- virtual hint enable + hint_prefix = icons.misc.Squirrel .. " ", -- Panda for parameter + hint_scheme = "Comment", + use_lspsaga = false, -- set to true if you want to use lspsaga popup + hi_parameter = "LspSignatureActiveParameter", -- how your parameter will be highlight + max_height = 12, -- max height of signature floating_window, if content is more than max_height, you can scroll down + -- to view the hiding contents + max_width = 120, -- max_width of signature floating_window, line will be wrapped if exceed max_width + handler_opts = { + border = "rounded", -- double, rounded, single, shadow, none + }, + + always_trigger = false, -- sometime show signature on new line or in middle of parameter can be confusing, set it to false for #58 + + auto_close_after = nil, -- autoclose signature float win after x sec, disabled if nil. + extra_trigger_chars = {}, -- Array of extra characters that will trigger signature completion, e.g., {"(", ","} + zindex = 200, -- by default it will be on top of all floating windows, set to <= 50 send it to bottom + + padding = "", -- character to pad on left and right of signature can be ' ', or '|' etc + + transparency = nil, -- disabled by default, allow floating win transparent value 1~100 + shadow_blend = 36, -- if you using shadow as border use this set the opacity + shadow_guibg = "Black", -- if you using shadow as border use this set the color e.g. 'Green' or '#121315' + timer_interval = 200, -- default timer check interval set to lower value if you want to reduce latency + toggle_key = nil, -- toggle signature on and off in insert mode, e.g. toggle_key = '' +} + +-- recommanded: +signature.setup(cfg) -- no need to specify bufnr if you don't use toggle_key + +-- You can also do this inside lsp on_attach +-- note: on_attach deprecated +-- require("lsp_signature").on_attach(cfg, bufnr) -- no need to specify bufnr if you don't use toggle_key +signature.on_attach(cfg) -- no need to specify bufnr if you don't use toggle_key diff --git a/.config/nvim/lua/user/lsp/mason.lua b/.config/nvim/lua/user/lsp/mason.lua new file mode 100644 index 0000000..3e6dc4c --- /dev/null +++ b/.config/nvim/lua/user/lsp/mason.lua @@ -0,0 +1,145 @@ +local status_ok, mason = pcall(require, "mason") +if not status_ok then + return +end + +local status_ok_1, mason_lspconfig = pcall(require, "mason-lspconfig") +if not status_ok_1 then + return +end + +local servers = { + "cssls", + "cssmodules_ls", + "emmet_ls", + "html", + "jdtls", + "jsonls", + "solc", + "solidity_ls", + "sumneko_lua", + "tflint", + "terraformls", + "tsserver", + "pyright", + "yamlls", + "bashls", + "clangd", + "rust_analyzer", + "taplo", + "zk@v0.10.1", + "lemminx" +} + +local settings = { + ui = { + border = "rounded", + icons = { + package_installed = "◍", + package_pending = "◍", + package_uninstalled = "◍", + }, + }, + log_level = vim.log.levels.INFO, + max_concurrent_installers = 4, +} + +mason.setup(settings) +mason_lspconfig.setup { + ensure_installed = servers, + automatic_installation = true, +} + +local lspconfig_status_ok, lspconfig = pcall(require, "lspconfig") +if not lspconfig_status_ok then + return +end + +local opts = {} + +for _, server in pairs(servers) do + opts = { + on_attach = require("user.lsp.handlers").on_attach, + capabilities = require("user.lsp.handlers").capabilities, + } + + server = vim.split(server, "@")[1] + + if server == "jsonls" then + local jsonls_opts = require "user.lsp.settings.jsonls" + opts = vim.tbl_deep_extend("force", jsonls_opts, opts) + end + + if server == "yamlls" then + local yamlls_opts = require "user.lsp.settings.yamlls" + opts = vim.tbl_deep_extend("force", yamlls_opts, opts) + end + + if server == "sumneko_lua" then + local l_status_ok, lua_dev = pcall(require, "lua-dev") + if not l_status_ok then + return + end + -- local sumneko_opts = require "user.lsp.settings.sumneko_lua" + -- opts = vim.tbl_deep_extend("force", sumneko_opts, opts) + -- opts = vim.tbl_deep_extend("force", require("lua-dev").setup(), opts) + local luadev = lua_dev.setup { + -- -- add any options here, or leave empty to use the default settings + -- lspconfig = opts, + lspconfig = { + on_attach = opts.on_attach, + capabilities = opts.capabilities, + -- -- settings = opts.settings, + }, + } + lspconfig.sumneko_lua.setup(luadev) + goto continue + end + + if server == "tsserver" then + local tsserver_opts = require "user.lsp.settings.tsserver" + opts = vim.tbl_deep_extend("force", tsserver_opts, opts) + end + + if server == "pyright" then + local pyright_opts = require "user.lsp.settings.pyright" + opts = vim.tbl_deep_extend("force", pyright_opts, opts) + end + + if server == "solc" then + local solc_opts = require "user.lsp.settings.solc" + opts = vim.tbl_deep_extend("force", solc_opts, opts) + end + + if server == "emmet_ls" then + local emmet_ls_opts = require "user.lsp.settings.emmet_ls" + opts = vim.tbl_deep_extend("force", emmet_ls_opts, opts) + end + + if server == "zk" then + local zk_opts = require "user.lsp.settings.zk" + opts = vim.tbl_deep_extend("force", zk_opts, opts) + end + + if server == "jdtls" then + goto continue + end + + if server == "rust_analyzer" then + local rust_opts = require "user.lsp.settings.rust" + -- opts = vim.tbl_deep_extend("force", rust_opts, opts) + local rust_tools_status_ok, rust_tools = pcall(require, "rust-tools") + if not rust_tools_status_ok then + return + end + + rust_tools.setup(rust_opts) + goto continue + end + + lspconfig[server].setup(opts) + ::continue:: +end + +-- TODO: add something to installer later +-- require("lspconfig").motoko.setup {} diff --git a/.config/nvim/lua/user/lsp/null-ls.lua b/.config/nvim/lua/user/lsp/null-ls.lua new file mode 100644 index 0000000..84de120 --- /dev/null +++ b/.config/nvim/lua/user/lsp/null-ls.lua @@ -0,0 +1,57 @@ +local null_ls_status_ok, null_ls = pcall(require, "null-ls") +if not null_ls_status_ok then + return +end + +-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting +local formatting = null_ls.builtins.formatting +-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics +local diagnostics = null_ls.builtins.diagnostics + +-- https://github.com/prettier-solidity/prettier-plugin-solidity +-- npm install --save-dev prettier prettier-plugin-solidity +null_ls.setup { + debug = false, + sources = { + formatting.prettier.with { + extra_filetypes = { "toml", "solidity" }, + extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" }, + }, + formatting.black.with { extra_args = { "--fast" } }, + formatting.stylua, + formatting.shfmt, + formatting.google_java_format, + -- diagnostics.flake8, + diagnostics.shellcheck, + }, +} + +local unwrap = { + method = null_ls.methods.DIAGNOSTICS, + filetypes = { "rust" }, + generator = { + fn = function(params) + local diagnostics = {} + -- sources have access to a params object + -- containing info about the current file and editor state + for i, line in ipairs(params.content) do + local col, end_col = line:find "unwrap()" + if col and end_col then + -- null-ls fills in undefined positions + -- and converts source diagnostics into the required format + table.insert(diagnostics, { + row = i, + col = col, + end_col = end_col, + source = "unwrap", + message = "hey " .. os.getenv("USER") .. ", don't forget to handle this" , + severity = 2, + }) + end + end + return diagnostics + end, + }, +} + +null_ls.register(unwrap) diff --git a/.config/nvim/lua/user/lsp/settings/emmet_ls.lua b/.config/nvim/lua/user/lsp/settings/emmet_ls.lua new file mode 100644 index 0000000..fac61ba --- /dev/null +++ b/.config/nvim/lua/user/lsp/settings/emmet_ls.lua @@ -0,0 +1,25 @@ +-- https://github.com/pedro757/emmet +-- npm i -g ls_emmet +return { + cmd = { "ls_emmet", "--stdio" }, + filetypes = { + "html", + "css", + "scss", + "javascript", + "javascriptreact", + "typescript", + "typescriptreact", + "haml", + "xml", + "xsl", + "pug", + "slim", + "sass", + "stylus", + "less", + "sss", + "hbs", + "handlebars", + }, +} diff --git a/.config/nvim/lua/user/lsp/settings/jsonls.lua b/.config/nvim/lua/user/lsp/settings/jsonls.lua new file mode 100644 index 0000000..8a096bb --- /dev/null +++ b/.config/nvim/lua/user/lsp/settings/jsonls.lua @@ -0,0 +1,24 @@ +local status_ok, schemastore = pcall(require, "schemastore") +if not status_ok then + return +end + +return { + init_options = { + provideFormatter = false, + }, + settings = { + json = { + schemas = schemastore.json.schemas(), + }, + }, + setup = { + commands = { + -- Format = { + -- function() + -- vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 }) + -- end, + -- }, + }, + }, +} diff --git a/.config/nvim/lua/user/lsp/settings/pyright.lua b/.config/nvim/lua/user/lsp/settings/pyright.lua new file mode 100644 index 0000000..ebb8886 --- /dev/null +++ b/.config/nvim/lua/user/lsp/settings/pyright.lua @@ -0,0 +1,15 @@ +return { + cmd = { "py" }, + settings = { + python = { + analysis = { + typeCheckingMode = "basic", + diagnosticMode = "workspace", + inlayHints = { + variableTypes = true, + functionReturnTypes = true, + }, + }, + }, + }, +} diff --git a/.config/nvim/lua/user/lsp/settings/rust.lua b/.config/nvim/lua/user/lsp/settings/rust.lua new file mode 100644 index 0000000..13f3305 --- /dev/null +++ b/.config/nvim/lua/user/lsp/settings/rust.lua @@ -0,0 +1,126 @@ +return { + tools = { + -- autoSetHints = false, + on_initialized = function() + vim.api.nvim_create_autocmd({ "BufWritePost", "BufEnter", "CursorHold", "InsertLeave" }, { + pattern = { "*.rs" }, + callback = function() + vim.lsp.codelens.refresh() + end, + }) + end, + + auto = false, + inlay_hints = { + -- Only show inlay hints for the current line + only_current_line = false, + auto = false, + + -- Event which triggers a refersh of the inlay hints. + -- You can make this "CursorMoved" or "CursorMoved,CursorMovedI" but + -- not that this may cause higher CPU usage. + -- This option is only respected when only_current_line and + -- autoSetHints both are true. + only_current_line_autocmd = "CursorHold", + + -- whether to show parameter hints with the inlay hints or not + -- default: true + show_parameter_hints = false, + + -- whether to show variable name before type hints with the inlay hints or not + -- default: false + show_variable_name = false, + + -- prefix for parameter hints + -- default: "<-" + -- parameter_hints_prefix = "<- ", + parameter_hints_prefix = " ", + + -- prefix for all the other hints (type, chaining) + -- default: "=>" + -- other_hints_prefix = "=> ", + other_hints_prefix = " ", + + -- whether to align to the lenght of the longest line in the file + max_len_align = false, + + -- padding from the left if max_len_align is true + max_len_align_padding = 1, + + -- whether to align to the extreme right or not + right_align = false, + + -- padding from the right if right_align is true + right_align_padding = 7, + + -- The color of the hints + highlight = "Comment", + }, + hover_actions = { + auto_focus = false, + border = "rounded", + width = 60, + -- height = 30, + }, + }, + server = { + --[[ + $ mkdir -p ~/.local/bin + $ curl -L https://github.com/rust-analyzer/rust-analyzer/releases/latest/download/rust-analyzer-x86_64-unknown-linux-gnu.gz | gunzip -c - > ~/.local/bin/rust-analyzer + $ chmod +x ~/.local/bin/rust-analyzer + --]] + -- cmd = { os.getenv "HOME" .. "/.local/bin/rust-analyzer" }, + cmd = { "rustup", "run", "nightly", os.getenv "HOME" .. "/.local/bin/rust-analyzer" }, + on_attach = require("user.lsp.handlers").on_attach, + capabilities = require("user.lsp.handlers").capabilities, + + settings = { + ["rust-analyzer"] = { + lens = { + enable = true, + }, + checkOnSave = { + command = "clippy", + }, + }, + }, + }, +} +-- return { +-- settings = { +-- rust_analyzer = { +-- inlayHints = { +-- bindingModeHints = { +-- enable = true, +-- }, +-- typeHints = { +-- enable = true, +-- hideClosureInitialization = false, +-- hideNamedConstructor = false, +-- }, +-- chainingHints = { +-- enable = true, +-- }, +-- closingBraceHints = { +-- enable = true, +-- minLines = 25, +-- }, +-- closureReturnTypeHints = { +-- enable = "never", +-- }, +-- lifetimeElisionHints = { +-- enable = "never", +-- useParameterNames = false, +-- maxLength = 25, +-- }, +-- parameterHints = { +-- enable = true, +-- }, +-- reborrowHints = { +-- enable = "never", +-- }, +-- renderColons = true, +-- }, +-- }, +-- }, +-- } diff --git a/.config/nvim/lua/user/lsp/settings/solang.lua b/.config/nvim/lua/user/lsp/settings/solang.lua new file mode 100644 index 0000000..5d60111 --- /dev/null +++ b/.config/nvim/lua/user/lsp/settings/solang.lua @@ -0,0 +1,4 @@ +-- targets can be one of ewasm, generic, sabre, solana, substrate +return { + cmd = { "solang", "--language-server", "--target", "ewasm", "--importpath", "node_modules/" }, +} diff --git a/.config/nvim/lua/user/lsp/settings/solc.lua b/.config/nvim/lua/user/lsp/settings/solc.lua new file mode 100644 index 0000000..d03d4f8 --- /dev/null +++ b/.config/nvim/lua/user/lsp/settings/solc.lua @@ -0,0 +1,5 @@ +-- targets can be one of ewasm, generic, sabre, solana, substrate +return { + -- cmd = { "solc", "--lsp", "--import-path", "node_modules" }, + cmd = { "solc", "--lsp", "--include-path", "../node_modules" }, +} diff --git a/.config/nvim/lua/user/lsp/settings/sumneko_lua.lua b/.config/nvim/lua/user/lsp/settings/sumneko_lua.lua new file mode 100644 index 0000000..1130c8a --- /dev/null +++ b/.config/nvim/lua/user/lsp/settings/sumneko_lua.lua @@ -0,0 +1,43 @@ +return { + settings = { + Lua = { + type = { + -- weakUnionCheck = true, + -- weakNilCheck = true, + -- castNumberToInteger = true, + }, + format = { + enable = false, + }, + hint = { + enable = true, + arrayIndex = "Disable", -- "Enable", "Auto", "Disable" + await = true, + paramName = "Disable", -- "All", "Literal", "Disable" + paramType = false, + semicolon = "Disable", -- "All", "SameLine", "Disable" + setType = true, + }, + -- spell = {"the"} + runtime = { + version = "LuaJIT", + special = { + reload = "require", + }, + }, + diagnostics = { + globals = { "vim" }, + }, + workspace = { + library = { + [vim.fn.expand "$VIMRUNTIME/lua"] = true, + [vim.fn.stdpath "config" .. "/lua"] = true, + -- [vim.fn.datapath "config" .. "/lua"] = true, + }, + }, + telemetry = { + enable = false, + }, + }, + }, +} diff --git a/.config/nvim/lua/user/lsp/settings/tsserver.lua b/.config/nvim/lua/user/lsp/settings/tsserver.lua new file mode 100644 index 0000000..e3ae6e8 --- /dev/null +++ b/.config/nvim/lua/user/lsp/settings/tsserver.lua @@ -0,0 +1,15 @@ +return { + settings = { + typescript = { + inlayHints = { + includeInlayEnumMemberValueHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayFunctionParameterTypeHints = true, + includeInlayParameterNameHints = "all", -- 'none' | 'literals' | 'all'; + includeInlayParameterNameHintsWhenArgumentMatchesName = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayVariableTypeHints = true, + }, + }, + }, +} diff --git a/.config/nvim/lua/user/lsp/settings/yamlls.lua b/.config/nvim/lua/user/lsp/settings/yamlls.lua new file mode 100644 index 0000000..5003f08 --- /dev/null +++ b/.config/nvim/lua/user/lsp/settings/yamlls.lua @@ -0,0 +1,8 @@ + +return { + yaml = { + schemaStore = { + enable = true + } + } +} diff --git a/.config/nvim/lua/user/lsp/settings/zk.lua b/.config/nvim/lua/user/lsp/settings/zk.lua new file mode 100644 index 0000000..12b4dac --- /dev/null +++ b/.config/nvim/lua/user/lsp/settings/zk.lua @@ -0,0 +1,5 @@ +local util = require "lspconfig.util" + +return { + root_dir = util.root_pattern { ".git", ".zk" }, +} diff --git a/.config/nvim/lua/user/winbar.lua b/.config/nvim/lua/user/winbar.lua new file mode 100644 index 0000000..3d760a7 --- /dev/null +++ b/.config/nvim/lua/user/winbar.lua @@ -0,0 +1,165 @@ +local M = {} + +M.winbar_filetype_exclude = { + "help", + "startify", + "dashboard", + "packer", + "neogitstatus", + "NvimTree", + "Trouble", + "alpha", + "lir", + "Outline", + "spectre_panel", + "toggleterm", + "DressingSelect", + "Jaq", + "harpoon", + "dapui_scopes", + "dapui_breakpoints", + "dapui_stacks", + "dapui_watches", + "dap-repl", + "dap-terminal", + "dapui_console", + "lab", + "Markdown", + "", +} + +M.get_filename = function() + local filename = vim.fn.expand "%:t" + local extension = vim.fn.expand "%:e" + local f = require "user.functions" + + if not f.isempty(filename) then + local file_icon, file_icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + + local hl_group = "FileIconColor" .. extension + + vim.api.nvim_set_hl(0, hl_group, { fg = file_icon_color }) + if f.isempty(file_icon) then + file_icon = "" + file_icon_color = "" + end + + -- local navic_text = vim.api.nvim_get_hl_by_name("NavicText", true) + -- vim.api.nvim_set_hl(0, "Winbar", { fg = navic_text.foreground }) + + return " " .. "%#" .. hl_group .. "#" .. file_icon .. "%*" .. " " .. "%#Winbar#" .. filename .. "%*" + end +end + +-- local get_gps = function() +-- local status_gps_ok, gps = pcall(require, "nvim-gps") +-- if not status_gps_ok then +-- return "" +-- end +-- +-- local status_ok, gps_location = pcall(gps.get_location, {}) +-- if not status_ok then +-- return "" +-- end +-- +-- if not gps.is_available() or gps_location == "error" then +-- return "" +-- end +-- +-- if not require("user.functions").isempty(gps_location) then +-- return require("user.icons").ui.ChevronRight .. " " .. gps_location +-- else +-- return "" +-- end +-- end + +local get_gps = function() + local status_gps_ok, gps = pcall(require, "nvim-navic") + if not status_gps_ok then + return "" + end + + local status_ok, gps_location = pcall(gps.get_location, {}) + if not status_ok then + return "" + end + + if not gps.is_available() or gps_location == "error" then + return "" + end + + if not require("user.functions").isempty(gps_location) then + return require("user.icons").ui.ChevronRight .. " " .. gps_location + else + return "" + end +end + +local excludes = function() + if vim.tbl_contains(M.winbar_filetype_exclude, vim.bo.filetype) then + vim.opt_local.winbar = nil + return true + end + return false +end + +M.get_winbar = function() + if excludes() then + return + end + local f = require "user.functions" + local value = M.get_filename() + + local gps_added = false + if not f.isempty(value) then + local gps_value = get_gps() + value = value .. " " .. gps_value + if not f.isempty(gps_value) then + gps_added = true + end + end + + if not f.isempty(value) and f.get_buf_option "mod" then + local mod = "%#LspCodeLens#" .. require("user.icons").ui.Circle .. "%*" + if gps_added then + value = value .. " " .. mod + else + value = value .. mod + end + end + + local num_tabs = #vim.api.nvim_list_tabpages() + + if num_tabs > 1 and not f.isempty(value) then + local tabpage_number = tostring(vim.api.nvim_tabpage_get_number(0)) + value = value .. "%=" .. tabpage_number .. "/" .. tostring(num_tabs) + end + + local status_ok, _ = pcall(vim.api.nvim_set_option_value, "winbar", value, { scope = "local" }) + if not status_ok then + return + end +end + +M.create_winbar = function() + vim.api.nvim_create_augroup("_winbar", {}) + if vim.fn.has "nvim-0.8" == 1 then + vim.api.nvim_create_autocmd( + { "CursorMoved", "CursorHold", "BufWinEnter", "BufFilePost", "InsertEnter", "BufWritePost", "TabClosed" }, + { + group = "_winbar", + callback = function() + local status_ok, _ = pcall(vim.api.nvim_buf_get_var, 0, "lsp_floating_window") + if not status_ok then + require("user.winbar").get_winbar() + end + end, + } + ) + end +end + +M.create_winbar() + +return M