diff --git a/nvim/init.lua b/nvim/init.lua index b56f20c..a0c3b4d 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -8,3 +8,5 @@ require 'dzu.keymaps' require 'dzu.plugins' require 'dzu.snippets' + +require 'dzu.lsp' diff --git a/nvim/lua/dzu/lsp.lua b/nvim/lua/dzu/lsp.lua new file mode 100644 index 0000000..b9491a4 --- /dev/null +++ b/nvim/lua/dzu/lsp.lua @@ -0,0 +1,52 @@ +local servers = { + "rust_analyzer", + "pyright", + "ts_ls", + "biome", + "clangd", + "lua_ls", + "tinymist", + "jdtls", + "html", + "dockerls", + "nil_ls", +} + +local is_ok, handlers = pcall(require, "dzu.lsp.handlers") +if not is_ok then + vim.notify("failed to initialize LSP handlers") + return +end +handlers.setup() + +local opts = { + capabilities = handlers.capabilities, +} + +for _, server in pairs(servers) do + server = vim.split(server, "@")[1] + + local is_ok, conf_opts = pcall(require, "dzu.lsp." .. server) + if not is_ok then + vim.notify("Failed to initialize config for " .. server) + goto continue + end + local opts0 = vim.tbl_deep_extend("force", opts, conf_opts) + + vim.lsp.config(server, opts0) + vim.lsp.enable(server, true) + ::continue:: +end + +-- -- format code on save +-- vim.api.nvim_create_autocmd({ "BufWritePre" }, { +-- pattern = { +-- "*.rs", -- rust sources +-- "*.py", -- python sources +-- "*.js", -- javascript sources +-- "*.html", -- html files +-- }, +-- callback = function(ev) +-- vim.lsp.buf.format() +-- end, +-- }) diff --git a/nvim/lua/dzu/lsp/biome.lua b/nvim/lua/dzu/lsp/biome.lua new file mode 100644 index 0000000..a564707 --- /dev/null +++ b/nvim/lua/dzu/lsp/biome.lua @@ -0,0 +1 @@ +return {} diff --git a/nvim/lua/dzu/lsp/clangd.lua b/nvim/lua/dzu/lsp/clangd.lua index bd86e02..ab99bfd 100644 --- a/nvim/lua/dzu/lsp/clangd.lua +++ b/nvim/lua/dzu/lsp/clangd.lua @@ -1,6 +1,6 @@ return { - filetypes = { "c", "h", "cpp" }, - single_file_support = true, + filetypes = { "c", "h", "cpp", "arduino" }, + root_markers = { ".git", "sketch.yaml" }, cmd = { "clangd", -- "-Wall", diff --git a/nvim/lua/dzu/lsp/dockerls.lua b/nvim/lua/dzu/lsp/dockerls.lua new file mode 100644 index 0000000..a564707 --- /dev/null +++ b/nvim/lua/dzu/lsp/dockerls.lua @@ -0,0 +1 @@ +return {} diff --git a/nvim/lua/dzu/lsp/init.lua b/nvim/lua/dzu/lsp/init.lua deleted file mode 100644 index 916aec8..0000000 --- a/nvim/lua/dzu/lsp/init.lua +++ /dev/null @@ -1,19 +0,0 @@ --- setup LSPs -local is_ok, _ = pcall(require, "dzu.lsp.mason") -if not is_ok then - vim.notify("failed to setup Mason") - return -end - --- -- format code on save --- vim.api.nvim_create_autocmd({ "BufWritePre" }, { --- pattern = { --- "*.rs", -- rust sources --- "*.py", -- python sources --- "*.js", -- javascript sources --- "*.html", -- html files --- }, --- callback = function(ev) --- vim.lsp.buf.format() --- end, --- }) diff --git a/nvim/lua/dzu/lsp/jdtls.lua b/nvim/lua/dzu/lsp/jdtls.lua index 26cf4c3..a3eeb6a 100644 --- a/nvim/lua/dzu/lsp/jdtls.lua +++ b/nvim/lua/dzu/lsp/jdtls.lua @@ -1,19 +1,41 @@ +local jdk_name = os.getenv("JDTLS_JDK_NAME") +local jdk_path = os.getenv("JDTLS_JDK_PATH") +local classpath = os.getenv("CLASSPATH") or "" +local jdtls_libs = {} + +for path in string.gmatch(classpath, "[^:]+") do + if string.len(path) == 0 then + -- empty path, nothing to do + goto continue + end + + if string.sub(path, -4) ~= ".jar" then + -- not a jar in path, skip + goto continue + end + + table.insert(jdtls_libs, path) + + ::continue:: +end + return { + cmd = { "jdtls", "--java-no-verify" }, + filetypes = { "java" }, + root_markers = { ".git", "build.xml" }, settings = { java = { configuration = { runtimes = { { - name = "openjdk 21.0.9", - path = "/usr/lib/jvm/java-21-openjdk/", + name = jdk_name, + path = jdk_path, default = true, } } }, project = { - referencedLibraries = { - './lib/*.jar', - }, + referencedLibraries = jdtls_libs, } } }, @@ -43,5 +65,4 @@ return { } }, init_options = {}, - root_markers = { "build.xml" }, } diff --git a/nvim/lua/dzu/lsp/lua_ls.lua b/nvim/lua/dzu/lsp/lua_ls.lua index a67daa5..7063c53 100644 --- a/nvim/lua/dzu/lsp/lua_ls.lua +++ b/nvim/lua/dzu/lsp/lua_ls.lua @@ -1,4 +1,7 @@ return { + cmd = { 'lua-language-server' }, + filetypes = { 'lua' }, + root_markers = { { '.luarc.json', '.luarc.jsonc' }, '.git' }, settings = { Lua = { runtime = { diff --git a/nvim/lua/dzu/lsp/mason.lua b/nvim/lua/dzu/lsp/mason.lua deleted file mode 100644 index 69a9752..0000000 --- a/nvim/lua/dzu/lsp/mason.lua +++ /dev/null @@ -1,85 +0,0 @@ -local settings = { - ui = { - border = "none", - icons = { - package_installed = "◍", - package_pending = "◍", - package_uninstalled = "◍", - }, - }, - log_level = vim.log.levels.INFO, - max_concurrent_installers = 4, -} -require("mason").setup(settings) - -local servers = { - { "rust_analyzer", "rust_analyzer" }, - { "pyright", "pyright" }, - { "ts_ls", nil }, - { "biome", nil }, - { "clangd", "clangd" }, - { "lua_ls", "lua_ls" }, - { "tinymist", "tinymist" }, - { nil, "jdtls" }, - { "html", nil }, - { "dockerls", nil }, -} -local ensure_installed = {} -local i = 1 -for _, s in pairs(servers) do - local s0 = s[1] - if s0 ~= nil then - table.insert(ensure_installed, i, s0) - i = i + 1 - vim.lsp.enable(s0, true) - end -end -for tool, _ in pairs(ADDITIONAL_MASON_TOOLS) do - table.insert(ensure_installed, i, tool) - i = i + 1 -end - -require("mason-tool-installer").setup({ - ensure_installed = ensure_installed, - auto_update = true, - run_on_start = true, -}) - -require("mason-lspconfig").setup({ - automatic_enable = true, - automatic_installation = true, -}) - -local config_servers = {} -for _, s in pairs(servers) do - local s1 = s[2] - if s1 ~= nil then - table.insert(config_servers, s1) - end -end - -local is_ok, handlers = pcall(require, "dzu.lsp.handlers") -if not is_ok then - vim.notify("failed to initialize LSP handlers") - return -end -handlers.setup() - -local opts = { - capabilities = handlers.capabilities, -} - -for _, server in pairs(config_servers) do - server = vim.split(server, "@")[1] - - local is_ok, conf_opts = pcall(require, "dzu.lsp." .. server) - if not is_ok then - vim.notify("Failed to initialize config for " .. server) - goto continue - end - local opts0 = vim.tbl_deep_extend("force", conf_opts, opts) - - vim.lsp.config(server, opts0) - vim.lsp.enable(server, true) - ::continue:: -end diff --git a/nvim/lua/dzu/lsp/nil_ls.lua b/nvim/lua/dzu/lsp/nil_ls.lua new file mode 100644 index 0000000..8e0c904 --- /dev/null +++ b/nvim/lua/dzu/lsp/nil_ls.lua @@ -0,0 +1,5 @@ +return { + cmd = { "nil" }, + root_markers = { { "flake.nix", "flake.lock" }, ".git" }, + filetypes = { "nix" }, +} diff --git a/nvim/lua/dzu/lsp/pyright.lua b/nvim/lua/dzu/lsp/pyright.lua index 7b93938..e8ed571 100644 --- a/nvim/lua/dzu/lsp/pyright.lua +++ b/nvim/lua/dzu/lsp/pyright.lua @@ -1,4 +1,7 @@ return { + cmd = { "pyright-langserver", "--stdio" }, + filetypes = { "python" }, + root_markers = { ".git" }, settings = { pyright = { disableLanguageServices = false, diff --git a/nvim/lua/dzu/lsp/rust_analyzer.lua b/nvim/lua/dzu/lsp/rust_analyzer.lua index 2d6a25f..2aa4cfb 100644 --- a/nvim/lua/dzu/lsp/rust_analyzer.lua +++ b/nvim/lua/dzu/lsp/rust_analyzer.lua @@ -1,4 +1,7 @@ return { + cmd = { "rust-analyzer" }, + filetypes = { "rust" }, + root_markers = { ".git", "Cargo.lock" }, settings = { ['rust-analyzer'] = { diagnostics = { @@ -19,7 +22,7 @@ return { enable = true -- show me bounds(?) }, termSearch = { - enable = true, -- nested completions? + enable = false, -- nested completions? }, }, hover = { diff --git a/nvim/lua/dzu/lsp/tinymist.lua b/nvim/lua/dzu/lsp/tinymist.lua index f6e4345..d46e3bc 100644 --- a/nvim/lua/dzu/lsp/tinymist.lua +++ b/nvim/lua/dzu/lsp/tinymist.lua @@ -10,6 +10,9 @@ vim.api.nvim_create_user_command("OpenPdf", function() end, {}) return { + cmd = { "tinymist" }, + filetypes = { "typst" }, + root_markers = { ".git", "main.typ" }, settings = { formatterMode = "typstyle", exportPdf = "onType", diff --git a/nvim/lua/dzu/lsp/ts_ls.lua b/nvim/lua/dzu/lsp/ts_ls.lua new file mode 100644 index 0000000..a564707 --- /dev/null +++ b/nvim/lua/dzu/lsp/ts_ls.lua @@ -0,0 +1 @@ +return {} diff --git a/nvim/lua/dzu/options.lua b/nvim/lua/dzu/options.lua index dff4314..8d40466 100644 --- a/nvim/lua/dzu/options.lua +++ b/nvim/lua/dzu/options.lua @@ -58,6 +58,9 @@ local options = { -- clipboard clipboard = 'unnamedplus', + + -- no folding + foldenable = false, } for k, v in pairs(options) do diff --git a/nvim/lua/dzu/plugins/lsp.lua b/nvim/lua/dzu/plugins/lsp.lua deleted file mode 100644 index a6c64f7..0000000 --- a/nvim/lua/dzu/plugins/lsp.lua +++ /dev/null @@ -1,11 +0,0 @@ -return { - "mason-org/mason-lspconfig.nvim", - dependencies = { - "mason-org/mason.nvim", - "neovim/nvim-lspconfig", - -- lsp completions - "hrsh7th/cmp-nvim-lsp", - 'nvim-java/nvim-java', - }, - lazy = false, -} diff --git a/nvim/lua/dzu/plugins/mason-tools.lua b/nvim/lua/dzu/plugins/mason-tools.lua deleted file mode 100644 index cced0fc..0000000 --- a/nvim/lua/dzu/plugins/mason-tools.lua +++ /dev/null @@ -1,29 +0,0 @@ -local function config() - local is_ok, _ = pcall(require, "mason-tool-installer") - if not is_ok then - vim.notify("Failed to setup mason tools") - return - end - - local is_ok, _ = pcall(require, "dzu.lsp") - if not is_ok then - vim.notify("failed to setup lsp") - return - end -end - -return { - "WhoIsSethDaniel/mason-tool-installer.nvim", - dependencies = { - "mason-org/mason-lspconfig.nvim", - }, - config = config, - lazy = false, - opts = { - integrations = { - ["mason-lspconfig"] = true, - ["mason-null-ls"] = false, - ["mason-nvim-dap"] = false, - }, - }, -} diff --git a/nvim/lua/dzu/plugins/mason.lua b/nvim/lua/dzu/plugins/mason.lua deleted file mode 100644 index 08a7e84..0000000 --- a/nvim/lua/dzu/plugins/mason.lua +++ /dev/null @@ -1,4 +0,0 @@ -return { - "mason-org/mason.nvim", - opts = {} -} diff --git a/nvim/lua/dzu/plugins/nvim-cmp.lua b/nvim/lua/dzu/plugins/nvim-cmp.lua index d902967..844958a 100644 --- a/nvim/lua/dzu/plugins/nvim-cmp.lua +++ b/nvim/lua/dzu/plugins/nvim-cmp.lua @@ -203,6 +203,7 @@ end return { "hrsh7th/nvim-cmp", dependencies = { + "cmp-nvim-lsp", "saadparwaiz1/cmp_luasnip", { "L3MON4D3/LuaSnip", diff --git a/nvim/lua/dzu/plugins/nvim-java.lua b/nvim/lua/dzu/plugins/nvim-java.lua deleted file mode 100644 index 4231beb..0000000 --- a/nvim/lua/dzu/plugins/nvim-java.lua +++ /dev/null @@ -1,56 +0,0 @@ -return { - 'nvim-java/nvim-java', - config = function() - require('java').setup({ - -- Startup checks - checks = { - nvim_version = true, -- Check Neovim version - nvim_jdtls_conflict = true, -- Check for nvim-jdtls conflict - }, - - -- JDTLS configuration - jdtls = { - version = '1.54.0', - }, - - -- Extensions - lombok = { - enable = false, - version = '1.18.40', - }, - - java_test = { - enable = false, - version = '0.40.1', - }, - - java_debug_adapter = { - enable = false, - version = '0.58.2', - }, - - spring_boot_tools = { - enable = false, - version = '1.55.1', - }, - - -- JDK installation - jdk = { - auto_install = false, - version = '17', - }, - - -- Logging - log = { - use_console = false, - use_file = true, - level = 'info', - log_file = vim.fn.stdpath('state') .. '/nvim-java.log', - max_lines = 1000, - show_location = false, - }, - }) - -- vim.lsp.enable('jdtls') - end, - lazy = false, -} diff --git a/nvim/lua/dzu/plugins/tree-sitter.lua b/nvim/lua/dzu/plugins/tree-sitter.lua index 4be5159..3c4db1c 100644 --- a/nvim/lua/dzu/plugins/tree-sitter.lua +++ b/nvim/lua/dzu/plugins/tree-sitter.lua @@ -2,7 +2,7 @@ return { "nvim-treesitter/nvim-treesitter", - branch = "master", + branch = "main", build = ':TSUpdate', lazy = false, } diff --git a/nvim/lua/dzu/syntax.lua b/nvim/lua/dzu/syntax.lua index 0a9eefc..66fd7fd 100644 --- a/nvim/lua/dzu/syntax.lua +++ b/nvim/lua/dzu/syntax.lua @@ -1,89 +1,73 @@ local M = {} function M.setup() - local is_ok, tree_sitter_config = pcall(require, "nvim-treesitter.configs") + local is_ok, tree_sitter = pcall(require, "nvim-treesitter") if not is_ok then vim.notify("couldn't find tree sitter") return end - local cfg = { + tree_sitter.setup() + + local is_ok, tree_sitter_config = pcall(require, "nvim-treesitter.config") + if not is_ok then + vim.notify("couldn't find tree sitter config") + return + end + + local ensure_installed = { "bash", "c", - { "comment", nil }, + "comment", "csv", - { "dockerfile", nil }, + "dockerfile", "fish", - { "gitignore", "gitignore" }, - { "haskell", "hs" }, + "gitignore", + "haskell", "html", - { "javascript", "js" }, - { "typescript", "ts" }, + "javascript", + "typescript", "tsx", "json", "lua", - { "luadoc", nil }, - { "make", nil }, - { "markdown", "md" }, - { "markdown_inline", "md" }, - { "python", "py" }, - { "rust", "rs" }, + "luadoc", + "make", + "markdown", + "markdown_inline", + "python", + "rust", "sql", "toml", - { "vim", nil }, - { "vimdoc", nil }, + "vim", + "vimdoc", "xml", "nu", "java", "yaml", + "arduino", } - local langs = {} - local li = 1 - local pattern = {} - local pi = 1 - for _, spec in pairs(cfg) do - if type(spec) == "table" then - table.insert(langs, li, spec[1]) - li = li + 1 - if type(spec[2]) ~= "nil" then - table.insert(pattern, pi, "*." .. spec[2]) - pi = pi + 1 - end - else - table.insert(langs, li, spec) - li = li + 1 - table.insert(pattern, pi, "*." .. spec) - pi = pi + 1 - end - end - table.insert(pattern, pi, "Dockerfile*") - pi = pi + 1 - table.insert(pattern, pi, "Cargo.lock") - pi = pi + 1 - table.insert(pattern, pi, "makefile*") - pi = pi + 1 - table.insert(pattern, pi, "Makefile*") - pi = pi + 1 + -- src: https://www.qu8n.com/posts/treesitter-migration-guide-for-nvim-0-12 + local already_installed = require('nvim-treesitter.config').get_installed() + local install = vim.iter(ensure_installed) + :filter(function(parser) + return not vim.tbl_contains(already_installed, parser) + end) + :totable() + tree_sitter.install(install) - local opts = { - ensure_installed = langs, - highlight = { - enable = true, -- false will disable the whole extension - }, - } - tree_sitter_config.setup(opts) + vim.treesitter.language.register("xml", "ant") vim.cmd.TSUpdate() - vim.api.nvim_create_autocmd('BufWinEnter', { - pattern = pattern, + vim.api.nvim_create_autocmd('FileType', { callback = function() - vim.treesitter.start() + -- Enable treesitter highlighting and disable regex syntax + pcall(vim.treesitter.start) + -- Enable treesitter-based indentation + vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" end, }) - - vim.treesitter.language.register("xml", "ant") end return M