-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Shubham Sourabh edited this page Apr 14, 2025
·
2 revisions
This document outlines the process and troubleshooting steps taken to configure Neovim based on kickstart.nvim for Java and Python development on Windows 11.
To have a functional Neovim environment with LSP support (autocompletion, diagnostics, go-to-definition), syntax highlighting (Treesitter), and formatting for Java and Python development.
- Neovim: Latest stable version (e.g., 0.10.x).
-
Git: For
lazy.nvimand plugin management. -
JDK 21 (or newer): Required to RUN
jdtls, even if working on older Java projects. Path needs to be configured specifically ininit.lua. -
JDK 1.8: Required for specific work projects (system
JAVA_HOMEpoints here). -
Python 3.x: With
pip. -
Visual Studio Build Tools: Crucially, requires the "Desktop development with C++" workload installed for the C/C++ compiler (
cl.exe). - (Optional but Recommended): Nerd Font installed and configured in the terminal (e.g., Windows Terminal).
This setup involved several specific challenges:
-
Problem:
nvim-treesitterrequires a C compiler to build language parsers (like Java, Python). Initially,:checkhealth nvim-treesitterreportedERROR cc executable not found. -
Solution:
- Installed Visual Studio Build Tools ensuring the "Desktop development with C++" workload was selected.
-
Critical Insight: The compiler (
cl.exe) is added to thePATHcorrectly only when using the Developer Prompt for VS (e.g., "Developer PowerShell for VS 2022"). Runningnvimfrom a standard Windows Terminal / PowerShell will not find the compiler by default. -
Resolution: Always launch
nvimfrom the Developer PowerShell for VS to ensure Treesitter can findcl.exeand build parsers.
-
Problem: Initially attempted to use
saghen/blink.cmp. This led to configuration errors (Each source... must have a "name") and internal health check errors (attempt to index a nil value).blink.cmpis not the standard completion engine used by Kickstart. -
Solution: Switched to the standard Kickstart completion engine,
hrsh7th/nvim-cmp.- Removed the
saghen/blink.cmpplugin block entirely frominit.lua. - Removed
saghen/blink.cmpfrom thedependencieslist ofnvim-lspconfig. - Ensured the default
hrsh7th/nvim-cmpblock (including its dependencies likecmp-nvim-lsp,LuaSnip,cmp_luasnip, etc., and itsconfig = function() ... endblock callingrequire('cmp').setup({...})) was present and active ininit.lua. - Updated the
capabilitiesvariable definition within thenvim-lspconfigconfig function to userequire('cmp_nvim_lsp').default_capabilities(). - Ensured this
capabilitiesvariable was passed to server setups in themason-lspconfighandlers.
- Removed the
-
Result: Completion errors were resolved. Note that
nvim-cmploads onInsertEnter, so it won't show in:checkhealthuntil triggered. Use<C-Space>for manual completion and<C-y>to accept suggestions (default Kickstart mappings).
-
Problem:
jdtlsfailed to start, with errors indicating it requires Java 17+ or 21+ to run. However, the systemJAVA_HOMEwas set to JDK 1.8 for compatibility with work projects. Runningjava -versionin the terminal showed JDK 21 was available viaPATH. -
Solution: Explicitly configure
lspconfigto launchjdtlsusing the desired JDK 21 installation, overridingJAVA_HOME.-
Find JDK 21 Path: Used PowerShell (
Get-ChildItem -Path "C:\Program Files\Java" -Filter "jdk-21*" ...) to locate the actual JDK 21 installation directory (e.g.,C:\Program Files\Java\jdk-21). The path to the executable is needed (e.g.,C:\Program Files\Java\jdk-21\bin\java.exe). Avoid Oracle'sjavapathsymlinks. -
Modify
init.lua: Added a specific handler for['jdtls']within therequire('mason-lspconfig').setup { handlers = { ... } }block. -
Set
cmd: Inside thejdtlshandler, defined thecmdtable, setting the first element to the full, correct path of the JDK 21java.exe(using double backslashes\\in the Lua string). Kept the standard-jar,-configuration, etc., arguments usingvim.fn.globto find the Mason-installedjdtlsfiles.
-
Find JDK 21 Path: Used PowerShell (
-
Result:
jdtlsnow successfully starts using JDK 21, ignoring the systemJAVA_HOME=1.8, and attaches to Java buffers.
-
Problem: After setting the correct Java 21 path,
jdtlsstill failed with a generic "Spawning language server ... failed" error. -
Solution: This was likely due to verifying paths and potentially reinstalling
jdtlsvia Mason (:Mason,Xonjdtls,ionjdtls). Ensuring the paths tojava.exe, the launcher JAR (org.eclipse.equinox.launcher_*.jar), and the configuration directory (config_win) used in thecmdtable were correct resolved this.
-
LSPs:
pyright(Python) andlua_ls(Lua) were also installed viamason-lspconfig. -
Formatting:
stevearc/conform.nvimis configured. Requires installing desired formatters (e.g.,stylua,black,isort,google-java-format) via Mason (:Mason) orpipand uncommenting/adding them in theformatters_by_fttable inconform's opts. -
Theme:
folke/tokyonight.nvimis used.
-
ripgrep(rg): Essential for Telescope'slive_grep. (Installed viawinget). -
fd: Improves Telescope file finding performance. (Installed viawinget). -
7-Zip: Needed bymason.nvimto extract.ziparchives (some LSPs/tools). Install viawinget install 7zip.7zip. -
make: Needed for optional native builds (e.g.,telescope-fzf-native,luasnipregex support). Install viachocoor MSYS2, or usenmakeavailable in the Developer Prompt.
- Neovim loads based on Kickstart.
- Treesitter highlighting works for Java/Python (when run from Developer Prompt).
- LSPs (
jdtls,pyright) attach successfully. Diagnostics appear. - Autocompletion (
nvim-cmp) is configured and should work onInsertEnter(trigger with<C-Space>, accept with<C-y>).
_Made with love and enthusiasm by vampirepapi_ ❤️🔥