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

Compare commits

..

No commits in common. "265f171172beb1289806bbc22c632c39048cfb86" and "a8a1b929212c9d2a015a14215dd58d94bc7bdfe8" have entirely different histories.

6 changed files with 95 additions and 96 deletions

View File

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

View File

@ -44,7 +44,14 @@ M.colorscheme_conf = {
vim.cmd([[colorscheme everforest]]) vim.cmd([[colorscheme everforest]])
end, end,
nightfox = function() nightfox = function()
vim.cmd([[colorscheme carbonfox]]) 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]])
end, end,
onedarkpro = function() onedarkpro = function()
-- set colorscheme after options -- set colorscheme after options
@ -66,6 +73,14 @@ M.colorscheme_conf = {
--- Use a random colorscheme from the pre-defined list of colorschemes. --- Use a random colorscheme from the pre-defined list of colorschemes.
M.rand_colorscheme = function() M.rand_colorscheme = function()
local colorscheme = utils.rand_element(vim.tbl_keys(M.colorscheme_conf)) 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 -- Load the colorscheme and its settings
M.colorscheme_conf[colorscheme]() M.colorscheme_conf[colorscheme]()
@ -77,4 +92,5 @@ M.rand_colorscheme = function()
end end
end end
return M -- Load a random colorscheme
M.rand_colorscheme()

View File

@ -1,12 +0,0 @@
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,10 +1,23 @@
local api = vim.api local api = vim.api
local keymap = vim.keymap local keymap = vim.keymap
local lsp = vim.lsp local lsp = vim.lsp
local diagnostic = vim.diagnostic
local lspconfig = require("lspconfig") local lspconfig = require("lspconfig")
local utils = require("utils") 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) local custom_attach = function(client, bufnr)
-- Mappings. -- Mappings.
local map = function(mode, l, r, opts) local map = function(mode, l, r, opts)
@ -17,10 +30,23 @@ local custom_attach = function(client, bufnr)
map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" }) map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" })
map("n", "<C-]>", vim.lsp.buf.definition) map("n", "<C-]>", vim.lsp.buf.definition)
map("n", "K", function() map("n", "K", function()
vim.lsp.buf.hover { border = "single", max_height = 25, max_width = 120 } vim.lsp.buf.hover { border = "single", max_height = 25 }
end) end)
map("n", "<C-k>", vim.lsp.buf.signature_help) map("n", "<C-k>", vim.lsp.buf.signature_help)
map("n", "<space>rn", vim.lsp.buf.rename, { desc = "varialbe rename" }) 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>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>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" }) map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" })
@ -39,6 +65,12 @@ local custom_attach = function(client, bufnr)
-- The blow command will highlight the current variable and its usages in the buffer. -- The blow command will highlight the current variable and its usages in the buffer.
if client.server_capabilities.documentHighlightProvider then 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 }) local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true })
api.nvim_create_autocmd("CursorHold", { api.nvim_create_autocmd("CursorHold", {
group = gid, group = gid,
@ -223,3 +255,45 @@ if utils.executable("lua-language-server") then
capabilities = capabilities, capabilities = capabilities,
} }
end 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,
})

View File

@ -1,66 +0,0 @@
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,13 +47,7 @@ local plugin_specs = {
require("config.lsp") require("config.lsp")
end, end,
}, },
{
"dnlhc/glance.nvim",
config = function()
require("config.glance")
end,
envnt = "VeryLazy",
},
{ {
"nvim-treesitter/nvim-treesitter", "nvim-treesitter/nvim-treesitter",
event = "VeryLazy", event = "VeryLazy",