added some new nvim related files
This commit is contained in:
parent
731917422d
commit
59a3d274c7
117
.config/nvim/lua/user/functions.lua
Normal file
117
.config/nvim/lua/user/functions.lua
Normal file
@ -0,0 +1,117 @@
|
||||
local M = {}
|
||||
|
||||
vim.cmd [[
|
||||
function Test()
|
||||
%SnipRun
|
||||
call feedkeys("\<esc>`.")
|
||||
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 "<cword>"
|
||||
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
|
||||
50
.config/nvim/lua/user/lsp-inlayhints.lua
Normal file
50
.config/nvim/lua/user/lsp-inlayhints.lua
Normal file
@ -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,
|
||||
}
|
||||
165
.config/nvim/lua/user/lsp/handlers.lua
Normal file
165
.config/nvim/lua/user/lsp/handlers.lua
Normal file
@ -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", "<cmd>Telescope lsp_definitions<CR>", opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "<cmd>Telescope lsp_declarations<CR>", opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "gI", "<cmd>Telescope lsp_implementations<CR>", opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "<cmd>Telescope lsp_references<CR>", opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "gl", "<cmd>lua vim.diagnostic.open_float()<CR>", opts)
|
||||
vim.cmd [[ command! Format execute 'lua vim.lsp.buf.format({ async = true })' ]]
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "gs", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "<M-f>", "<cmd>Format<cr>", opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "<M-a>", "<cmd>lua vim.lsp.buf.code_action()<cr>", opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "<M-s>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>f", "<cmd>lua vim.diagnostic.open_float()<CR>", opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", '<cmd>lua vim.diagnostic.goto_prev({ border = "rounded" })<CR>', opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", '<cmd>lua vim.diagnostic.goto_next({ border = "rounded" })<CR>', opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>q", "<cmd>lua vim.diagnostic.setloclist()<CR>", 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
|
||||
40
.config/nvim/lua/user/lsp/init.lua
Normal file
40
.config/nvim/lua/user/lsp/init.lua
Normal file
@ -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
|
||||
59
.config/nvim/lua/user/lsp/lsp-signature.lua
Normal file
59
.config/nvim/lua/user/lsp/lsp-signature.lua
Normal file
@ -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 = '<M-x>'
|
||||
}
|
||||
|
||||
-- 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
|
||||
145
.config/nvim/lua/user/lsp/mason.lua
Normal file
145
.config/nvim/lua/user/lsp/mason.lua
Normal file
@ -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 {}
|
||||
57
.config/nvim/lua/user/lsp/null-ls.lua
Normal file
57
.config/nvim/lua/user/lsp/null-ls.lua
Normal file
@ -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)
|
||||
25
.config/nvim/lua/user/lsp/settings/emmet_ls.lua
Normal file
25
.config/nvim/lua/user/lsp/settings/emmet_ls.lua
Normal file
@ -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",
|
||||
},
|
||||
}
|
||||
24
.config/nvim/lua/user/lsp/settings/jsonls.lua
Normal file
24
.config/nvim/lua/user/lsp/settings/jsonls.lua
Normal file
@ -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,
|
||||
-- },
|
||||
},
|
||||
},
|
||||
}
|
||||
15
.config/nvim/lua/user/lsp/settings/pyright.lua
Normal file
15
.config/nvim/lua/user/lsp/settings/pyright.lua
Normal file
@ -0,0 +1,15 @@
|
||||
return {
|
||||
cmd = { "py" },
|
||||
settings = {
|
||||
python = {
|
||||
analysis = {
|
||||
typeCheckingMode = "basic",
|
||||
diagnosticMode = "workspace",
|
||||
inlayHints = {
|
||||
variableTypes = true,
|
||||
functionReturnTypes = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
126
.config/nvim/lua/user/lsp/settings/rust.lua
Normal file
126
.config/nvim/lua/user/lsp/settings/rust.lua
Normal file
@ -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,
|
||||
-- },
|
||||
-- },
|
||||
-- },
|
||||
-- }
|
||||
4
.config/nvim/lua/user/lsp/settings/solang.lua
Normal file
4
.config/nvim/lua/user/lsp/settings/solang.lua
Normal file
@ -0,0 +1,4 @@
|
||||
-- targets can be one of ewasm, generic, sabre, solana, substrate
|
||||
return {
|
||||
cmd = { "solang", "--language-server", "--target", "ewasm", "--importpath", "node_modules/" },
|
||||
}
|
||||
5
.config/nvim/lua/user/lsp/settings/solc.lua
Normal file
5
.config/nvim/lua/user/lsp/settings/solc.lua
Normal file
@ -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" },
|
||||
}
|
||||
43
.config/nvim/lua/user/lsp/settings/sumneko_lua.lua
Normal file
43
.config/nvim/lua/user/lsp/settings/sumneko_lua.lua
Normal file
@ -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,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
15
.config/nvim/lua/user/lsp/settings/tsserver.lua
Normal file
15
.config/nvim/lua/user/lsp/settings/tsserver.lua
Normal file
@ -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,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
8
.config/nvim/lua/user/lsp/settings/yamlls.lua
Normal file
8
.config/nvim/lua/user/lsp/settings/yamlls.lua
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
return {
|
||||
yaml = {
|
||||
schemaStore = {
|
||||
enable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
5
.config/nvim/lua/user/lsp/settings/zk.lua
Normal file
5
.config/nvim/lua/user/lsp/settings/zk.lua
Normal file
@ -0,0 +1,5 @@
|
||||
local util = require "lspconfig.util"
|
||||
|
||||
return {
|
||||
root_dir = util.root_pattern { ".git", ".zk" },
|
||||
}
|
||||
165
.config/nvim/lua/user/winbar.lua
Normal file
165
.config/nvim/lua/user/winbar.lua
Normal file
@ -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
|
||||
Loading…
Reference in New Issue
Block a user