not quite sure what I've done here
This commit is contained in:
parent
b22873f45f
commit
83aaa5aef3
18 changed files with 392 additions and 392 deletions
|
|
@ -7,10 +7,10 @@ local M = {}
|
|||
function M.copyhl(hlgroup, namespace)
|
||||
namespace = namespace or 0
|
||||
local res = {
|
||||
["foreground"] = "#ff0000",
|
||||
["background"] = "#ff0000",
|
||||
["special"] = "#ff0000"
|
||||
}
|
||||
["foreground"] = "#ff0000",
|
||||
["background"] = "#ff0000",
|
||||
["special"] = "#ff0000"
|
||||
}
|
||||
|
||||
local ok, hl = pcall(vim.api.nvim_get_hl, namespace, {
|
||||
name = hlgroup,
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ local function on_list(opts)
|
|||
|
||||
-- get to the closest reference to the cursor (likely the one gr or gd was
|
||||
-- called on)
|
||||
--
|
||||
-- TODO: switch this to use opts.idx?
|
||||
--
|
||||
-- TODO: switch this to use opts.idx?
|
||||
local closest, distance = 1, false
|
||||
for i, item in ipairs(opts.items) do
|
||||
if item.filename and vim.fn.expand("%:p") == item.filename then
|
||||
|
|
@ -37,32 +37,32 @@ end
|
|||
|
||||
local group = misc.augroup("lsp.bind")
|
||||
auto("LspAttach", {
|
||||
group = group,
|
||||
callback = function(ctx)
|
||||
local list_opts = { on_list = on_list }
|
||||
local opts = { buffer = ctx.buf, nowait = true }
|
||||
group = group,
|
||||
callback = function(ctx)
|
||||
local list_opts = { on_list = on_list }
|
||||
local opts = { buffer = ctx.buf, nowait = true }
|
||||
|
||||
-- LSP actions
|
||||
map("n", "K", vim.lsp.buf.hover, opts)
|
||||
map("n", "gd", function() vim.lsp.buf.definition(list_opts) end, opts)
|
||||
map("n", "gD", function() vim.lsp.buf.declaration(list_opts) end, opts)
|
||||
map("n", "gi", function() vim.lsp.buf.implementation(list_opts) end, opts)
|
||||
map("n", "gy", function() vim.lsp.buf.type_definition(list_opts) end, opts)
|
||||
map("n", "gr", function() vim.lsp.buf.references(nil, list_opts) end, opts)
|
||||
map("n", "<S-Tab>", vim.lsp.buf.signature_help, opts)
|
||||
map("n", "<leader>r", vim.lsp.buf.rename, opts)
|
||||
map("n", "gA", vim.lsp.buf.code_action, opts)
|
||||
-- LSP actions
|
||||
map("n", "K", vim.lsp.buf.hover, opts)
|
||||
map("n", "gd", function() vim.lsp.buf.definition(list_opts) end, opts)
|
||||
map("n", "gD", function() vim.lsp.buf.declaration(list_opts) end, opts)
|
||||
map("n", "gi", function() vim.lsp.buf.implementation(list_opts) end, opts)
|
||||
map("n", "gy", function() vim.lsp.buf.type_definition(list_opts) end, opts)
|
||||
map("n", "gr", function() vim.lsp.buf.references(nil, list_opts) end, opts)
|
||||
map("n", "<S-Tab>", vim.lsp.buf.signature_help, opts)
|
||||
map("n", "<leader>r", vim.lsp.buf.rename, opts)
|
||||
map("n", "gA", vim.lsp.buf.code_action, opts)
|
||||
|
||||
-- Diagnostics
|
||||
map("n", "[d", function()
|
||||
vim.diagnostic.jump({ count = -1 })
|
||||
end, opts)
|
||||
map("n", "]d", function()
|
||||
vim.diagnostic.jump({ count = 1 })
|
||||
end, opts)
|
||||
map("n", "gb", vim.diagnostic.setqflist, opts)
|
||||
-- Diagnostics
|
||||
map("n", "[d", function()
|
||||
vim.diagnostic.jump({ count = -1 })
|
||||
end, opts)
|
||||
map("n", "]d", function()
|
||||
vim.diagnostic.jump({ count = 1 })
|
||||
end, opts)
|
||||
map("n", "gb", vim.diagnostic.setqflist, opts)
|
||||
|
||||
-- formatting
|
||||
map("n", "<leader>c", vim.lsp.buf.format)
|
||||
end
|
||||
-- formatting
|
||||
map("n", "<leader>c", vim.lsp.buf.format)
|
||||
end
|
||||
})
|
||||
|
|
|
|||
|
|
@ -9,16 +9,16 @@
|
|||
---@param list table list of chars
|
||||
---@param char number|string char to add
|
||||
local function add_to_client(list, char)
|
||||
local c
|
||||
local c
|
||||
|
||||
if type(char) == "string" then
|
||||
c = char
|
||||
elseif type(char) == "number" then
|
||||
c = string.char(char)
|
||||
end
|
||||
if not table.contains(list, c) then
|
||||
table.insert(list, c)
|
||||
end
|
||||
if type(char) == "string" then
|
||||
c = char
|
||||
elseif type(char) == "number" then
|
||||
c = string.char(char)
|
||||
end
|
||||
if not table.contains(list, c) then
|
||||
table.insert(list, c)
|
||||
end
|
||||
end
|
||||
|
||||
-- make sure we can add autos
|
||||
|
|
@ -29,49 +29,49 @@ local completion_group = misc.augroup("lsp.completion")
|
|||
-- Configure the lsp completion menu. In addition to setting up lsp completion
|
||||
-- this also styles it to look nice.
|
||||
auto("LspAttach", {
|
||||
group = completion_group,
|
||||
callback = function(ctx)
|
||||
local client = vim.lsp.get_client_by_id(ctx.data.client_id)
|
||||
if not client or not client:supports_method("textDocument/completion") then
|
||||
return
|
||||
end
|
||||
group = completion_group,
|
||||
callback = function(ctx)
|
||||
local client = vim.lsp.get_client_by_id(ctx.data.client_id)
|
||||
if not client or not client:supports_method("textDocument/completion") then
|
||||
return
|
||||
end
|
||||
|
||||
-- Make completion menu appear whenever you type something.
|
||||
local c = client.server_capabilities.completionProvider.triggerCharacters
|
||||
if c then
|
||||
for i = 32, 126 do
|
||||
add_to_client(c, string.char(i))
|
||||
end
|
||||
end
|
||||
-- Make completion menu appear whenever you type something.
|
||||
local c = client.server_capabilities.completionProvider.triggerCharacters
|
||||
if c then
|
||||
for i = 32, 126 do
|
||||
add_to_client(c, string.char(i))
|
||||
end
|
||||
end
|
||||
|
||||
vim.lsp.completion.enable(true, client.id, ctx.buf, {
|
||||
autotrigger = true,
|
||||
convert = function(item)
|
||||
vim.lsp.completion.enable(true, client.id, ctx.buf, {
|
||||
autotrigger = true,
|
||||
convert = function(item)
|
||||
local kind = vim.lsp.protocol.CompletionItemKind[item.kind] or 'u'
|
||||
return {
|
||||
-- in the future if we ever get the ability to highlight specific
|
||||
-- entries in the pummenu I'd like to add treesitter highlighting to
|
||||
-- the entries
|
||||
-- in the future if we ever get the ability to highlight specific
|
||||
-- entries in the pummenu I'd like to add treesitter highlighting to
|
||||
-- the entries
|
||||
abbr = item.label:gsub('%b()', ''),
|
||||
kind = kind:sub(1, 1):lower(),
|
||||
menu = ''
|
||||
}
|
||||
end
|
||||
})
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
})
|
||||
|
||||
-- attempt to style the completion documentation popup
|
||||
auto("CompleteChanged", {
|
||||
group = completion_group,
|
||||
callback = function()
|
||||
local info = vim.fn.complete_info({ "selected" })
|
||||
if info.preview_bufnr and vim.bo[info.preview_bufnr].filetype == "" then
|
||||
vim.bo[info.preview_bufnr].filetype = "markdown"
|
||||
vim.wo[info.preview_winid].conceallevel = 2
|
||||
vim.wo[info.preview_winid].concealcursor = "niv"
|
||||
end
|
||||
end
|
||||
group = completion_group,
|
||||
callback = function()
|
||||
local info = vim.fn.complete_info({ "selected" })
|
||||
if info.preview_bufnr and vim.bo[info.preview_bufnr].filetype == "" then
|
||||
vim.bo[info.preview_bufnr].filetype = "markdown"
|
||||
vim.wo[info.preview_winid].conceallevel = 2
|
||||
vim.wo[info.preview_winid].concealcursor = "niv"
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
-- Add snippet support to lsp clients who don't do it for us. Currently this
|
||||
|
|
@ -81,121 +81,121 @@ auto("CompleteChanged", {
|
|||
-- not follow the c-style function call style. I've only gotten this working in
|
||||
-- lua thus far.
|
||||
auto("CompleteDonePre", {
|
||||
group = completion_group,
|
||||
callback = function()
|
||||
local item = vim.tbl_get(
|
||||
vim.v.completed_item,
|
||||
"user_data",
|
||||
"nvim",
|
||||
"lsp",
|
||||
"completion_item"
|
||||
)
|
||||
if not item then
|
||||
return
|
||||
end
|
||||
group = completion_group,
|
||||
callback = function()
|
||||
local item = vim.tbl_get(
|
||||
vim.v.completed_item,
|
||||
"user_data",
|
||||
"nvim",
|
||||
"lsp",
|
||||
"completion_item"
|
||||
)
|
||||
if not item then
|
||||
return
|
||||
end
|
||||
|
||||
-- TODO: we need to truncate the item.label to ensure that we don't
|
||||
-- duplicate any text below is my attempt to start work on it:
|
||||
--
|
||||
-- local cursor = vim.api.nvim_win_get_cursor(0)
|
||||
-- local line = vim.api.nvim_buf_get_lines(
|
||||
-- vim.api.nvim_win_get_buf(0),
|
||||
-- cursor[1] - 1,
|
||||
-- cursor[1],
|
||||
-- false
|
||||
-- )[1]
|
||||
-- item.label = string.gsub(item.label, string.sub(line, cursor[2] + 1), "")
|
||||
-- item.insertText = item.label
|
||||
-- TODO: we need to truncate the item.label to ensure that we don't
|
||||
-- duplicate any text below is my attempt to start work on it:
|
||||
--
|
||||
-- local cursor = vim.api.nvim_win_get_cursor(0)
|
||||
-- local line = vim.api.nvim_buf_get_lines(
|
||||
-- vim.api.nvim_win_get_buf(0),
|
||||
-- cursor[1] - 1,
|
||||
-- cursor[1],
|
||||
-- false
|
||||
-- )[1]
|
||||
-- item.label = string.gsub(item.label, string.sub(line, cursor[2] + 1), "")
|
||||
-- item.insertText = item.label
|
||||
|
||||
-- if the item isn't a snippet then we might want to create a snippet
|
||||
if item.label and item.kind and item.insertTextFormat then
|
||||
if item.insertTextFormat ~= 2 and item.kind == 3 then
|
||||
local n_complete_item = vim.v.completed_item
|
||||
-- if the item isn't a snippet then we might want to create a snippet
|
||||
if item.label and item.kind and item.insertTextFormat then
|
||||
if item.insertTextFormat ~= 2 and item.kind == 3 then
|
||||
local n_complete_item = vim.v.completed_item
|
||||
|
||||
-- attempt to modify the function args to create a snippet
|
||||
local paren1 = string.find(item.label, "%(")
|
||||
if not paren1 then
|
||||
return
|
||||
end
|
||||
-- attempt to modify the function args to create a snippet
|
||||
local paren1 = string.find(item.label, "%(")
|
||||
if not paren1 then
|
||||
return
|
||||
end
|
||||
|
||||
-- try and create a snippet from a function call
|
||||
local i = 1
|
||||
local text = ""
|
||||
local l_paren = paren1
|
||||
local next, is_paren
|
||||
while not is_paren do
|
||||
-- find the next token
|
||||
next = string.find(item.label, "%,", l_paren + 1)
|
||||
if not next then
|
||||
next = string.find(item.label, "%)", l_paren + 1)
|
||||
if not next then
|
||||
return
|
||||
end
|
||||
is_paren = true
|
||||
end
|
||||
-- try and create a snippet from a function call
|
||||
local i = 1
|
||||
local text = ""
|
||||
local l_paren = paren1
|
||||
local next, is_paren
|
||||
while not is_paren do
|
||||
-- find the next token
|
||||
next = string.find(item.label, "%,", l_paren + 1)
|
||||
if not next then
|
||||
next = string.find(item.label, "%)", l_paren + 1)
|
||||
if not next then
|
||||
return
|
||||
end
|
||||
is_paren = true
|
||||
end
|
||||
|
||||
-- concat text
|
||||
if text == "" then
|
||||
-- start the snippet
|
||||
text = string.sub(item.label, 0, l_paren).."${"..i..":"
|
||||
else
|
||||
-- continue the snippet
|
||||
text = text.."}, ".."${"..i..":"
|
||||
end
|
||||
-- concat text
|
||||
if text == "" then
|
||||
-- start the snippet
|
||||
text = string.sub(item.label, 0, l_paren).."${"..i..":"
|
||||
else
|
||||
-- continue the snippet
|
||||
text = text.."}, ".."${"..i..":"
|
||||
end
|
||||
|
||||
do -- add the content of the argument to the snippet
|
||||
-- we need to account for cases in which the developer uses spaces
|
||||
-- between their commas and code
|
||||
local is_space = string.sub(item.label, l_paren + 1, l_paren + 1)
|
||||
local plus = is_space == " " and 2 or 1
|
||||
do -- add the content of the argument to the snippet
|
||||
-- we need to account for cases in which the developer uses spaces
|
||||
-- between their commas and code
|
||||
local is_space = string.sub(item.label, l_paren + 1, l_paren + 1)
|
||||
local plus = is_space == " " and 2 or 1
|
||||
|
||||
text = text..string.sub(item.label, l_paren + plus, next - 1)
|
||||
end
|
||||
text = text..string.sub(item.label, l_paren + plus, next - 1)
|
||||
end
|
||||
|
||||
-- increment
|
||||
l_paren = next
|
||||
i = i + 1
|
||||
end
|
||||
-- end the snippet
|
||||
text = text.."})"
|
||||
-- increment
|
||||
l_paren = next
|
||||
i = i + 1
|
||||
end
|
||||
-- end the snippet
|
||||
text = text.."})"
|
||||
|
||||
n_complete_item.user_data.nvim.lsp.completion_item.insertText = text
|
||||
n_complete_item.user_data.nvim.lsp.completion_item.insertTextFormat = 2
|
||||
n_complete_item.user_data.nvim.lsp.completion_item.kind = 3
|
||||
vim.v.completed_item = n_complete_item
|
||||
end
|
||||
end
|
||||
end
|
||||
n_complete_item.user_data.nvim.lsp.completion_item.insertText = text
|
||||
n_complete_item.user_data.nvim.lsp.completion_item.insertTextFormat = 2
|
||||
n_complete_item.user_data.nvim.lsp.completion_item.kind = 3
|
||||
vim.v.completed_item = n_complete_item
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
-- show the signature help when inside a function call
|
||||
auto("CompleteDone", {
|
||||
group = completion_group,
|
||||
callback = function(ctx)
|
||||
-- make sure there's an lsp client, and make sure the lsp client supports
|
||||
-- textDocument/signatureHelp
|
||||
local client = vim.lsp.get_clients({ bufnr = ctx.buf })[1]
|
||||
if not client or not client:supports_method("textDocument/signatureHelp") then
|
||||
return
|
||||
end
|
||||
group = completion_group,
|
||||
callback = function(ctx)
|
||||
-- make sure there's an lsp client, and make sure the lsp client supports
|
||||
-- textDocument/signatureHelp
|
||||
local client = vim.lsp.get_clients({ bufnr = ctx.buf })[1]
|
||||
if not client or not client:supports_method("textDocument/signatureHelp") then
|
||||
return
|
||||
end
|
||||
|
||||
-- show the signature help
|
||||
local item = vim.tbl_get(
|
||||
vim.v.completed_item,
|
||||
"user_data",
|
||||
"nvim",
|
||||
"lsp",
|
||||
"completion_item"
|
||||
)
|
||||
if not item then
|
||||
return
|
||||
end
|
||||
-- show the signature help
|
||||
local item = vim.tbl_get(
|
||||
vim.v.completed_item,
|
||||
"user_data",
|
||||
"nvim",
|
||||
"lsp",
|
||||
"completion_item"
|
||||
)
|
||||
if not item then
|
||||
return
|
||||
end
|
||||
|
||||
-- show signature help when the completion is a function
|
||||
if item.kind == 3 and (item.textEdit ~= nil or item.insertText ~= nil) then
|
||||
-- for some reason calling vim.schedule didn't work for me
|
||||
vim.defer_fn(vim.lsp.buf.signature_help, 100)
|
||||
end
|
||||
end,
|
||||
desc = "Auto show signature help when completion is done"
|
||||
-- show signature help when the completion is a function
|
||||
if item.kind == 3 and (item.textEdit ~= nil or item.insertText ~= nil) then
|
||||
-- for some reason calling vim.schedule didn't work for me
|
||||
vim.defer_fn(vim.lsp.buf.signature_help, 100)
|
||||
end
|
||||
end,
|
||||
desc = "Auto show signature help when completion is done"
|
||||
})
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ function M.setup()
|
|||
capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
}
|
||||
|
||||
require("core.lsp.binds")
|
||||
require("core.lsp.completion")
|
||||
require("core.lsp.wtf")
|
||||
require("core.lsp.binds")
|
||||
require("core.lsp.completion")
|
||||
require("core.lsp.wtf")
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -9,29 +9,29 @@ auto('LspAttach', {
|
|||
group = wtf_group,
|
||||
callback = function(ctx)
|
||||
local client = vim.lsp.get_client_by_id(ctx.data.client_id)
|
||||
if not client then
|
||||
return
|
||||
end
|
||||
if not client then
|
||||
return
|
||||
end
|
||||
|
||||
-- highlight color codes via lsp (supported by cssls)
|
||||
-- #ff0000
|
||||
-- highlight color codes via lsp (supported by cssls)
|
||||
_ = "#ff0000"
|
||||
if client:supports_method('textDocument/documentColor') then
|
||||
pcall(vim.lsp.document_color.enable, true, ctx.buf)
|
||||
end
|
||||
|
||||
-- enable linked editing this allows lsps to modify things like html tags
|
||||
-- for example when you change <p> to <a> </p> will be changed by the lsp
|
||||
-- to </a>
|
||||
-- enable linked editing this allows lsps to modify things like html tags
|
||||
-- for example when you change <p> to <a> </p> will be changed by the lsp
|
||||
-- to </a>
|
||||
if client:supports_method('textDocument/linkedEditingRange') then
|
||||
pcall(vim.lsp.linked_editing_range.enable, true, { client_id = client.id })
|
||||
pcall(vim.lsp.linked_editing_range.enable, true, { client_id = client.id })
|
||||
end
|
||||
|
||||
-- disabled for now cause I don't like it
|
||||
-- -- enable type formatting which allows lsps to modify text while you're
|
||||
-- -- typing for example if you insert {} in a string in python basedpyright
|
||||
-- -- will change the string to a format string
|
||||
-- if client:supports_method('textDocument/onTypeFormatting') then
|
||||
-- pcall(vim.lsp.on_type_formatting.enable, true, { client_id = client.id })
|
||||
-- end
|
||||
-- disabled for now cause I don't like it
|
||||
-- -- enable type formatting which allows lsps to modify text while you're
|
||||
-- -- typing for example if you insert {} in a string in python basedpyright
|
||||
-- -- will change the string to a format string
|
||||
-- if client:supports_method('textDocument/onTypeFormatting') then
|
||||
-- pcall(vim.lsp.on_type_formatting.enable, true, { client_id = client.id })
|
||||
-- end
|
||||
end
|
||||
})
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ function M.map(mode, bind, cmd, opts)
|
|||
end
|
||||
end
|
||||
|
||||
vim.keymap.set(mode, bind, cmd, opts)
|
||||
vim.keymap.set(mode, bind, cmd, opts)
|
||||
end
|
||||
|
||||
--- a small map wrapper to easily create local buffer mappings
|
||||
|
|
@ -56,18 +56,18 @@ end
|
|||
---@return string|function lazified
|
||||
---@nodiscard
|
||||
function M.lz(txt)
|
||||
if type(txt) == "string" then
|
||||
return "<cmd>se lz<CR>"..txt.."<cmd>se lz!<CR>"
|
||||
elseif type(txt) == "function" then
|
||||
return function()
|
||||
vim.cmd.se("lz")
|
||||
-- gotta make sure we can always unset lz
|
||||
pcall(txt)
|
||||
vim.cmd.se("lz!")
|
||||
end
|
||||
else
|
||||
return txt
|
||||
end
|
||||
if type(txt) == "string" then
|
||||
return "<cmd>se lz<CR>"..txt.."<cmd>se lz!<CR>"
|
||||
elseif type(txt) == "function" then
|
||||
return function()
|
||||
vim.cmd.se("lz")
|
||||
-- gotta make sure we can always unset lz
|
||||
pcall(txt)
|
||||
vim.cmd.se("lz!")
|
||||
end
|
||||
else
|
||||
return txt
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue