diff --git a/init.lua b/init.lua index caa33f9..1e23430 100644 --- a/init.lua +++ b/init.lua @@ -1,18 +1,18 @@ --- Bootstrap packer.nvim if not already installed -local ensure_packer = function() - local fn = vim.fn - local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" - if fn.empty(fn.glob(install_path)) > 0 then - fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }) - vim.cmd([[packadd packer.nvim]]) - return true - end - return false +-- Bootstrap lazy.nvim (the modern, maintained plugin manager) +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or vim.loop).fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", + lazypath, + }) end +vim.opt.rtp:prepend(lazypath) -local packer_bootstrap = ensure_packer() - --- Load user configuration files +-- ── Core configuration (no plugins needed) ─────────────────────────── require("user.options") require("user.keymaps") require("user.autocmds") @@ -21,105 +21,130 @@ require("user.files_utils") require("user.terminal") require("user.android") require("user.flutter") --- Plugin-dependent modules — wrapped in pcall so init doesn't crash when --- plugins aren't installed yet (e.g. during :PackerSync on a fresh setup). -pcall(require, "user.cmp") -pcall(require, "user.autopairs") -pcall(require, "user.telescope") -pcall(require, "user.gruvbox") -pcall(require, "user.lsp") -pcall(require, "user.typescript-tools") -pcall(require, "user.null-ls") -pcall(require, "user.treesitter") -pcall(require, "user.markdown") -pcall(require, "user.comment") -pcall(require, "user.trouble") -return require("packer").startup(function(use) - -- Let packer manage itself - use("wbthomason/packer.nvim") +-- Build plugin list — user modules can contribute additional specs +local test_plugins = require("user.test") - -- Completion framework - use("hrsh7th/nvim-cmp") - use("hrsh7th/cmp-buffer") - use("hrsh7th/cmp-path") - use("hrsh7th/cmp-nvim-lsp") - use("hrsh7th/cmp-nvim-lua") - use("saadparwaiz1/cmp_luasnip") - use("L3MON4D3/LuaSnip") +-- ── Plugin specifications ──────────────────────────────────────────── +require("lazy").setup(vim.list_extend({ - -- Load test plugin configuration - require("user.test")(use) + -- Colorscheme (high priority — loads before anything else) + { + "ellisonleao/gruvbox.nvim", + priority = 1000, + config = function() + require("user.gruvbox") + end, + }, - -- NERDTree plugin - use("preservim/nerdtree") + -- LSP + Mason (LSP servers, formatters, linters, debuggers) + { + "williamboman/mason-lspconfig.nvim", + dependencies = { + { "williamboman/mason.nvim", build = ":MasonUpdate" }, + "neovim/nvim-lspconfig", + "hrsh7th/cmp-nvim-lsp", -- ensure cmp capabilities are available + }, + config = function() + require("user.lsp") + end, + }, - -- Plugin for integrating formatters/linters (community fork of archived null-ls) - use("nvimtools/none-ls.nvim") + -- Completion framework + { + "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-nvim-lua", + "saadparwaiz1/cmp_luasnip", + "L3MON4D3/LuaSnip", + }, + config = function() + require("user.cmp") + end, + }, - -- Modern TypeScript integration (replaces archived nvim-lsp-ts-utils) - use({ - "pmizio/typescript-tools.nvim", - requires = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" }, - }) + -- Treesitter (syntax highlighting, folding, incremental selection) + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = function() + require("user.treesitter") + end, + }, - -- Treesitter - use("nvim-treesitter/nvim-treesitter") + -- Telescope (fuzzy finder — files, grep, buffers, help) + { + "nvim-telescope/telescope.nvim", + tag = "v0.1.9", + dependencies = { + "nvim-lua/plenary.nvim", + { + "nvim-telescope/telescope-fzf-native.nvim", + build = "make", + }, + }, + config = function() + require("user.telescope") + end, + }, - -- Auto pairs - use("windwp/nvim-autopairs") + -- Auto pairs (automatically close brackets, quotes, etc.) + { + "windwp/nvim-autopairs", + config = function() + require("user.autopairs") + end, + }, - -- LSP Configuration - use("neovim/nvim-lspconfig") + -- TypeScript / JavaScript LSP enhancements (organize imports, etc.) + { + "pmizio/typescript-tools.nvim", + dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" }, + config = function() + require("user.typescript-tools") + end, + }, - -- Java Language Server support - use("mfussenegger/nvim-jdtls") + -- Formatters & linters (community fork of archived null-ls) + { + "nvimtools/none-ls.nvim", + config = function() + require("user.null-ls") + end, + }, - -- Markdown Preview (optional) - use({ - "iamcco/markdown-preview.nvim", - run = function() - vim.fn["mkdp#util#install"]() - end, - }) + -- Java LSP (eclipse.jdt.ls integration) + "mfussenegger/nvim-jdtls", - use({ - "nvim-telescope/telescope.nvim", - tag = "0.1.8", - -- or , branch = '0.1.x', - requires = { { "nvim-lua/plenary.nvim" } }, - }) + -- Markdown preview (live preview in browser) + { + "iamcco/markdown-preview.nvim", + build = function() + vim.fn["mkdp#util#install"]() + end, + }, - -- Comment - use 'numToStr/Comment.nvim' + -- Comment (gc / gb to toggle comments in any language) + { + "numToStr/Comment.nvim", + config = function() + require("user.comment") + end, + }, - -- Trouble: workspace diagnostics panel - use { - "folke/trouble.nvim", - requires = { "nvim-tree/nvim-web-devicons" }, - } + -- Trouble (pretty diagnostics, references, quickfix panel) + { + "folke/trouble.nvim", + dependencies = { "nvim-tree/nvim-web-devicons" }, + config = function() + require("user.trouble") + end, + }, + -- NERDTree (file explorer sidebar) + "preservim/nerdtree", - -- Telescope FZF native - use({ - "nvim-telescope/telescope-fzf-native.nvim", - run = "make", - }) - - use({ "ellisonleao/gruvbox.nvim" }) - - use({ - "williamboman/mason.nvim", - config = function() - require("mason").setup() - end, - }) - - -- Mason LSPConfig for integrating Mason with nvim-lspconfig - use("williamboman/mason-lspconfig.nvim") - - -- Automatically install plugins on first run - if packer_bootstrap then - require("packer").sync() - end -end) +}, test_plugins)) diff --git a/jars/ktfmt.jar b/jars/ktfmt.jar deleted file mode 100644 index 9ca8572..0000000 Binary files a/jars/ktfmt.jar and /dev/null differ diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..8415122 --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,28 @@ +{ + "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" }, + "LuaSnip": { "branch": "master", "commit": "0abc8f390b278c3b4aabc4c004ac8a088b65cf24" }, + "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "cbc7b02bb99fae35cb42f514762b89b5126651ef" }, + "cmp-nvim-lua": { "branch": "main", "commit": "e3a22cb071eb9d6508a156306b102c45cd2d573d" }, + "cmp-path": { "branch": "main", "commit": "c642487086dbd9a93160e1679a1327be111cbc25" }, + "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, + "gruvbox.nvim": { "branch": "main", "commit": "154eb5ff5b96d0641307113fa385eaf0d36d9796" }, + "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" }, + "markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "67029ccdac1ef8941e13b826417bc0ffac24cc86" }, + "mason.nvim": { "branch": "main", "commit": "2a6940af80375532e5e9e7c1f2fc6319a1b7a69d" }, + "nerdtree": { "branch": "master", "commit": "690d061b591525890f1471c6675bcb5bdc8cdff9" }, + "none-ls.nvim": { "branch": "main", "commit": "01f8e62ea11603e59ad9ff7afcfa94fd183f76d6" }, + "nvim-autopairs": { "branch": "master", "commit": "7b9923abad60b903ece7c52940e1321d39eccc79" }, + "nvim-cmp": { "branch": "main", "commit": "2ffe79f1f021def8dd1fcd81deb16f1bb0d989f3" }, + "nvim-jdtls": { "branch": "master", "commit": "6e9d953f0b82bccdb834cfde0e893f3119c22592" }, + "nvim-lspconfig": { "branch": "master", "commit": "1c0d8f70dbc8827263eedc3cf7021ceba0f68689" }, + "nvim-treesitter": { "branch": "main", "commit": "7b6cc8949f9999c5ed91436cbe24aa5f99c42025" }, + "nvim-web-devicons": { "branch": "master", "commit": "2ae6958df7ced50baac5035cec0c15799eedfbf7" }, + "plenary.nvim": { "branch": "master", "commit": "74b06c6c75e4eeb3108ec01852001636d85a932b" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "b25b749b9db64d375d782094e2b9dce53ad53a40" }, + "telescope.nvim": { "branch": "master", "commit": "84b9ba066d1860f7a586ce9cd732fd6c4f77d1d9" }, + "trouble.nvim": { "branch": "main", "commit": "bd67efe408d4816e25e8491cc5ad4088e708a69a" }, + "typescript-tools.nvim": { "branch": "master", "commit": "c2f5910074103705661e9651aa841e0d7eea9932" }, + "vim-test": { "branch": "master", "commit": "2676d84c6901e484df00b5d728bd6a345d47ee12" } +} diff --git a/lua/user/lsp.lua b/lua/user/lsp.lua index a68b7fe..55dd236 100644 --- a/lua/user/lsp.lua +++ b/lua/user/lsp.lua @@ -17,10 +17,10 @@ require("mason-lspconfig").setup({ -- Remove "jdtls" from here to prevent the 'enable' (nil value) crash ensure_installed = { "pyright", - "typescript-language-server", + "ts_ls", "marksman", - "kotlin-language-server", - "svelte-language-server", + + "svelte", "gopls", }, }) @@ -43,7 +43,7 @@ require("user.lsp_servers.pyright") require("user.lsp_servers.ts_ls") require("user.lsp_servers.jdtls") require("user.lsp_servers.marksman") -require("user.lsp_servers.kotlin_ls") + require("user.lsp_servers.dartls") require("user.lsp_servers.svelte") require("user.lsp_servers.golang") diff --git a/lua/user/lsp_servers/dartls.lua b/lua/user/lsp_servers/dartls.lua index 6fa0e18..74c8ed2 100644 --- a/lua/user/lsp_servers/dartls.lua +++ b/lua/user/lsp_servers/dartls.lua @@ -3,7 +3,7 @@ local function get_dart_sdk_path() -- Try Flutter's bundled Dart SDK first - local flutter_dart = vim.fn.expand("~/flutter/bin/cache/dart-sdk/bin/dart") + local flutter_dart = vim.fn.expand("~/development/flutter/bin/cache/dart-sdk/bin/dart") if vim.fn.executable(flutter_dart) == 1 then return flutter_dart end diff --git a/lua/user/lsp_servers/jdtls.lua b/lua/user/lsp_servers/jdtls.lua index d328093..5cedd8d 100644 --- a/lua/user/lsp_servers/jdtls.lua +++ b/lua/user/lsp_servers/jdtls.lua @@ -3,7 +3,7 @@ local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") local capabilities = status_ok and cmp_nvim_lsp.default_capabilities(vim.lsp.protocol.make_client_capabilities()) or vim.lsp.protocol.make_client_capabilities() -local java_bin = "java" -- use java from PATH +local java_bin = "/usr/lib/jvm/java-21-openjdk-amd64/bin/java" -- jdtls requires Java 21+ local jdtls_path = vim.fn.stdpath("data") .. "/mason/packages/jdtls" local jdtls_launcher_jar = vim.fn.glob(jdtls_path .. "/plugins/org.eclipse.equinox.launcher_*.jar") local lombok_jar = jdtls_path .. "/lombok.jar" @@ -29,6 +29,7 @@ vim.lsp.config('jdtls', { }, capabilities = capabilities, -- In 0.11, use root_markers instead of a root_dir function + filetypes = { "java" }, root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" }, settings = { java = { diff --git a/lua/user/lsp_servers/kotlin_ls.lua b/lua/user/lsp_servers/kotlin_ls.lua deleted file mode 100644 index fd77285..0000000 --- a/lua/user/lsp_servers/kotlin_ls.lua +++ /dev/null @@ -1,87 +0,0 @@ --- Kotlin LSP = fwcd kotlin-language-server (installed via Mason). --- --- NOTE: the JetBrains `kotlin-lsp` (intellij-server) was tried but it imports --- Android Gradle modules with an EMPTY set of source sets, so it resolves --- nothing for Android (hover/definition/references all return empty). fwcd --- resolves the Gradle compile classpath itself and DOES navigate Android --- projects, so we use it here. (kotlin-lsp remains fine for plain Kotlin/JVM.) --- --- CPU/Memory notes for Android projects: --- - Formatting disabled in LSP capabilities — ktfmt in-process spawns a SECOND --- Kotlin compiler, doubling memory (OOMs even at 4GB). Formatting is handled --- externally by null-ls running ktfmt as a separate process. --- - Linting enabled — runs on the same compiler already loaded for completions, --- so no extra memory cost. Provides error diagnostics (red squiggles). --- - Semantic tokens disabled — extra compilation passes, not worth the CPU. --- - 500ms debounce reduces compilation frequency during typing. --- - Persistent tmpdir so the SQLite compilation cache survives across sessions. -local bin = vim.fn.expand("~/.local/share/nvim/mason/bin/kotlin-language-server") - -if vim.fn.executable(bin) == 0 then - vim.notify("kotlin-language-server not found — run :MasonInstall kotlin-language-server", - vim.log.levels.WARN) - return -end - --- Build capabilities, then strip formatting to prevent ktfmt OOMs. -local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") -local capabilities = status_ok and cmp_nvim_lsp.default_capabilities() or vim.lsp.protocol.make_client_capabilities() -capabilities.textDocument.formatting = nil -capabilities.textDocument.rangeFormatting = nil -capabilities.textDocument.onTypeFormatting = nil - --- 1. Configuration -vim.lsp.config('kotlin_language_server', { - cmd = { bin }, - filetypes = { "kotlin" }, - - -- Kotlin/Android projects are rooted at a Gradle build file or git repo. - -- vim.lsp.config expects callback form: function(bufnr, on_dir). - root_dir = function(bufnr, on_dir) - local fname = vim.api.nvim_buf_get_name(bufnr) - local root = vim.fs.root(fname, { - "settings.gradle.kts", - "settings.gradle", - "build.gradle.kts", - "build.gradle", - "pom.xml", - ".git", - }) - on_dir(root or vim.fs.dirname(fname)) - end, - - capabilities = capabilities, - - -- Strip formatting from the server's advertised capabilities. - -- client-side capabilities only prevent the server from expecting format - -- requests; server-side capabilities are what vim.lsp.buf.format() actually - -- checks. Without this, format-on-save routes through the LSP's ktfmt → - -- second Kotlin compiler → OOM. - on_attach = function(client) - client.server_capabilities.documentFormattingProvider = false - client.server_capabilities.documentRangeFormattingProvider = false - end, - - -- 6GB heap — Android classpath is large (163 deps + 320 source files). - -- Persistent tmpdir so the compilation cache survives across sessions. - -- Use Android Studio's JBR 21 — optimised GC/JIT for Kotlin workloads. - cmd_env = { - KOTLIN_LANGUAGE_SERVER_OPTS = "-Xmx6G -Xms512m -Djava.io.tmpdir=/home/prabhat/.cache/kotlin-ls-fwcd", - JAVA_HOME = "/opt/android-studio/jbr", - }, - - init_options = { - debounceTextChanges = 500, - }, - - settings = { - kotlin = { - linting = { enabled = true }, - completion = { enabled = true }, - semanticTokens = { enabled = false }, - }, - }, -}) - --- 2. Enable the server -vim.lsp.enable('kotlin_language_server') diff --git a/lua/user/null-ls.lua b/lua/user/null-ls.lua index 05e1275..3455ee9 100644 --- a/lua/user/null-ls.lua +++ b/lua/user/null-ls.lua @@ -22,18 +22,6 @@ local sources = { extra_args = { "--aosp" }, -- optional: use AOSP style formatting --command = "google-java-format", -- specify command if not in PATH }), - -- Kotlin formatting via ktfmt — runs as separate JVM, no OOM risk. - -- Custom formatter (not in null-ls builtins for this version). - { - name = "ktfmt", - method = null_ls.methods.FORMATTING, - filetypes = { "kotlin" }, - generator = null_ls.generator({ - command = "java", - args = { "-jar", "/home/prabhat/.config/nvim/jars/ktfmt.jar", "-" }, - to_stdin = true, - }), - }, -- YAML formatting via yamlfmt (Mason: yamlfmt) formatting.yamlfmt, -- XML formatting via xmllint (system package: libxml2-utils) diff --git a/lua/user/test.lua b/lua/user/test.lua index 692ecb2..50e85fa 100644 --- a/lua/user/test.lua +++ b/lua/user/test.lua @@ -1,7 +1,8 @@ -- lua/user/test.lua -return function() - -- Set up vim-test plugin - require("packer").use({ +-- Returns vim-test plugin spec for lazy.nvim + +return { + { "vim-test/vim-test", config = function() vim.cmd([[ @@ -14,5 +15,5 @@ return function() nmap t :TestVisit ]]) end, - }) -end + }, +} diff --git a/lua/user/treesitter.lua b/lua/user/treesitter.lua index c75d131..86f35d4 100644 --- a/lua/user/treesitter.lua +++ b/lua/user/treesitter.lua @@ -13,7 +13,7 @@ ts.setup({ "c", "cpp", "javascript", - "kotlin", + "go", "dart", "typescript",