summaryrefslogtreecommitdiffstats
path: root/lua/core
diff options
context:
space:
mode:
authorSquibid <me@zacharyscheiman.com>2025-05-06 16:51:24 -0500
committerSquibid <me@zacharyscheiman.com>2025-05-06 16:51:24 -0500
commit7c3289fded1f75f6e060f56bd06edc2a327744d9 (patch)
treebf579e6eb1de84237a74ef13ce67703c15266afe /lua/core
parent3094bf2a3983b375f4adeccd25c3b12bbbded2aa (diff)
downloadnvim-7c3289fded1f75f6e060f56bd06edc2a327744d9.tar.gz
nvim-7c3289fded1f75f6e060f56bd06edc2a327744d9.tar.bz2
nvim-7c3289fded1f75f6e060f56bd06edc2a327744d9.zip
kitchen sink again :(
Diffstat (limited to 'lua/core')
-rw-r--r--lua/core/lsp/functions.lua86
-rw-r--r--lua/core/misc.lua40
-rw-r--r--lua/core/snippets/shorthands.lua2
3 files changed, 60 insertions, 68 deletions
diff --git a/lua/core/lsp/functions.lua b/lua/core/lsp/functions.lua
index 4c27bca..e37cc02 100644
--- a/lua/core/lsp/functions.lua
+++ b/lua/core/lsp/functions.lua
@@ -1,24 +1,38 @@
-local misc = require('core.misc')
+local misc = require("core.misc")
local map, include = misc.map, misc.include
local M = {}
-local function on_list(options)
- vim.fn.setqflist({}, 'r', options)
- if #options.items > 1 then
+-- TODO: find a way to make the qflist current item be the one closest to the
+-- cursor whenever we open it
+local function on_list(opts)
+ vim.fn.setqflist({}, "r", opts)
+ if #opts.items > 1 then
vim.cmd.copen()
end
- vim.cmd("cc! 1")
+ vim.cmd(".cc! 1")
end
-local function _w(func)
- return function()
- func({
- border = "solid",
- max_width = math.floor(vim.o.columns * 0.7),
- }, { on_list = on_list })
- end
-end
+---@type vim.lsp.util.open_floating_preview.Opts
+local popup_opts = {
+ border = vim.g.border_style
+}
+---@type vim.lsp.buf.hover.Opts
+---@diagnostic disable-next-line: assign-type-mismatch
+local hover_opts = vim.tbl_deep_extend("force", popup_opts, {})
+
+---@type vim.lsp.buf.signature_help.Opts
+---@diagnostic disable-next-line: assign-type-mismatch
+local signature_opts = vim.tbl_deep_extend("force", popup_opts, {})
+
+---@type vim.lsp.ListOpts
+local list_opts = {
+ on_list = on_list
+}
+
+---@type vim.lsp.LocationOpts
+---@diagnostic disable-next-line: assign-type-mismatch
+local location_opts = vim.tbl_deep_extend("force", list_opts, {})
--- setup basic options on lsp attach
---@param bufnr number buffer number
@@ -26,39 +40,35 @@ local function attach(bufnr)
local opts = { buffer = bufnr, nowait = true }
-- LSP actions
- map('n', 'K', _w(vim.lsp.buf.hover), opts)
- map('n', 'gd', _w(vim.lsp.buf.definition), opts)
- map('n', 'gD', _w(vim.lsp.buf.declaration), opts)
- map('n', 'gi', _w(vim.lsp.buf.implementation), opts)
- map('n', 'gy', _w(vim.lsp.buf.type_definition), opts)
- map('n', 'gr', _w(vim.lsp.buf.references), opts)
- map('n', '<S-Tab>', _w(vim.lsp.buf.signature_help), opts)
- map('n', { '<leader>r', '<F2>' }, _w(vim.lsp.buf.rename), opts)
- map('n', 'gA', _w(vim.lsp.buf.code_action), {
- buffer = bufnr,
- desc = 'check code actions',
- })
- map('n', '<F4>', _w(vim.lsp.buf.code_action), {
+ map("n", "K", function() vim.lsp.buf.hover(hover_opts) end, opts)
+ map("n", "gd", function() vim.lsp.buf.definition(location_opts) end, opts)
+ map("n", "gD", function() vim.lsp.buf.declaration(location_opts) end, opts)
+ map("n", "gi", function() vim.lsp.buf.implementation(location_opts) end, opts)
+ map("n", "gy", function() vim.lsp.buf.type_definition(location_opts) end, opts)
+ map("n", "gr", function() vim.lsp.buf.references(nil, list_opts) end, opts)
+ map("n", "<S-Tab>", function() vim.lsp.buf.signature_help(signature_opts) end, opts)
+ map("n", { "<leader>r", "<F2>" }, vim.lsp.buf.rename, opts)
+ map("n", { "gA", "<F4>" }, vim.lsp.buf.code_action, {
buffer = bufnr,
- desc = 'check code actions'
+ desc = "check code actions",
})
-- Diagnostics
- map('n', '[d', function()
+ map("n", "[d", function()
if not vim.fn.has("nvim-0.11") then
vim.diagnostic.goto_prev()
else
vim.diagnostic.jump({ count = -1 })
end
end, opts)
- map('n', ']d', function()
+ map("n", "]d", function()
if not vim.fn.has("nvim-0.11") then
vim.diagnostic.goto_next()
else
vim.diagnostic.jump({ count = 1 })
end
end, opts)
- -- map('n', 'qD', vim.diagnostic.setqflist, opts)
+ -- map("n", "qD", vim.diagnostic.setqflist, opts)
end
function M.setup()
@@ -81,18 +91,18 @@ function M.setup()
}
if not vim.fn.has("nvim-0.11") then
- vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(
- vim.lsp.handlers.hover, { border = 'solid' })
+ vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(
+ vim.lsp.handlers.hover, { border = vim.g.border_style })
- vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(
- vim.lsp.handlers.signature_help, { border = 'solid' })
+ vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
+ vim.lsp.handlers.signature_help, { border = vim.g.border_style })
end
-- set default capabilities
- include('lspconfig.util').default_config.capabilities = M.capabilities
+ include("lspconfig.util").default_config.capabilities = M.capabilities
-- run whenever a client attaches
- vim.api.nvim_create_autocmd('LspAttach', {
+ vim.api.nvim_create_autocmd("LspAttach", {
callback = function(event)
-- map keybinds
attach(event.buf)
@@ -100,6 +110,8 @@ function M.setup()
})
end
+-- FIXME: I don"t like this way of doing things, there has to be a better way
+
--- capabilities that are to be used in lsp servers, for those setup through
--- lspconfig, this is already set as the default. Incase there is a server
--- not setup through lspconfig this function may be called to receive the
@@ -109,7 +121,7 @@ M.capabilities = vim.lsp.protocol.make_client_capabilities()
--- add capabilities to the default capabilities string
---@param new_capabilities lsp.ClientCapabilities
function M.add_capabilities(new_capabilities)
- vim.tbl_deep_extend('force', M.capabilities, new_capabilities)
+ vim.tbl_deep_extend("force", M.capabilities, new_capabilities)
end
return M
diff --git a/lua/core/misc.lua b/lua/core/misc.lua
index 5d0c0cf..d9c8613 100644
--- a/lua/core/misc.lua
+++ b/lua/core/misc.lua
@@ -9,7 +9,7 @@ M.appid = "Nvim Config"
function M.include(fn)
local ok, r = pcall(require, fn)
if not ok then
- vim.notify('Could not find "'..fn..'": '..r, vim.log.levels.WARN, { title = M.appid })
+ vim.notify("Could not find '"..fn.."': "..r, vim.log.levels.WARN, { title = M.appid })
return ok
end
return r
@@ -26,26 +26,6 @@ function M.loopf(path, body, ext)
end
end
---- set colorscheme
----@param name string name of colorscheme
-function M.colorscheme(name)
- -- only set the colorscheme if it exists
- for _, v in pairs(vim.fn.getcompletion('', 'color')) do
- if v == name then
- vim.cmd("colorscheme "..name)
- break
- end
- end
-
- -- override with any addons
- for _, v in pairs(vim.fn.getcompletion('', 'color')) do
- if v == name..'.ext' then
- vim.cmd("colorscheme"..name..'.ext')
- break
- end
- end
-end
-
--- extend vim.kemap.set
---@param mode string|table mode for the keymap
---@param bind string|table keymap
@@ -53,26 +33,26 @@ end
---@param opts vim.keymap.set.Opts? keymap options
function M.map(mode, bind, cmd, opts)
opts = opts or {}
- opts['noremap'] = true
- opts['silent'] = true
+ opts["noremap"] = true
+ opts["silent"] = true
-- attempt to autogenerate a basic description
- if not opts['desc'] then
+ if not opts["desc"] then
if type(cmd) == "string" then
- opts['desc'] = cmd:gsub("<%a+>", "")
+ opts["desc"] = cmd:gsub("<%a+>", "")
elseif type(cmd) == "function" then
-- TODO: find a way to generate a better name
local file_name = vim.fn.fnamemodify(debug.getinfo(cmd, "S").short_src, ":t")
- opts['desc'] = "origin@"..file_name
+ opts["desc"] = "origin@"..file_name
end
end
-- define the keybinds
- if type(bind) == 'table' then
+ if type(bind) == "table" then
for i in pairs(bind) do
vim.keymap.set(mode, bind[i], cmd, opts)
end
- elseif type(bind) == 'string' then
+ elseif type(bind) == "string" then
vim.keymap.set(mode, bind, cmd, opts)
end
end
@@ -110,11 +90,11 @@ end
function M.highlight(group, opts, namespace)
namespace = namespace or 0
- if type(group) == 'table' then
+ if type(group) == "table" then
for i in pairs(group) do
vim.api.nvim_set_hl(namespace, group[i], opts)
end
- elseif type(group) == 'string' then
+ elseif type(group) == "string" then
vim.api.nvim_set_hl(namespace, group, opts)
end
end
diff --git a/lua/core/snippets/shorthands.lua b/lua/core/snippets/shorthands.lua
index 9f122ff..4e6aa10 100644
--- a/lua/core/snippets/shorthands.lua
+++ b/lua/core/snippets/shorthands.lua
@@ -1,4 +1,4 @@
-ls = require('luasnip')
+ls = require("luasnip")
s = ls.snippet
sn = ls.snippet_node
t = ls.text_node