From: Huck Boles Date: Wed, 17 May 2023 14:03:41 +0000 (-0500) Subject: fix: lsp - treesitter integration X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=b52d40449af3f96da3181acfcfc7bf581a89386c;p=nvim.git fix: lsp - treesitter integration --- diff --git a/lua/huck/functions.lua b/lua/huck/functions.lua index cbf5915..235bbd5 100644 --- a/lua/huck/functions.lua +++ b/lua/huck/functions.lua @@ -31,11 +31,3 @@ vim.api.nvim_create_autocmd("BufNewFile", { end end, }) - --- auto format code on save -vim.api.nvim_create_autocmd("BufWritePre", { - pattern = { "*" }, - callback = function() - vim.lsp.buf.format() - end, -}) diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index e2149d6..01da992 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -3,6 +3,7 @@ return { "jose-elias-alvarez/null-ls.nvim", dependencies = { "plenary.nvim", + "nvim-treesitter", { "jay-babu/mason-null-ls.nvim", dependencies = { "mason.nvim" }, @@ -46,6 +47,7 @@ return { { "williamboman/mason-lspconfig", dependencies = { + "nvim-treesitter", { "williamboman/mason.nvim", build = ":MasonUpdate", @@ -75,6 +77,7 @@ return { "Maan2003/lsp_lines.nvim", }, config = function() + -- servers to setup local lsp = require("lspconfig") lsp.awk_ls.setup({}) lsp.bashls.setup({}) @@ -87,22 +90,11 @@ return { lsp.lua_ls.setup({}) lsp.marksman.setup({}) lsp.solargraph.setup({}) - -- lsp.sorbet.setup({}) lsp.rust_analyzer.setup({}) lsp.taplo.setup({}) lsp.yamlls.setup({}) - local border = { - { "┏", "FloatBorder" }, - { "━", "FloatBorder" }, - { "┓", "FloatBorder" }, - { "┃", "FloatBorder" }, - { "┛", "FloatBorder" }, - { "━", "FloatBorder" }, - { "┗", "FloatBorder" }, - { "┃", "FloatBorder" }, - } - + -- diagnostic settings vim.lsp.diagnostics = { signs = true, underline = true, @@ -110,18 +102,39 @@ return { severity_sort = { reverse = false }, } + -- custom signs local signs = { Error = ">>", Warn = "> ", Hint = "- ", Info = " " } for type, icon in pairs(signs) do local hl = "DiagnosticSign" .. type vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) end + -- borders on windows + local border = { + { "┏", "FloatBorder" }, + { "━", "FloatBorder" }, + { "┓", "FloatBorder" }, + { "┃", "FloatBorder" }, + { "┛", "FloatBorder" }, + { "━", "FloatBorder" }, + { "┗", "FloatBorder" }, + { "┃", "FloatBorder" }, + } + local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...) opts = opts or {} opts.border = opts.border or border return orig_util_open_floating_preview(contents, syntax, opts, ...) end + + -- auto format code on save + vim.api.nvim_create_autocmd("BufWritePre", { + pattern = { "*" }, + callback = function() + vim.lsp.buf.format() + end, + }) end, }, } diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index fe1ef0c..625b3f8 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -39,6 +39,33 @@ return { } require('telescope').load_extension('fzf') + + -- give telescope window if opened with no command + vim.api.nvim_create_autocmd('VimEnter', { + pattern = '*', + callback = function() + local arg = vim.api.nvim_eval('argv(0)') + if arg and (vim.fn.isdirectory(arg) ~= 0 or arg == "") then + vim.defer_fn(function() + local function is_git_repo() + vim.fn.system("git rev-parse --is-inside-work-tree") + return vim.v.shell_error == 0 + end + local function get_git_root() + local dot_git_path = vim.fn.finddir(".git", ".;") + return vim.fn.fnamemodify(dot_git_path, ":h") + end + local opts = {} + if is_git_repo() then + opts = { + cwd = get_git_root(), + } + end + require("telescope.builtin").find_files(opts) + end, 10) + end + end + }) end }, } diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua index b87674f..12fa589 100644 --- a/lua/plugins/treesitter.lua +++ b/lua/plugins/treesitter.lua @@ -10,7 +10,7 @@ return { sync_install = true, auto_install = true, highlight = { enable = true }, - indent = { enable = true }, + indent = { enable = false }, } end },