mirror of
https://github.com/ViViDboarder/vim-settings.git
synced 2024-12-22 13:07:36 +00:00
More switching over to v0.7 methods
This commit is contained in:
parent
92550be390
commit
f812c58597
@ -1,3 +1,9 @@
|
|||||||
|
-- TODO: Don't add these if it's already set
|
||||||
|
vim.cmd([[
|
||||||
|
:highlight link LspReferenceRead MatchParen
|
||||||
|
:highlight link LspReferenceText MatchParen
|
||||||
|
:highlight link LspReferenceWrite MatchParen
|
||||||
|
]])
|
||||||
-- Update colors based on environment variables
|
-- Update colors based on environment variables
|
||||||
function _G.update_colors()
|
function _G.update_colors()
|
||||||
local function maybe_set(scope, name, val, force)
|
local function maybe_set(scope, name, val, force)
|
||||||
@ -61,16 +67,11 @@ end
|
|||||||
-- Don't need the autocommand when dark-notify is installed
|
-- Don't need the autocommand when dark-notify is installed
|
||||||
local utils = require("utils")
|
local utils = require("utils")
|
||||||
if not utils.is_plugin_loaded("dark-notify") then
|
if not utils.is_plugin_loaded("dark-notify") then
|
||||||
-- TODO: remove check when dropping v0.6.0
|
vim.api.nvim_create_autocmd({ "FocusGained" }, {
|
||||||
if vim.fn.has("nvim-0.7.0") == 1 then
|
pattern = "*",
|
||||||
vim.api.nvim_create_autocmd({ "FocusGained" }, {
|
callback = _G.update_colors,
|
||||||
pattern = "*",
|
group = vim.api.nvim_create_augroup("auto_colors", { clear = true }),
|
||||||
callback = _G.update_colors,
|
})
|
||||||
group = vim.api.nvim_create_augroup("auto_colors", { clear = true }),
|
|
||||||
})
|
|
||||||
else
|
|
||||||
utils.autocmd("auto_colors", "FocusGained * call v:lua.update_colors()")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Initial setting of colors
|
-- Initial setting of colors
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
if vim.fn.has("nvim-0.7.0") ~= 1 then
|
||||||
|
print("ERROR: Requires nvim >= 0.7.0")
|
||||||
|
end
|
||||||
|
|
||||||
local o = vim.o
|
local o = vim.o
|
||||||
|
|
||||||
-- Helpers
|
-- Helpers
|
||||||
|
@ -92,32 +92,53 @@ local function get_default_attach(override_capabilities)
|
|||||||
-- Mappings
|
-- Mappings
|
||||||
-- TODO: use functions instead of strings when dropping 0.6
|
-- TODO: use functions instead of strings when dropping 0.6
|
||||||
local lsp_keymap = utils.curry_keymap("n", "<leader>l", { buffer = bufnr })
|
local lsp_keymap = utils.curry_keymap("n", "<leader>l", { buffer = bufnr })
|
||||||
lsp_keymap("h", "<cmd>lua vim.lsp.buf.hover()<CR>", { desc = "Display hover" })
|
lsp_keymap("h", function()
|
||||||
lsp_keymap("rn", "<cmd>lua vim.lsp.buf.rename()<CR>", { desc = "Refactor rename" })
|
vim.lsp.buf.hover()
|
||||||
lsp_keymap("e", "<cmd>lua vim.diagnostic.open_float()<CR>", { desc = "Open float dialog" })
|
end, { desc = "Display hover" })
|
||||||
lsp_keymap("D", "<cmd>lua vim.lsp.buf.declaration()<CR>", { desc = "Go to declaration" })
|
lsp_keymap("rn", function()
|
||||||
lsp_keymap("d", "<cmd>lua vim.lsp.buf.definition()<CR>", { desc = "Go to definition" })
|
vim.lsp.buf.rename()
|
||||||
lsp_keymap("t", "<cmd>lua vim.lsp.buf.type_definition()<CR>", { desc = "Go to type definition" })
|
end, { desc = "Refactor rename" })
|
||||||
lsp_keymap("i", "<cmd>lua vim.lsp.buf.implementation()<CR>", { desc = "Show implementations" })
|
lsp_keymap("e", function()
|
||||||
lsp_keymap("s", "<cmd>lua vim.lsp.buf.signature_help()<CR>", { desc = "Show signature help" })
|
vim.diagnostic.open_float()
|
||||||
lsp_keymap("wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", { desc = "Workspace: Add folder" })
|
end, { desc = "Open float dialog" })
|
||||||
lsp_keymap("wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", { desc = "Workspace: Remove folder" })
|
lsp_keymap("D", function()
|
||||||
lsp_keymap(
|
vim.lsp.buf.declaration()
|
||||||
"wl",
|
end, { desc = "Go to declaration" })
|
||||||
"<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>",
|
lsp_keymap("d", function()
|
||||||
{ desc = "Workspace: List folders" }
|
vim.lsp.buf.definition()
|
||||||
)
|
end, { desc = "Go to definition" })
|
||||||
lsp_keymap("r", "<cmd>lua vim.lsp.buf.references()<CR>", { desc = "References" })
|
lsp_keymap("t", function()
|
||||||
lsp_keymap("p", "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", { desc = "Diagnostics: Go to previous" })
|
vim.lsp.buf.type_definition()
|
||||||
lsp_keymap("n", "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>", { desc = "Diagnostics: Go to next" })
|
end, { desc = "Go to type definition" })
|
||||||
|
lsp_keymap("i", function()
|
||||||
|
vim.lsp.buf.implementation()
|
||||||
|
end, { desc = "Show implementations" })
|
||||||
|
lsp_keymap("s", function()
|
||||||
|
vim.lsp.buf.signature_help()
|
||||||
|
end, { desc = "Show signature help" })
|
||||||
|
lsp_keymap("wa", function()
|
||||||
|
vim.lsp.buf.add_workspace_folder()
|
||||||
|
end, { desc = "Workspace: Add folder" })
|
||||||
|
lsp_keymap("wr", function()
|
||||||
|
vim.lsp.buf.remove_workspace_folder()
|
||||||
|
end, { desc = "Workspace: Remove folder" })
|
||||||
|
lsp_keymap("wl", function()
|
||||||
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||||
|
end, { desc = "Workspace: List folders" })
|
||||||
|
lsp_keymap("r", function()
|
||||||
|
vim.lsp.buf.references()
|
||||||
|
end, { desc = "References" })
|
||||||
|
lsp_keymap("p", function()
|
||||||
|
vim.lsp.diagnostic.goto_prev()
|
||||||
|
end, { desc = "Diagnostics: Go to previous" })
|
||||||
|
lsp_keymap("n", function()
|
||||||
|
vim.lsp.diagnostic.goto_next()
|
||||||
|
end, { desc = "Diagnostics: Go to next" })
|
||||||
|
|
||||||
-- Set insert keymap for signature help
|
-- Set insert keymap for signature help
|
||||||
utils.keymap_set(
|
utils.keymap_set("i", "<C-k>", function()
|
||||||
"i",
|
vim.lsp.buf.signature_help()
|
||||||
"<C-k>",
|
end, { buffer = bufnr, desc = "Show signature help" })
|
||||||
"<cmd>lua vim.lsp.buf.signature_help()<CR>",
|
|
||||||
{ buffer = bufnr, desc = "Show signature help" }
|
|
||||||
)
|
|
||||||
|
|
||||||
-- Older keymaps
|
-- Older keymaps
|
||||||
--[[
|
--[[
|
||||||
@ -153,12 +174,12 @@ local function get_default_attach(override_capabilities)
|
|||||||
|
|
||||||
-- Set some keybinds conditional on server capabilities
|
-- Set some keybinds conditional on server capabilities
|
||||||
if vim.fn.has("nvim-0.8") == 1 then
|
if vim.fn.has("nvim-0.8") == 1 then
|
||||||
lsp_keymap("f", "<cmd>lua vim.lsp.buf.format({async=true})<CR>", { desc = "Format code" })
|
lsp_keymap("f", function()
|
||||||
lsp_keymap(
|
vim.lsp.buf.format({ async = true })
|
||||||
"f",
|
end, { desc = "Format code" })
|
||||||
"<cmd>lua vim.lsp.buf.format({async=true})<CR>",
|
lsp_keymap("f", function()
|
||||||
{ mode = "v", desc = "Format selected code" }
|
vim.lsp.buf.format({ async = true })
|
||||||
)
|
end, { mode = "v", desc = "Format selected code" })
|
||||||
if server_capabilities.documentFormattingProvider then
|
if server_capabilities.documentFormattingProvider then
|
||||||
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
||||||
pattern = { "*.rs", "*.go", "*.sh", "*.lua" },
|
pattern = { "*.rs", "*.go", "*.sh", "*.lua" },
|
||||||
@ -171,34 +192,41 @@ local function get_default_attach(override_capabilities)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- HACK: Support for <0.8
|
-- HACK: Support for <0.8
|
||||||
lsp_keymap("f", "<cmd>lua vim.lsp.buf.formatting()<CR>", { desc = "Format code" })
|
lsp_keymap("f", function()
|
||||||
lsp_keymap(
|
vim.lsp.buf.formatting()
|
||||||
"f",
|
end, { desc = "Format code" })
|
||||||
"<cmd>lua vim.lsp.buf.range_formatting()<CR>",
|
lsp_keymap("f", function()
|
||||||
{ mode = "v", desc = "Format selected code" }
|
vim.lsp.buf.range_formatting()
|
||||||
)
|
end, { mode = "v", desc = "Format selected code" })
|
||||||
if server_capabilities.documentFormattingProvider then
|
if server_capabilities.documentFormattingProvider then
|
||||||
vim.cmd([[
|
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
||||||
augroup lsp_format
|
pattern = { "*.rs", "*.go", "*.sh", "*.lua" },
|
||||||
autocmd!
|
callback = function()
|
||||||
autocmd BufWritePre lua vim.lsp.buf.formatting_sync(nil, 1000)
|
vim.lsp.buf.formatting_sync(nil, 1000)
|
||||||
augroup END
|
end,
|
||||||
]])
|
group = vim.api.nvim_create_augroup("lsp_format", { clear = true }),
|
||||||
|
desc = "Auto format code on save",
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set autocommands conditional on server_capabilities
|
-- Set autocommands conditional on server_capabilities
|
||||||
if server_capabilities.documentHighlightProvider then
|
if server_capabilities.documentHighlightProvider then
|
||||||
vim.cmd([[
|
local lsp_document_highlight = vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true })
|
||||||
:highlight link LspReferenceRead MatchParen
|
vim.api.nvim_create_autocmd({ "CursorHold" }, {
|
||||||
:highlight link LspReferenceText MatchParen
|
buffer = bufnr,
|
||||||
:highlight link LspReferenceWrite MatchParen
|
callback = function()
|
||||||
augroup lsp_document_highlight
|
vim.lsp.buf.document_highlight()
|
||||||
autocmd!
|
end,
|
||||||
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
|
group = lsp_document_highlight,
|
||||||
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
|
})
|
||||||
augroup END
|
vim.api.nvim_create_autocmd({ "CursorMoved" }, {
|
||||||
]])
|
buffer = bufnr,
|
||||||
|
callback = function()
|
||||||
|
vim.lsp.buf.clear_references()
|
||||||
|
end,
|
||||||
|
group = lsp_document_highlight,
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Some override some fuzzy finder bindings to use lsp sources
|
-- Some override some fuzzy finder bindings to use lsp sources
|
||||||
|
Loading…
Reference in New Issue
Block a user