update
This commit is contained in:
parent
132854cc0c
commit
5793c3da7f
9 changed files with 176 additions and 129 deletions
|
|
@ -1,13 +1,33 @@
|
||||||
-- Load language server configuration
|
-- 1. Setup Mason first
|
||||||
|
require("mason").setup()
|
||||||
|
require("mason-lspconfig").setup({
|
||||||
|
-- Remove "jdtls" from here to prevent the 'enable' (nil value) crash
|
||||||
|
ensure_installed = {
|
||||||
|
"pyright",
|
||||||
|
"ts_ls",
|
||||||
|
"marksman",
|
||||||
|
"kotlin_language_server",
|
||||||
|
"graphql"
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
-- 2. Global LSP Attach (The modern way to handle keymaps)
|
||||||
|
vim.api.nvim_create_autocmd('LspAttach', {
|
||||||
|
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
|
||||||
|
callback = function(ev)
|
||||||
|
local opts = { buffer = ev.buf }
|
||||||
|
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
|
||||||
|
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
|
||||||
|
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
|
||||||
|
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- 3. Load your modernized server configs
|
||||||
|
-- These files should now use vim.lsp.config and vim.lsp.enable
|
||||||
require("user.lsp_servers.pyright")
|
require("user.lsp_servers.pyright")
|
||||||
require("user.lsp_servers.ts_ls")
|
require("user.lsp_servers.ts_ls")
|
||||||
require("user.lsp_servers.jdtls")
|
require("user.lsp_servers.jdtls")
|
||||||
require("user.lsp_servers.marksman")
|
require("user.lsp_servers.marksman")
|
||||||
require("user.lsp_servers.kotlin_ls")
|
require("user.lsp_servers.kotlin_ls")
|
||||||
require("user.lsp_servers.graphql")
|
require("user.lsp_servers.graphql")
|
||||||
|
|
||||||
-- Mason setup
|
|
||||||
require("mason").setup()
|
|
||||||
require("mason-lspconfig").setup({
|
|
||||||
ensure_installed = { "pyright", "ts_ls", "jdtls", "marksman", "kotlin_language_server" }, -- Ensure Kotlin LSP is installed
|
|
||||||
})
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,21 @@
|
||||||
local lspconfig = require("lspconfig")
|
-- 1. Configuration
|
||||||
|
vim.lsp.config('graphql', {
|
||||||
|
cmd = { "graphql-lsp", "server", "-m", "stream" },
|
||||||
|
filetypes = { "graphql", "gql", "javascript", "typescript", "typescriptreact", "javascriptreact" },
|
||||||
|
|
||||||
lspconfig.graphql.setup({
|
-- This ensures GraphQL only starts if it finds a config file
|
||||||
capabilities = require("cmp_nvim_lsp").default_capabilities(),
|
root_markers = {
|
||||||
filetypes = { "graphql", "gql", "javascript", "typescript" },
|
".graphqlrc",
|
||||||
|
".graphqlrc.json",
|
||||||
|
".graphqlrc.yaml",
|
||||||
|
".graphqlrc.yml",
|
||||||
|
"graphql.config.json",
|
||||||
|
"graphql.config.yaml",
|
||||||
|
"graphql.config.yml"
|
||||||
|
},
|
||||||
|
|
||||||
|
capabilities = require("cmp_nvim_lsp").default_capabilities(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- 2. Enable the server
|
||||||
|
vim.lsp.enable('graphql')
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
local lspconfig = require("lspconfig")
|
-- 1. Setup paths and capabilities
|
||||||
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
|
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||||
|
|
||||||
-- Java binary (ensure it's Java 21)
|
|
||||||
local java_bin = "/usr/lib/jvm/java-21-openjdk/bin/java"
|
local java_bin = "/usr/lib/jvm/java-21-openjdk/bin/java"
|
||||||
|
local jdtls_path = vim.fn.stdpath("data") .. "/mason/packages/jdtls"
|
||||||
-- Find JDTLS and Lombok paths dynamically
|
|
||||||
local jdtls_path = "/home/prabhat/.local/share/nvim/mason/packages/jdtls"
|
|
||||||
local jdtls_launcher_jar = vim.fn.glob(jdtls_path .. "/plugins/org.eclipse.equinox.launcher_*.jar")
|
local jdtls_launcher_jar = vim.fn.glob(jdtls_path .. "/plugins/org.eclipse.equinox.launcher_*.jar")
|
||||||
local lombok_jar = vim.fn.glob(jdtls_path .. "/lombok.jar")
|
local lombok_jar = jdtls_path .. "/lombok.jar"
|
||||||
|
|
||||||
lspconfig.jdtls.setup({
|
-- 2. Define the configuration
|
||||||
|
vim.lsp.config('jdtls', {
|
||||||
cmd = {
|
cmd = {
|
||||||
java_bin,
|
java_bin,
|
||||||
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
|
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
|
||||||
|
|
@ -17,22 +14,19 @@ lspconfig.jdtls.setup({
|
||||||
"-Declipse.product=org.eclipse.jdt.ls.core.product",
|
"-Declipse.product=org.eclipse.jdt.ls.core.product",
|
||||||
"-Dlog.protocol=true",
|
"-Dlog.protocol=true",
|
||||||
"-Dlog.level=INFO",
|
"-Dlog.level=INFO",
|
||||||
"-Xmx2G", -- Max heap size
|
"-Xmx2G",
|
||||||
"-Xms256m", -- Min heap size
|
"-Xms256m",
|
||||||
"--add-modules=ALL-SYSTEM",
|
"--add-modules=ALL-SYSTEM",
|
||||||
"--add-opens", "java.base/java.util=ALL-UNNAMED",
|
"--add-opens", "java.base/java.util=ALL-UNNAMED",
|
||||||
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
|
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
|
||||||
"-javaagent:" .. lombok_jar, -- Lombok support
|
"-javaagent:" .. lombok_jar,
|
||||||
"-jar", jdtls_launcher_jar, -- JDTLS launcher
|
"-jar", jdtls_launcher_jar,
|
||||||
"-configuration", jdtls_path .. "/config_linux",
|
"-configuration", jdtls_path .. "/config_linux",
|
||||||
"-data", vim.fn.stdpath("data") .. "/jdtls-workspace/" .. vim.fn.fnamemodify(vim.loop.cwd(), ":p:h:t"),
|
"-data", vim.fn.stdpath("data") .. "/jdtls-workspace/" .. vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t"),
|
||||||
},
|
},
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
root_dir = function()
|
-- In 0.11, use root_markers instead of a root_dir function
|
||||||
return vim.fs.dirname(
|
root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" },
|
||||||
vim.fs.find({ ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" }, { upward = true })[1]
|
|
||||||
)
|
|
||||||
end,
|
|
||||||
settings = {
|
settings = {
|
||||||
java = {
|
java = {
|
||||||
completion = {
|
completion = {
|
||||||
|
|
@ -51,23 +45,10 @@ lspconfig.jdtls.setup({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
import = {
|
import = {
|
||||||
exclusions = {
|
maven = { enabled = true, downloadSources = true },
|
||||||
"**/internal/**",
|
gradle = { enabled = true },
|
||||||
},
|
|
||||||
maven = {
|
|
||||||
enabled = true,
|
|
||||||
downloadSources = true,
|
|
||||||
},
|
|
||||||
gradle = {
|
|
||||||
enabled = true,
|
|
||||||
},
|
|
||||||
settings = {
|
settings = {
|
||||||
importOrder = {
|
importOrder = { "java", "javax", "org", "com" },
|
||||||
"java",
|
|
||||||
"javax",
|
|
||||||
"org",
|
|
||||||
"com",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
inlayHints = {
|
inlayHints = {
|
||||||
|
|
@ -83,3 +64,5 @@ lspconfig.jdtls.setup({
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- 3. Enable the server
|
||||||
|
vim.lsp.enable('jdtls')
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,22 @@
|
||||||
-- lua/user/lsp_servers/kotlin_ls.lua
|
-- 1. Configuration
|
||||||
|
vim.lsp.config('kotlin_language_server', {
|
||||||
|
cmd = { "kotlin-language-server" },
|
||||||
|
filetypes = { "kotlin" },
|
||||||
|
-- Kotlin projects are usually defined by build files or git
|
||||||
|
root_markers = { "settings.gradle", "settings.gradle.kts", "pom.xml", ".git" },
|
||||||
|
|
||||||
local lspconfig = require("lspconfig")
|
-- flags in lspconfig setup are now part of the general config table
|
||||||
|
init_options = {
|
||||||
|
debounceTextChanges = 150,
|
||||||
|
},
|
||||||
|
|
||||||
-- Setup the Kotlin language server
|
settings = {
|
||||||
lspconfig.kotlin_language_server.setup({
|
kotlin = {
|
||||||
cmd = { "kotlin-language-server" }, -- The command to start the server
|
linting = { enabled = true },
|
||||||
on_attach = function(client, bufnr)
|
completion = { enabled = true },
|
||||||
-- Key mappings for LSP functions
|
},
|
||||||
local opts = { noremap = true, silent = true }
|
},
|
||||||
local function buf_set_keymap(...)
|
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, ...)
|
|
||||||
end
|
|
||||||
|
|
||||||
buf_set_keymap("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)
|
|
||||||
buf_set_keymap("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>", opts)
|
|
||||||
buf_set_keymap("n", "<leader>rn", "<Cmd>lua vim.lsp.buf.rename()<CR>", opts)
|
|
||||||
end,
|
|
||||||
flags = {
|
|
||||||
debounce_text_changes = 150,
|
|
||||||
},
|
|
||||||
settings = {
|
|
||||||
kotlin = {
|
|
||||||
linting = { enabled = true },
|
|
||||||
completion = { enabled = true },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- 2. Enable the server
|
||||||
|
vim.lsp.enable('kotlin_language_server')
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
local lspconfig = require("lspconfig")
|
-- 1. Configuration
|
||||||
-- Setup for Markdown LSP (Marksman)
|
vim.lsp.config('marksman', {
|
||||||
lspconfig.marksman.setup({
|
cmd = { "marksman", "server" },
|
||||||
-- Add additional settings here
|
filetypes = { "markdown", "markdown.md" },
|
||||||
filetypes = { "markdown", "md" },
|
-- Marksman looks for a .marksman.toml or a .git directory to define the project root
|
||||||
|
root_markers = { ".marksman.toml", ".git" },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- 2. Enable the server
|
||||||
|
-- Note: You don't need to redefine the LspAttach autocmd here
|
||||||
|
-- if you already added it to your pyright or ts_ls files.
|
||||||
|
vim.lsp.enable('marksman')
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,32 @@
|
||||||
local lspconfig = require("lspconfig")
|
-- Define the configuration for pyright
|
||||||
|
vim.lsp.config('pyright', {
|
||||||
|
-- The command to start the server (usually the same as lspconfig's default)
|
||||||
|
cmd = { "pyright-langserver", "--stdio" },
|
||||||
|
filetypes = { "python" },
|
||||||
|
root_markers = { ".git", "pyproject.toml", "setup.py", "requirements.txt" },
|
||||||
|
|
||||||
lspconfig.pyright.setup({
|
-- Your custom settings move here
|
||||||
on_attach = function(client, bufnr)
|
settings = {
|
||||||
-- Custom keymaps and commands for pyright
|
python = {
|
||||||
end,
|
analysis = {
|
||||||
settings = {
|
autoSearchPaths = true,
|
||||||
python = {
|
useLibraryCodeForTypes = true,
|
||||||
analysis = {
|
},
|
||||||
autoSearchPaths = true,
|
},
|
||||||
useLibraryCodeForTypes = true,
|
},
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Handle the on_attach logic
|
||||||
|
vim.api.nvim_create_autocmd('LspAttach', {
|
||||||
|
callback = function(args)
|
||||||
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||||
|
if client and client.name == 'pyright' then
|
||||||
|
local bufnr = args.buf
|
||||||
|
-- Your custom keymaps and commands for pyright go here
|
||||||
|
-- Example: vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = bufnr })
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Finally, enable the server
|
||||||
|
vim.lsp.enable('pyright')
|
||||||
|
|
|
||||||
|
|
@ -1,41 +1,53 @@
|
||||||
local lspconfig = require("lspconfig")
|
-- 1. Configuration
|
||||||
|
vim.lsp.config('ts_ls', {
|
||||||
lspconfig.ts_ls.setup({
|
cmd = { "typescript-language-server", "--stdio" },
|
||||||
on_attach = function(client, bufnr)
|
filetypes = {
|
||||||
-- Custom keymaps and commands for tsserver
|
"typescript",
|
||||||
local opts = { noremap = true, silent = true }
|
"typescriptreact",
|
||||||
-- Example key mappings
|
"typescript.tsx",
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)
|
"javascript",
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>", opts)
|
"javascriptreact",
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>rn", "<Cmd>lua vim.lsp.buf.rename()<CR>", opts)
|
"javascript.jsx",
|
||||||
end,
|
},
|
||||||
filetypes = {
|
-- In 0.11, root_markers replaces root_dir logic
|
||||||
"typescript",
|
root_markers = { "package.json", "tsconfig.json", "jsconfig.json", ".git" },
|
||||||
"typescriptreact",
|
settings = {
|
||||||
"typescript.tsx",
|
javascript = {
|
||||||
"javascript",
|
format = {
|
||||||
"javascriptreact",
|
enable = true,
|
||||||
"javascript.jsx",
|
insertSpaceAfterCommaDelimiter = true,
|
||||||
},
|
insertSpaceAfterSemicolon = true,
|
||||||
cmd = { "typescript-language-server", "--stdio" },
|
insertSpaceBeforeAndAfterOperator = true,
|
||||||
root_dir = lspconfig.util.root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git"),
|
indentStyle = "smart",
|
||||||
settings = {
|
indentSize = 2,
|
||||||
-- Enable document formatting
|
},
|
||||||
format = {
|
},
|
||||||
enable = true,
|
typescript = {
|
||||||
insertSpaceAfterCommaDelimiter = true,
|
format = {
|
||||||
insertSpaceAfterSemicolon = true,
|
enable = true,
|
||||||
insertSpaceBeforeAndAfterOperator = true,
|
insertSpaceAfterCommaDelimiter = true,
|
||||||
indentStyle = "smart",
|
insertSpaceAfterSemicolon = true,
|
||||||
indentSize = 2,
|
insertSpaceBeforeAndAfterOperator = true,
|
||||||
wrapLineLength = 120,
|
indentStyle = "smart",
|
||||||
},
|
indentSize = 2,
|
||||||
-- Diagnostics and completion settings
|
},
|
||||||
diagnostics = {
|
},
|
||||||
enable = true,
|
},
|
||||||
},
|
|
||||||
completions = {
|
|
||||||
enable = true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- 2. Global LspAttach for Keymaps
|
||||||
|
-- This works for all servers, so you only need to define it once (e.g., in user/lsp.lua)
|
||||||
|
vim.api.nvim_create_autocmd('LspAttach', {
|
||||||
|
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
|
||||||
|
callback = function(ev)
|
||||||
|
local opts = { buffer = ev.buf, noremap = true, silent = true }
|
||||||
|
|
||||||
|
-- Modern way to set keymaps using the lua function directly
|
||||||
|
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
|
||||||
|
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
|
||||||
|
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- 3. Enable the server
|
||||||
|
vim.lsp.enable('ts_ls')
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
require("nvim-treesitter.configs").setup({
|
require("nvim-treesitter").setup({
|
||||||
ensure_installed = {
|
ensure_installed = {
|
||||||
"markdown",
|
"markdown",
|
||||||
"markdown_inline",
|
"markdown_inline",
|
||||||
|
|
|
||||||
BIN
nvim-macos-x86_64/bin/nvim
Executable file
BIN
nvim-macos-x86_64/bin/nvim
Executable file
Binary file not shown.
Loading…
Reference in a new issue