1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

Compare commits

...

4 Commits

Author SHA1 Message Date
jdhao
265f171172 remove unused variable 2025-03-30 18:58:23 +02:00
jdhao
b82c1c112f
update colorscheme (#390)
1. Remove catppuccin, it is too purple/blue for me
2. use another nightfox variant
2025-03-30 18:02:28 +02:00
jdhao
0816faee76
Separate diagnostic config from lsp ones (#389) 2025-03-30 17:58:09 +02:00
jdhao
12147bec86
Use glance.nvim for lsp references/implementations preview (#388) 2025-03-30 17:55:51 +02:00
6 changed files with 96 additions and 95 deletions

View File

@ -29,5 +29,12 @@ require("custom-autocmd")
require("mappings")
-- all the plugins installed and their configurations
vim.cmd("source " .. vim.fs.joinpath(config_dir, "viml_conf/plugins.vim"))
-- diagnostic related config
require("diagnostic-conf")
-- colorscheme settings
require("colorschemes")
local color_scheme = require("colorschemes")
-- Load a random colorscheme
color_scheme.rand_colorscheme()

View File

@ -44,14 +44,7 @@ M.colorscheme_conf = {
vim.cmd([[colorscheme everforest]])
end,
nightfox = function()
vim.cmd([[colorscheme nordfox]])
end,
catppuccin = function()
-- available option: latte, frappe, macchiato, mocha
vim.g.catppuccin_flavour = "frappe"
require("catppuccin").setup()
vim.cmd([[colorscheme catppuccin]])
vim.cmd([[colorscheme carbonfox]])
end,
onedarkpro = function()
-- set colorscheme after options
@ -73,14 +66,6 @@ M.colorscheme_conf = {
--- Use a random colorscheme from the pre-defined list of colorschemes.
M.rand_colorscheme = function()
local colorscheme = utils.rand_element(vim.tbl_keys(M.colorscheme_conf))
colorscheme = "gruvbox_material"
if not vim.tbl_contains(vim.tbl_keys(M.colorscheme_conf), colorscheme) then
local msg = "Invalid colorscheme: " .. colorscheme
vim.notify(msg, vim.log.levels.ERROR, { title = "nvim-config" })
return
end
-- Load the colorscheme and its settings
M.colorscheme_conf[colorscheme]()
@ -92,5 +77,4 @@ M.rand_colorscheme = function()
end
end
-- Load a random colorscheme
M.rand_colorscheme()
return M

12
lua/config/glance.lua Normal file
View File

@ -0,0 +1,12 @@
local glance = require("glance")
glance.setup {
height = 25,
border = {
enable = true,
},
}
vim.keymap.set("n", "<space>gd", "<cmd>Glance definitions<cr>")
vim.keymap.set("n", "<space>gr", "<cmd>Glance references<cr>")
vim.keymap.set("n", "<space>gi", "<cmd>Glance implementations<cr>")

View File

@ -1,23 +1,10 @@
local api = vim.api
local keymap = vim.keymap
local lsp = vim.lsp
local diagnostic = vim.diagnostic
local lspconfig = require("lspconfig")
local utils = require("utils")
-- set quickfix list from diagnostics in a certain buffer, not the whole workspace
local set_qflist = function(buf_num, severity)
local diagnostics = nil
diagnostics = diagnostic.get(buf_num, { severity = severity })
local qf_items = diagnostic.toqflist(diagnostics)
vim.fn.setqflist({}, " ", { title = "Diagnostics", items = qf_items })
-- open quickfix by default
vim.cmd([[copen]])
end
local custom_attach = function(client, bufnr)
-- Mappings.
local map = function(mode, l, r, opts)
@ -30,23 +17,10 @@ local custom_attach = function(client, bufnr)
map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" })
map("n", "<C-]>", vim.lsp.buf.definition)
map("n", "K", function()
vim.lsp.buf.hover { border = "single", max_height = 25 }
vim.lsp.buf.hover { border = "single", max_height = 25, max_width = 120 }
end)
map("n", "<C-k>", vim.lsp.buf.signature_help)
map("n", "<space>rn", vim.lsp.buf.rename, { desc = "varialbe rename" })
map("n", "gr", vim.lsp.buf.references, { desc = "show references" })
map("n", "[d", function()
diagnostic.jump { count = -1 }
end, { desc = "previous diagnostic" })
map("n", "]d", function()
diagnostic.jump { count = 1 }
end, { desc = "next diagnostic" })
-- this puts diagnostics from opened files to quickfix
map("n", "<space>qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" })
-- this puts diagnostics from current buffer to quickfix
map("n", "<space>qb", function()
set_qflist(bufnr)
end, { desc = "put buffer diagnostics to qf" })
map("n", "<space>ca", vim.lsp.buf.code_action, { desc = "LSP code action" })
map("n", "<space>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" })
map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" })
@ -65,12 +39,6 @@ local custom_attach = function(client, bufnr)
-- The blow command will highlight the current variable and its usages in the buffer.
if client.server_capabilities.documentHighlightProvider then
vim.cmd([[
hi! link LspReferenceRead Visual
hi! link LspReferenceText Visual
hi! link LspReferenceWrite Visual
]])
local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true })
api.nvim_create_autocmd("CursorHold", {
group = gid,
@ -255,45 +223,3 @@ if utils.executable("lua-language-server") then
capabilities = capabilities,
}
end
-- global config for diagnostic
diagnostic.config {
underline = false,
virtual_text = false,
virtual_lines = false,
signs = {
text = {
[diagnostic.severity.ERROR] = "🆇",
[diagnostic.severity.WARN] = "⚠️",
[diagnostic.severity.INFO] = "",
[diagnostic.severity.HINT] = "",
},
},
severity_sort = true,
float = {
source = true,
header = "Diagnostics:",
prefix = " ",
border = "single",
},
}
api.nvim_create_autocmd("CursorHold", {
pattern = "*",
callback = function()
if #vim.diagnostic.get(0) == 0 then
return
end
if not vim.b.diagnostics_pos then
vim.b.diagnostics_pos = { nil, nil }
end
local cursor_pos = api.nvim_win_get_cursor(0)
if cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2] then
diagnostic.open_float()
end
vim.b.diagnostics_pos = cursor_pos
end,
})

66
lua/diagnostic-conf.lua Normal file
View File

@ -0,0 +1,66 @@
local diagnostic = vim.diagnostic
local api = vim.api
-- global config for diagnostic
diagnostic.config {
underline = false,
virtual_text = false,
virtual_lines = false,
signs = {
text = {
[diagnostic.severity.ERROR] = "🆇",
[diagnostic.severity.WARN] = "⚠️",
[diagnostic.severity.INFO] = "",
[diagnostic.severity.HINT] = "",
},
},
severity_sort = true,
float = {
source = true,
header = "Diagnostics:",
prefix = " ",
border = "single",
},
}
-- set quickfix list from diagnostics in a certain buffer, not the whole workspace
local set_qflist = function(buf_num, severity)
local diagnostics = nil
diagnostics = diagnostic.get(buf_num, { severity = severity })
local qf_items = diagnostic.toqflist(diagnostics)
vim.fn.setqflist({}, " ", { title = "Diagnostics", items = qf_items })
-- open quickfix by default
vim.cmd([[copen]])
end
-- this puts diagnostics from opened files to quickfix
vim.keymap.set("n", "<space>qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" })
-- this puts diagnostics from current buffer to quickfix
vim.keymap.set("n", "<space>qb", function()
set_qflist(0)
end, { desc = "put buffer diagnostics to qf" })
-- automatically show diagnostic in float win for current line
api.nvim_create_autocmd("CursorHold", {
pattern = "*",
callback = function()
if #vim.diagnostic.get(0) == 0 then
return
end
if not vim.b.diagnostics_pos then
vim.b.diagnostics_pos = { nil, nil }
end
local cursor_pos = api.nvim_win_get_cursor(0)
if not vim.deep_equal(cursor_pos, vim.b.diagnostics_pos) then
diagnostic.open_float { width = 100 }
end
vim.b.diagnostics_pos = cursor_pos
end,
})

View File

@ -47,7 +47,13 @@ local plugin_specs = {
require("config.lsp")
end,
},
{
"dnlhc/glance.nvim",
config = function()
require("config.glance")
end,
envnt = "VeryLazy",
},
{
"nvim-treesitter/nvim-treesitter",
event = "VeryLazy",