|
1 | 1 | return { |
2 | | - { |
3 | | - "williamboman/mason-lspconfig.nvim", |
4 | | - config = function() |
5 | | - require("mason-lspconfig").setup({ |
6 | | - -- Availables LSP Servers |
7 | | - -- https://github.com/williamboman/mason-lspconfig.nvim?tab=readme-ov-file#available-lsp-servers |
8 | | - ensure_installed = { |
9 | | - "jdtls", |
10 | | - "kotlin_language_server", |
11 | | - "lua_ls", |
12 | | - "pyright", |
13 | | - "ruff", |
14 | | - "solargraph", |
15 | | - "tailwindcss", |
16 | | - "terraformls", |
17 | | - "ts_ls", |
18 | | - }, |
19 | | - }) |
20 | | - end, |
21 | | - }, |
22 | | - { |
23 | | - "mfussenegger/nvim-jdtls", |
24 | | - ft = { "java" }, -- Carrega apenas para arquivos Java |
25 | | - }, |
26 | | - { |
27 | | - "neovim/nvim-lspconfig", |
28 | | - dependencies = { |
29 | | - "mfussenegger/nvim-jdtls", |
30 | | - }, |
31 | | - config = function() |
32 | | - local capabilities = require("cmp_nvim_lsp").default_capabilities() |
33 | | - local lspconfig = require("lspconfig") |
34 | | - local java_path = vim.fn.expand("~/.asdf/shims/java") |
35 | | - local jdtls = require("jdtls") |
36 | | - local on_attach = require("cmp_nvim_lsp").on_attach |
| 2 | + { |
| 3 | + "williamboman/mason-lspconfig.nvim", |
| 4 | + config = function() |
| 5 | + require("mason-lspconfig").setup({ |
| 6 | + -- Availables LSP Servers |
| 7 | + -- https://github.com/williamboman/mason-lspconfig.nvim?tab=readme-ov-file#available-lsp-servers |
| 8 | + ensure_installed = { |
| 9 | + "autopep8", |
| 10 | + "jdtls", |
| 11 | + "kotlin_language_server", |
| 12 | + "lua_ls", |
| 13 | + "pyright", |
| 14 | + "ruby-lsp", |
| 15 | + "ruff", |
| 16 | + "solargrah", |
| 17 | + "tailwindcss", |
| 18 | + "terraformls", |
| 19 | + "tsserver", |
| 20 | + }, |
| 21 | + }) |
| 22 | + end, |
| 23 | + }, |
| 24 | + { |
| 25 | + "neovim/nvim-lspconfig", |
| 26 | + dependencies = { |
| 27 | + "mfussenegger/nvim-jdtls", |
| 28 | + }, |
| 29 | + config = function() |
| 30 | + local lspconfig = require("lspconfig") |
| 31 | + local mason_lspconfig = require("mason-lspconfig") |
| 32 | + local capabilities = require("cmp_nvim_lsp").default_capabilities() |
| 33 | + local on_attach = require("cmp_nvim_lsp").on_attach |
37 | 34 |
|
38 | | - lspconfig.lua_ls.setup({ |
39 | | - capabilities = capabilities, |
40 | | - }) |
41 | | - lspconfig.ts_ls.setup({ |
42 | | - capabilities = capabilities, |
43 | | - }) |
44 | | - lspconfig.pyright.setup({ |
45 | | - capabilities = capabilities, |
46 | | - on_attach = on_attach, |
47 | | - filetypes = { "python" }, |
48 | | - }) |
49 | | - lspconfig.ruff.setup({ |
50 | | - capabilities = capabilities, |
51 | | - on_attach = on_attach, |
52 | | - filetypes = { "python" }, |
53 | | - }) |
54 | | - lspconfig.kotlin_language_server.setup({ |
55 | | - capabilities = capabilities, |
56 | | - }) |
57 | | - lspconfig.jdtls.setup({ |
58 | | - cmd = { "jdtls" }, |
59 | | - root_dir = lspconfig.util.root_pattern("pom.xml", "build.gradle", ".git"), -- Define o diretório raiz do projector |
60 | | - settings = { |
61 | | - java = { |
62 | | - configuration = { |
63 | | - runtimes = { |
64 | | - { |
65 | | - name = "JavaSE-17", |
66 | | - path = java_path, -- Usa o caminho do JDK gerenciado pelo asdf |
67 | | - }, |
68 | | - }, |
69 | | - }, |
70 | | - }, |
71 | | - }, |
72 | | - }) |
| 35 | + -- Setup language servers installed through Mason |
| 36 | + local servers = mason_lspconfig.get_installed_servers() |
| 37 | + for _, server_name in ipairs(servers) do |
| 38 | + -- Exclude jdtls from the general setup, as it has a custom one |
| 39 | + if server_name ~= "jdtls" then |
| 40 | + lspconfig[server_name].setup({ |
| 41 | + on_attach = on_attach, |
| 42 | + capabilities = capabilities, |
| 43 | + }) |
| 44 | + end |
| 45 | + end |
73 | 46 |
|
74 | | - jdtls.start_or_attach({ |
75 | | - cmd = { vim.fn.expand("$HOME/.local/share/nvim/mason/bin/jdtls") }, -- Caminho do jdtls |
76 | | - root_dir = vim.fs.dirname(vim.fs.find({ "pom.xml", "build.gradle", ".git" }, { upward = true })[1]), -- Define o diretório raiz do projeto |
77 | | - settings = { |
78 | | - java = { |
79 | | - configuration = { |
80 | | - runtimes = { |
81 | | - { |
82 | | - name = "JavaSE-17", |
83 | | - path = java_path, -- Usa o caminho do JDK gerenciado pelo asdf |
84 | | - }, |
85 | | - }, |
86 | | - }, |
87 | | - }, |
88 | | - }, |
89 | | - }) |
| 47 | + -- Custom setup for jdtls |
| 48 | + local java_path = vim.fn.expand("~/.asdf/shims/java") |
| 49 | + local jdtls = require("jdtls") |
| 50 | + lspconfig.jdtls.setup({ |
| 51 | + cmd = { "jdtls" }, |
| 52 | + root_dir = lspconfig.util.root_pattern("pom.xml", "build.gradle", ".git"), |
| 53 | + settings = { |
| 54 | + java = { |
| 55 | + configuration = { |
| 56 | + runtimes = { |
| 57 | + { |
| 58 | + name = "JavaSE-17", |
| 59 | + path = java_path, |
| 60 | + }, |
| 61 | + }, |
| 62 | + }, |
| 63 | + }, |
| 64 | + }, |
| 65 | + }) |
| 66 | + jdtls.start_or_attach({ |
| 67 | + cmd = { vim.fn.expand("$HOME/.local/share/nvim/mason/bin/jdtls") }, |
| 68 | + root_dir = vim.fs.dirname(vim.fs.find({ "pom.xml", "build.gradle", ".git" }, { upward = true })[1]), |
| 69 | + }) |
90 | 70 |
|
91 | | - lspconfig.terraformls.setup({ |
92 | | - capabilities = capabilities, |
93 | | - }) |
| 71 | + -- Global keymaps |
| 72 | + vim.keymap.set("n", "K", vim.lsp.buf.hover, {}) |
| 73 | + vim.keymap.set("n", "gd", vim.lsp.buf.definition, {}) |
| 74 | + vim.keymap.set("n", "gr", vim.lsp.buf.references, {}) |
| 75 | + vim.keymap.set("n", "gD", vim.lsp.buf.declaration, {}) |
| 76 | + vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, {}) |
| 77 | + vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, {}) |
| 78 | + vim.keymap.set({ "n", "v" }, "<leader>oi", function() |
| 79 | + vim.lsp.buf.code_action({ context = { only = { "source.organizeImports" } } }) |
| 80 | + end, { desc = "Organize Imports" }) |
94 | 81 |
|
95 | | - -- Buffer local mappings. |
96 | | - -- See `:help vim.lsp.*` for documentation on any of the below functions |
97 | | - -- Read more: https://github.com/neovim/nvim-lspconfig?tab=readme-ov-file#suggested-configuration |
98 | | - vim.keymap.set("n", "K", vim.lsp.buf.hover, {}) -- Will open helper pop-up |
99 | | - vim.keymap.set("n", "gd", vim.lsp.buf.definition, {}) |
100 | | - vim.keymap.set("n", "gr", vim.lsp.buf.references, {}) |
101 | | - vim.keymap.set("n", "gD", vim.lsp.buf.declaration, {}) |
102 | | - vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, {}) |
103 | | - vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, {}) |
104 | | - |
105 | | - -- Format on save |
106 | | - vim.api.nvim_create_autocmd("BufWritePre", { |
107 | | - group = vim.api.nvim_create_augroup("Format", { clear = true }), |
108 | | - callback = function() |
109 | | - vim.lsp.buf.format() |
110 | | - end, |
111 | | - }) |
112 | | - |
113 | | - -- Add blankline at EOF on save |
114 | | - vim.api.nvim_create_autocmd("BufWritePre", { |
115 | | - group = vim.api.nvim_create_augroup("AddBlankLine", { clear = true }), |
116 | | - callback = function() |
117 | | - local last_line = vim.api.nvim_buf_line_count(0) |
118 | | - local last_line_content = vim.api.nvim_buf_get_lines(0, last_line - 1, last_line, false)[1] |
119 | | - if last_line_content ~= "" then |
120 | | - vim.api.nvim_buf_set_lines(0, last_line, last_line, false, { "" }) |
121 | | - end |
122 | | - end, |
123 | | - }) |
124 | | - |
125 | | - -- Organize import |
126 | | - vim.keymap.set({ "n", "v" }, "<leader>oi", function() |
127 | | - vim.lsp.buf.code_action({ |
128 | | - context = { |
129 | | - only = { "source.organizeImports" }, |
130 | | - }, |
131 | | - }) |
132 | | - end) |
133 | | - end, |
134 | | - }, |
| 82 | + -- Format on save |
| 83 | + vim.api.nvim_create_autocmd("BufWritePre", { |
| 84 | + group = vim.api.nvim_create_augroup("LspFormatOnSave", { clear = true }), |
| 85 | + callback = function(args) |
| 86 | + vim.lsp.buf.format({ bufnr = args.buf }) |
| 87 | + end, |
| 88 | + }) |
| 89 | + end, |
| 90 | + }, |
135 | 91 | } |
136 | | - |
0 commit comments