Skip to content

Commit 0104c51

Browse files
refactor: Refactored mason plugins to support the new native vim lsp support api.
1 parent 68ff64f commit 0104c51

2 files changed

Lines changed: 75 additions & 91 deletions

File tree

lua/plugins/mason.lua

Lines changed: 57 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -10,102 +10,70 @@ return {
1010
"williamboman/mason-lspconfig.nvim",
1111
dependencies = { "neovim/nvim-lspconfig" },
1212
config = function()
13+
local capabilities = require("cmp_nvim_lsp").default_capabilities()
14+
1315
require("mason-lspconfig").setup({
1416
ensure_installed = { "lua_ls", "pyright", "ts_ls" }, -- Add more LSP servers you need
1517
})
1618

17-
require("mason-lspconfig").setup_handlers({
18-
function(server_name) -- Default handler
19-
require("lspconfig")[server_name].setup({
20-
capabilities = require("cmp_nvim_lsp").default_capabilities(),
21-
on_attach = function(client, bufnr)
22-
-- Optional: Custom on_attach function to set keymaps, etc.
23-
end,
24-
})
25-
end,
26-
27-
["jdtls"] = function() end, -- Prevent Mason from attaching `jdtls`
28-
29-
-- Custom setup for Lua language server
30-
["lua_ls"] = function()
31-
require("lspconfig").lua_ls.setup({
32-
settings = {
33-
Lua = {
34-
runtime = {
35-
version = "Lua 5.3",
36-
},
37-
diagnostics = {
38-
globals = { "bit", "vim", "it", "describe", "before_each", "after_each" },
39-
},
40-
workspace = {
41-
library = vim.api.nvim_get_runtime_file("", true), -- Make Neovim runtime files discoverable
42-
checkThirdParty = false, -- Avoid popping up workspace notifications
43-
},
44-
telemetry = {
45-
enable = false, -- Disable telemetry to avoid sending data
46-
},
47-
codeLens = {
48-
enable = true,
49-
},
50-
completion = {
51-
callSnippet = "Replace",
52-
},
53-
doc = {
54-
privateName = { "^_" },
55-
},
56-
hint = {
57-
enable = true,
58-
setType = false,
59-
paramType = true,
60-
paramName = "Disable",
61-
semicolon = "Disable",
62-
arrayIndex = "Disable",
63-
},
64-
},
19+
vim.lsp.config('lua_ls', {
20+
settings = {
21+
Lua = {
22+
runtime = {
23+
version = "Lua 5.3",
6524
},
66-
})
67-
end,
68-
69-
["kotlin_language_server"] = function()
70-
require('lspconfig').kotlin_language_server.setup({
71-
cmd = { 'kotlin-language-server' },
72-
root_dir = require('lspconfig.util').root_pattern('settings.gradle', 'settings.gradle.kts',
73-
'build.gradle', 'build.gradle.kts', 'pom.xml', '.git'),
74-
on_attach = function(client, bufnr)
75-
-- Set up buffer-local keybindings, etc.
76-
end,
77-
capabilities = require('cmp_nvim_lsp').default_capabilities(),
78-
})
79-
end,
80-
81-
["arduino_language_server"] = function()
82-
require('lspconfig').arduino_language_server.setup({
83-
cmd = {
84-
"arduino-language-server",
85-
"-cli-config", "/home/zkrallah/.arduino15/arduino-cli.yaml", -- Path to your arduino-cli.yaml file
86-
"-fqbn", "esp32:esp32:esp32" -- Replace with your board’s fully qualified board name (FQBN)
25+
diagnostics = {
26+
globals = { "bit", "vim", "it", "describe", "before_each", "after_each" },
8727
},
88-
on_attach = function(client, bufnr)
89-
-- Optional: Set key mappings or custom settings here
90-
end,
91-
})
92-
end,
93-
94-
["pyright"] = function()
95-
require('lspconfig').pyright.setup({
96-
settings = {
97-
python = {
98-
analysis = {
99-
pythonPath = "/usr/bin/python3",
100-
autoSearchPaths = true,
101-
useLibraryCodeForTypes = true,
102-
typeCheckingMode = "basic", -- Change to "strict" for more detailed checks
103-
},
104-
},
28+
workspace = {
29+
library = vim.api.nvim_get_runtime_file("", true), -- Make Neovim runtime files discoverable
30+
checkThirdParty = false, -- Avoid popping up workspace notifications
10531
},
106-
})
107-
end
108-
32+
telemetry = {
33+
enable = false, -- Disable telemetry to avoid sending data
34+
},
35+
codeLens = {
36+
enable = true,
37+
},
38+
completion = {
39+
callSnippet = "Replace",
40+
},
41+
doc = {
42+
privateName = { "^_" },
43+
},
44+
hint = {
45+
enable = true,
46+
setType = false,
47+
paramType = true,
48+
paramName = "Disable",
49+
semicolon = "Disable",
50+
arrayIndex = "Disable",
51+
},
52+
},
53+
},
54+
})
55+
--- Pyright
56+
vim.lsp.config('pyright', {
57+
capabilities = capabilities,
58+
settings = {
59+
python = {
60+
analysis = {
61+
pythonPath = "/usr/bin/python3",
62+
autoSearchPaths = true,
63+
useLibraryCodeForTypes = true,
64+
typeCheckingMode = "basic",
65+
},
66+
},
67+
},
68+
})
69+
--- Arduino
70+
vim.lsp.config('arduino_language_server', {
71+
cmd = {
72+
"arduino-language-server",
73+
"-cli-config", "/home/zkrallah/.arduino15/arduino-cli.yaml",
74+
"-fqbn", "esp32:esp32:esp32"
75+
},
76+
capabilities = capabilities,
10977
})
11078
end,
11179
}

lua/plugins/nvim-jdtls.lua

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,24 @@ return {
33
dependencies = { "nvim-lua/plenary.nvim" },
44
ft = { "java" }, -- Automatically load for Java files
55
opts = function()
6-
local mason_registry = require("mason-registry")
7-
local lombok_jar = mason_registry.get_package("jdtls"):get_install_path() .. "/lombok.jar"
6+
-- Use $MASON environment variable to find lombok.jar
7+
local lombok_jar = vim.fn.expand("$MASON/share/jdtls/lombok.jar")
8+
9+
-- Verify the file actually exists
10+
if vim.fn.filereadable(lombok_jar) == 0 then
11+
vim.notify("lombok.jar not found at: " .. lombok_jar, vim.log.levels.WARN)
12+
lombok_jar = nil
13+
end
14+
15+
-- Fallback configuration if lombok.jar isn't found
16+
if not lombok_jar then
17+
vim.notify("Using jdtls without lombok support", vim.log.levels.WARN)
18+
return {
19+
root_dir = require("lspconfig").util.root_pattern(".git", "mvnw", "gradlew"),
20+
cmd = { vim.fn.exepath("jdtls") },
21+
-- other default configurations...
22+
}
23+
end
824
return {
925
-- Define the root directory using standard lspconfig
1026
root_dir = require("lspconfig").util.root_pattern(".git", "mvnw", "gradlew"),

0 commit comments

Comments
 (0)