diff --git a/init.lua b/init.lua index aff5250e921..9f0c796986e 100644 --- a/init.lua +++ b/init.lua @@ -99,7 +99,7 @@ do vim.g.maplocalleader = ' ' -- Set to true if you have a Nerd Font installed and selected in the terminal - vim.g.have_nerd_font = false + vim.g.have_nerd_font = true -- [[ Setting options ]] -- See `:help vim.o` @@ -371,6 +371,7 @@ do spec = { { 's', group = '[S]earch', mode = { 'n', 'v' } }, { 't', group = '[T]oggle' }, + { 'l', group = '[L]aTeX' }, -- VimTeX maps (see lua/custom/plugins/vimtex.lua) { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, -- Enable gitsigns recommended keymaps first { 'gr', group = 'LSP Actions', mode = { 'n' } }, }, @@ -705,6 +706,38 @@ do stylua = {}, -- Used to format Lua code + -- Java: jdtls is installed via Mason (it's a key here so mason-tool-installer + -- picks it up), but its LSP config and `vim.lsp.enable` are owned by nvim-java + -- (see lua/custom/plugins/nvim-java.lua). We therefore SKIP jdtls in the + -- config/enable loop below so nvim-java's jdtls bootstrap is the one that wins + -- and there is no competing vanilla jdtls setup. + jdtls = {}, + + -- ty: Astral's Python type checker. Not yet shipped by nvim-lspconfig, so we + -- define the whole config here (ported from the old `lspconfig.configs.ty` + -- approach to the new `vim.lsp.config` API). Installed separately via uv, so + -- it is excluded from Mason below. + ty = { + cmd = { 'ty', 'server' }, + filetypes = { 'python' }, + root_markers = { 'pyproject.toml', 'ty.toml', '.git' }, + }, + + -- ruff: Python linter/formatter LSP. nvim-lspconfig ships the base `ruff` + -- config (cmd, etc.); this only overlays init_options. Installed separately + -- via uv, so it is excluded from Mason below. + ruff = { + init_options = { + settings = { + fixAll = true, + }, + }, + }, + + -- texlab: LaTeX language server (completion/refs/diagnostics). VimTeX does not + -- provide this. Installed via Mason. + texlab = {}, + -- Special Lua Config, as recommended by neovim help docs lua_ls = { on_init = function(client) @@ -758,6 +791,9 @@ do -- -- You can press `g?` for help in this menu. local ensure_installed = vim.tbl_keys(servers or {}) + -- ty and ruff are installed separately via uv (~/.local/bin), so exclude them + -- from Mason auto-install. + ensure_installed = vim.tbl_filter(function(name) return name ~= 'ty' and name ~= 'ruff' end, ensure_installed) vim.list_extend(ensure_installed, { -- You can add other tools here that you want Mason to install }) @@ -765,8 +801,13 @@ do require('mason-tool-installer').setup { ensure_installed = ensure_installed } for name, server in pairs(servers) do - vim.lsp.config(name, server) - vim.lsp.enable(name) + -- jdtls is configured and enabled by nvim-java (lua/custom/plugins/nvim-java.lua), + -- which must run `require('java').setup()` before `vim.lsp.enable('jdtls')`. + -- Skip it here to avoid a second, competing jdtls setup. + if name ~= 'jdtls' then + vim.lsp.config(name, server) + vim.lsp.enable(name) + end end end @@ -796,12 +837,20 @@ do }, -- You can also specify external formatters in here. formatters_by_ft = { - -- rust = { 'rustfmt' }, - -- Conform can also run multiple formatters sequentially - -- python = { "isort", "black" }, - -- + lua = { 'stylua' }, + -- ruff handles BOTH import-sorting and formatting (black/isort are not + -- installed; ruff is). Organize imports first, then format. + python = { 'ruff_organize_imports', 'ruff_format' }, -- You can use 'stop_after_first' to run the first available formatter from the list - -- javascript = { "prettierd", "prettier", stop_after_first = true }, + javascript = { 'prettierd', 'prettier', stop_after_first = true }, + -- conform matches the lowercase `vim.bo.filetype`, so the key must be `sql` + -- (an uppercase `SQL` key would never fire). The formatter id is + -- `sql_formatter` (conform's name); it wraps the `sql-formatter` executable. + sql = { 'sql_formatter' }, + -- Wire in installed-but-previously-unused Mason tools: + java = { 'google-java-format' }, + tex = { 'latexindent' }, + plaintex = { 'latexindent' }, }, } @@ -904,7 +953,7 @@ do vim.pack.add { { src = gh 'nvim-treesitter/nvim-treesitter', version = 'main' } } -- Ensure basic parsers are installed - local parsers = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' } + local parsers = { 'bash', 'c', 'diff', 'html', 'latex', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' } require('nvim-treesitter').install(parsers) ---@param buf integer @@ -966,17 +1015,17 @@ do -- Here are some example plugins that I've included in the Kickstart repository. -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- - -- require 'kickstart.plugins.debug' - -- require 'kickstart.plugins.indent_line' - -- require 'kickstart.plugins.lint' - -- require 'kickstart.plugins.autopairs' - -- require 'kickstart.plugins.neo-tree' - -- require 'kickstart.plugins.gitsigns' -- adds gitsigns recommended keymaps + require 'kickstart.plugins.debug' + require 'kickstart.plugins.indent_line' + require 'kickstart.plugins.lint' + require 'kickstart.plugins.autopairs' + require 'kickstart.plugins.neo-tree' + require 'kickstart.plugins.gitsigns' -- adds gitsigns recommended keymaps -- NOTE: You can add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- require 'custom.plugins' + require 'custom.plugins' end -- The line beneath this is called `modeline`. See `:help modeline` diff --git a/lua/custom/plugins/nvim-java.lua b/lua/custom/plugins/nvim-java.lua new file mode 100644 index 00000000000..452a1a39eec --- /dev/null +++ b/lua/custom/plugins/nvim-java.lua @@ -0,0 +1,29 @@ +-- nvim-java: full Java IDE layer on top of jdtls (tests, DAP, refactors, Spring Boot). +-- https://github.com/nvim-java/nvim-java +-- +-- This file is loaded by the custom-plugins loader (lua/custom/plugins/init.lua), +-- which runs in Section 10 of init.lua -- AFTER the LSP section (Section 6). The LSP +-- section deliberately SKIPS jdtls in its `vim.lsp.config`/`vim.lsp.enable` loop, so +-- this is the single place jdtls is configured and enabled. That guarantees the +-- required order (`require('java').setup()` before `vim.lsp.enable('jdtls')`) and +-- avoids a second, competing vanilla jdtls setup. +-- +-- Requirements (nvim-java README, vim.pack install): Neovim 0.11.5+. jdtls, +-- java-debug-adapter and java-test are provided via Mason -- jdtls from the LSP +-- section's mason-tool-installer, java-debug-adapter + java-test from +-- lua/kickstart/plugins/debug.lua (mason-nvim-dap). nvim-dap and nui.nvim are also +-- pulled in by debug.lua / neo-tree.lua respectively; re-listing them here is +-- idempotent and keeps this spec self-contained per the README. +vim.pack.add { + { src = 'https://github.com/JavaHello/spring-boot.nvim', version = '218c0c26c14d99feca778e4d13f5ec3e8b1b60f0' }, + 'https://github.com/MunifTanjim/nui.nvim', + 'https://github.com/mfussenegger/nvim-dap', + 'https://github.com/nvim-java/nvim-java', +} + +-- Must run BEFORE jdtls is enabled: it patches the jdtls config so the language +-- server is launched with the java-test / java-debug-adapter bundles. +require('java').setup() + +-- Enable jdtls using the config nvim-java just registered (the new Neovim 0.11+ API). +vim.lsp.enable 'jdtls' diff --git a/lua/custom/plugins/vimtex.lua b/lua/custom/plugins/vimtex.lua new file mode 100644 index 00000000000..5ad52dada66 --- /dev/null +++ b/lua/custom/plugins/vimtex.lua @@ -0,0 +1,27 @@ +-- VimTeX: LaTeX support (compile, view, errors) +-- https://github.com/lervag/vimtex +-- +-- Ported from the user's lazy.nvim spec (lazy = false) to this base's `vim.pack` +-- imperative style. VimTeX reads its `vim.g.vimtex_*` settings when it is sourced, +-- so we set them BEFORE `vim.pack.add` loads the plugin (the equivalent of the old +-- lazy `init` hook). + +-- Viewer settings (adjust based on your PDF viewer) +vim.g.vimtex_view_method = 'zathura' -- Use 'skim' on macOS, 'sumatra' on Windows, etc. + +-- Compiler settings +vim.g.vimtex_compiler_method = 'latexmk' -- Default compiler backend + +-- Optional: Disable some features if you don't need them +vim.g.vimtex_quickfix_enabled = 1 -- Enable quickfix window for errors +vim.g.vimtex_syntax_enabled = 1 -- Syntax highlighting (works with Tree-sitter too) + +-- Set TeX flavor (usually not needed, but good to know) +vim.g.tex_flavor = 'latex' + +vim.pack.add { 'https://github.com/lervag/vimtex' } + +-- LaTeX keymaps (which-key group label is defined in init.lua: `l` = [L]aTeX) +vim.keymap.set('n', 'll', 'VimtexCompile', { desc = 'Compile LaTeX' }) +vim.keymap.set('n', 'lv', 'VimtexView', { desc = 'View PDF' }) +vim.keymap.set('n', 'le', 'VimtexErrors', { desc = 'Show Errors' }) diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index db5448c2cfc..b7fd7bf0480 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -42,6 +42,8 @@ require('mason-nvim-dap').setup { ensure_installed = { -- Update this to ensure that you have the debuggers for the langs you want 'delve', + 'java-debug-adapter', + 'java-test', }, } diff --git a/lua/kickstart/plugins/lint.lua b/lua/kickstart/plugins/lint.lua index d63054452fd..d757185fefc 100644 --- a/lua/kickstart/plugins/lint.lua +++ b/lua/kickstart/plugins/lint.lua @@ -4,7 +4,9 @@ vim.pack.add { 'https://github.com/mfussenegger/nvim-lint' } local lint = require 'lint' lint.linters_by_ft = { - markdown = { 'markdownlint' }, -- Make sure to install `markdownlint` via mason / npm + -- Only enable markdownlint if it is actually installed (it is not installed here), + -- otherwise nvim-lint errors on every markdown buffer. + markdown = vim.fn.executable 'markdownlint' == 1 and { 'markdownlint' } or {}, } -- To allow other plugins to add linters to require('lint').linters_by_ft,