Browse Source

feat: add back trouble

master
Tovi Jaeschke-Rogers 7 months ago
parent
commit
ad0712f1f6
5 changed files with 210 additions and 137 deletions
  1. +51
    -18
      .config/nvim/lua/tovi/plugins/flash.lua
  2. +95
    -93
      .config/nvim/lua/tovi/plugins/lsp/lspconfig.lua
  3. +25
    -26
      .config/nvim/lua/tovi/plugins/nvim-cmp.lua
  4. +2
    -0
      .config/nvim/lua/tovi/plugins/telescope.lua
  5. +37
    -0
      .config/nvim/lua/tovi/plugins/trouble.lua

+ 51
- 18
.config/nvim/lua/tovi/plugins/flash.lua View File

@ -1,20 +1,53 @@
return {
"folke/flash.nvim",
event = "VeryLazy",
---@type Flash.Config
opts = {
modes = {
char = {
enabled = false,
}
}
},
-- stylua: ignore
keys = {
{ "s", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" },
{ "S", mode = { "n", "x", "o" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" },
{ "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" },
{ "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" },
{ "<c-s>", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" },
},
"folke/flash.nvim",
event = "VeryLazy",
opts = {
modes = {
char = {
enabled = false,
},
},
},
keys = {
{
"s",
mode = { "n", "x", "o" },
function()
require("flash").jump()
end,
desc = "Flash",
},
{
"S",
mode = { "n", "x", "o" },
function()
require("flash").treesitter()
end,
desc = "Flash Treesitter",
},
{
"r",
mode = "o",
function()
require("flash").remote()
end,
desc = "Remote Flash",
},
{
"R",
mode = { "o", "x" },
function()
require("flash").treesitter_search()
end,
desc = "Treesitter Search",
},
{
"<c-s>",
mode = { "c" },
function()
require("flash").toggle()
end,
desc = "Toggle Flash Search",
},
},
}

+ 95
- 93
.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua View File

@ -8,7 +8,7 @@ return {
config = function()
-- import lspconfig plugin
local lspconfig = require("lspconfig")
local util = require("lspconfig.util")
local util = require("lspconfig.util")
-- import cmp-nvim-lsp plugin
local cmp_nvim_lsp = require("cmp_nvim_lsp")
@ -79,13 +79,16 @@ return {
vim.diagnostic.goto_next({ severity = vim.diagnostic.severity.ERROR })
end, opts)
opts.desc = "Show documentation for what is under cursor"
keymap.set("n", "<leader>ld", vim.diagnostic.setqflist, opts) -- show documentation for what is under cursor
opts.desc = "Show documentation for what is under cursor"
keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor
end
-- override default floating window border if not set
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
---@diagnostic disable-next-line: duplicate-set-field
---@diagnostic disable-next-line: duplicate-set-field
function vim.lsp.util.open_floating_preview(contents, syntax, options, ...)
options = options or {}
options.border = options.border or "rounded"
@ -107,72 +110,72 @@ return {
on_attach = on_attach,
})
-- Function to detect the operating system
local function get_os()
local handle = io.popen('uname')
if not handle then
return error("Failed to detect operating system")
end
local result = handle:read("*a")
handle:close()
return result:lower():gsub("%s+", "")
end
-- Set the base path based on the operating system
local os = get_os()
local base_path = ""
if os == "darwin" then
base_path = "/opt/homebrew/lib/node_modules"
elseif os == "linux" then
base_path = "/usr/local/lib/node_modules"
end
lspconfig.tsserver.setup({
init_options = {
plugins = {
{
name = "@vue/typescript-plugin",
location = base_path .. "/@vue/typescript-plugin",
languages = { "javascript", "typescript", "vue" },
},
},
},
filetypes = {
"javascript",
"typescript",
"vue",
},
capabilities = capabilities,
})
local function get_typescript_server_path(root_dir)
local global_ts = base_path .. '/typescript/lib'
local found_ts = ''
local function check_dir(path)
found_ts = util.path.join(path, 'node_modules', 'typescript', 'lib')
if util.path.exists(found_ts) then
return path
end
end
if util.search_ancestors(root_dir, check_dir) then
return found_ts
else
return global_ts
end
end
-- Function to detect the operating system
local function get_os()
local handle = io.popen("uname")
if not handle then
return error("Failed to detect operating system")
end
local result = handle:read("*a")
handle:close()
return result:lower():gsub("%s+", "")
end
-- Set the base path based on the operating system
local os = get_os()
local base_path = ""
if os == "darwin" then
base_path = "/opt/homebrew/lib/node_modules"
elseif os == "linux" then
base_path = "/usr/local/lib/node_modules"
end
lspconfig.tsserver.setup({
init_options = {
plugins = {
{
name = "@vue/typescript-plugin",
location = base_path .. "/@vue/typescript-plugin",
languages = { "javascript", "typescript", "vue" },
},
},
},
filetypes = {
"javascript",
"typescript",
"vue",
},
capabilities = capabilities,
})
local function get_typescript_server_path(root_dir)
local global_ts = base_path .. "/typescript/lib"
local found_ts = ""
local function check_dir(path)
found_ts = util.path.join(path, "node_modules", "typescript", "lib")
if util.path.exists(found_ts) then
return path
end
end
if util.search_ancestors(root_dir, check_dir) then
return found_ts
else
return global_ts
end
end
lspconfig.volar.setup({
capabilities = capabilities,
on_attach = on_attach,
filetypes = {
"javascript",
"typescript",
"vue",
},
on_new_config = function(new_config, new_root_dir)
new_config.init_options.typescript.tsdk = get_typescript_server_path(new_root_dir)
end,
filetypes = {
"javascript",
"typescript",
"vue",
},
on_new_config = function(new_config, new_root_dir)
new_config.init_options.typescript.tsdk = get_typescript_server_path(new_root_dir)
end,
})
-- configure css server
@ -183,39 +186,38 @@ return {
-- configure php server
lspconfig["intelephense"].setup({
root_dir = function(pattern)
---@diagnostic disable-next-line: undefined-field
local cwd = vim.loop.cwd()
local root = util.root_pattern('composer.json')(pattern)
-- prefer cwd if root is a descendant
return util.path.is_descendant(cwd, root) and cwd or root
end,
root_dir = function(pattern)
---@diagnostic disable-next-line: undefined-field
local cwd = vim.loop.cwd()
local root = util.root_pattern("composer.json")(pattern)
-- prefer cwd if root is a descendant
return util.path.is_descendant(cwd, root) and cwd or root
end,
capabilities = capabilities,
on_attach = on_attach,
init_options = {
licenceKey = vim.fn.expand('$HOME/.local/share/nvim/intelephense-licence.txt')
},
settings = {
}
init_options = {
licenceKey = vim.fn.expand("$HOME/.local/share/nvim/intelephense-licence.txt"),
},
settings = {},
})
lspconfig.gopls.setup {
on_attach = on_attach,
capabilities = capabilities,
cmd = {"gopls"},
filetypes = { "go", "gomod", "gowork", "gotmpl" },
root_dir = util.root_pattern("go.work", "go.mod", ".git"),
settings = {
gopls = {
completeUnimported = true,
usePlaceholders = true,
analyses = {
unusedparams = true,
},
},
},
}
lspconfig.gopls.setup({
on_attach = on_attach,
capabilities = capabilities,
cmd = { "gopls" },
filetypes = { "go", "gomod", "gowork", "gotmpl" },
root_dir = util.root_pattern("go.work", "go.mod", ".git"),
settings = {
gopls = {
completeUnimported = true,
usePlaceholders = true,
analyses = {
unusedparams = true,
},
},
},
})
-- configure lua server (with special settings)
lspconfig["lua_ls"].setup({


+ 25
- 26
.config/nvim/lua/tovi/plugins/nvim-cmp.lua View File

@ -9,7 +9,7 @@ return {
"saadparwaiz1/cmp_luasnip",
"rafamadriz/friendly-snippets",
"onsails/lspkind.nvim",
"kristijanhusak/vim-dadbod-completion",
"kristijanhusak/vim-dadbod-completion",
},
config = function()
local cmp = require("cmp")
@ -21,10 +21,10 @@ return {
-- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
require("luasnip.loaders.from_vscode").lazy_load({ paths = { "~/.config/nvim/snippets" } })
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match "%s" == nil
end
local has_words_before = function()
local line, col = table.unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
cmp.setup({
completion = {
@ -77,36 +77,35 @@ return {
-- sources for autocompletion
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "copilot" },
{ name = "copilot" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "path" },
{ name = "vim-dadbod-completion" },
{ name = "vim-dadbod-completion" },
}),
-- configure lspkind for vs-code like pictograms in completion menu
formatting = {
format = lspkind.cmp_format({
mode = "symbol_text",
-- with_text = true,
menu = {
nvim_lua = "[api]",
nvim_lsp = "[LSP]",
luasnip = "[snip]",
vim_dadbod_completion = "[DB]",
path = "[path]",
buffer = "[Buffer]",
},
mode = "symbol_text",
menu = {
nvim_lua = "[api]",
nvim_lsp = "[LSP]",
luasnip = "[snip]",
vim_dadbod_completion = "[DB]",
path = "[path]",
buffer = "[Buffer]",
},
}),
},
event = {
on = {
CompleteChanged = function(data)
if data.entry then
vim.lsp.buf.hover()
end
end,
},
},
event = {
on = {
CompleteChanged = function(data)
if data.entry then
vim.lsp.buf.hover()
end
end,
},
},
})
end,
}

+ 2
- 0
.config/nvim/lua/tovi/plugins/telescope.lua View File

@ -126,6 +126,8 @@ return {
keymap.set("n", "<leader>fo", builtin.oldfiles, {})
keymap.set("n", "<leader>m", builtin.marks, {})
keymap.set("n", "<leader>cc", builtin.commands, {})
keymap.set("n", "<leader>ch", builtin.command_history, {})
keymap.set("n", "<leader>gb", function()


+ 37
- 0
.config/nvim/lua/tovi/plugins/trouble.lua View File

@ -0,0 +1,37 @@
return {
"folke/trouble.nvim",
opts = {},
cmd = "Trouble",
keys = {
{
"<leader>xx",
"<cmd>Trouble diagnostics toggle<cr>",
desc = "Diagnostics (Trouble)",
},
{
"<leader>xX",
"<cmd>Trouble diagnostics toggle filter.buf=0<cr>",
desc = "Buffer Diagnostics (Trouble)",
},
{
"<leader>cs",
"<cmd>Trouble symbols toggle focus=false<cr>",
desc = "Symbols (Trouble)",
},
{
"<leader>cl",
"<cmd>Trouble lsp toggle focus=false win.position=right<cr>",
desc = "LSP Definitions / references / ... (Trouble)",
},
{
"<leader>xL",
"<cmd>Trouble loclist toggle<cr>",
desc = "Location List (Trouble)",
},
{
"<leader>xQ",
"<cmd>Trouble qflist toggle<cr>",
desc = "Quickfix List (Trouble)",
},
},
}

Loading…
Cancel
Save