diff --git a/README.md b/README.md index dd88636b..2a0af816 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,7 @@ docker run -it --rm -v $(pwd):/home/neovim/workspace liubang/nvim - [nvim-autopairs](https://github.com/windwp/nvim-autopairs) - [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) - [nvim-colorizer.lua](https://github.com/NvChad/nvim-colorizer.lua) +- [nvim-jdtls](https://github.com/mfussenegger/nvim-jdtls) - [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) - [nvim-navic](https://github.com/SmiteshP/nvim-navic) - [nvim-notify](https://github.com/rcarriga/nvim-notify) @@ -200,6 +201,7 @@ docker run -it --rm -v $(pwd):/home/neovim/workspace liubang/nvim - [telescope-fzf-native.nvim](https://github.com/nvim-telescope/telescope-fzf-native.nvim) - [telescope-ui-select.nvim](https://github.com/nvim-telescope/telescope-ui-select.nvim) - [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim) +- [typescript.nvim](https://github.com/jose-elias-alvarez/typescript.nvim) - [undotree](https://github.com/mbbill/undotree) - [vim-caser](https://github.com/arthurxavierx/vim-caser) - [vim-diagon](https://github.com/willchao612/vim-diagon) diff --git a/lazy-lock.json b/lazy-lock.json index 14eac498..aa707782 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,13 +1,13 @@ { - "Comment.nvim": { "branch": "master", "commit": "eab2c83a0207369900e92783f56990808082eac2" }, + "Comment.nvim": { "branch": "master", "commit": "6821b3ae27a57f1f3cf8ed030e4a55d70d0c4e43" }, "LuaSnip": { "branch": "master", "commit": "58fbfc627a93281a77f7d161d4ff702e639677b1" }, "accelerated-jk.nvim": { "branch": "main", "commit": "38bbbf9258aab876906588ea979901ed3ed569c6" }, - "aerial.nvim": { "branch": "master", "commit": "a467e9a06aa92db81812f4c2c26364877bbafb80" }, - "alpha-nvim": { "branch": "main", "commit": "1c903fd40b1d51e7740b4d90e9f18e83f2916586" }, + "aerial.nvim": { "branch": "master", "commit": "89031be806abded509a7bafd99bd9944eb5108a5" }, + "alpha-nvim": { "branch": "main", "commit": "b3eef69e95674905bf26c7740dd4bbb09b355494" }, "asyncrun.extra": { "branch": "master", "commit": "8c1f8795aaf1041276657ee868bf3c48c11d5c7d" }, "asyncrun.vim": { "branch": "master", "commit": "bd240b2a2ac5c975216744fda57abe5ff8f39957" }, "asynctasks.vim": { "branch": "master", "commit": "784a4b1f75a913cc6c43dd6c4dbe69d648dbbfa5" }, - "bufdelete.nvim": { "branch": "master", "commit": "f79e9d186b42fba5f1b1362006e7c70240db97a4" }, + "bufdelete.nvim": { "branch": "master", "commit": "8933abc09df6c381d47dc271b1ee5d266541448e" }, "bufferline.nvim": { "branch": "main", "commit": "84b0822b2af478d0b4f7b0f9249ca218855331db" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-calc": { "branch": "main", "commit": "50792f34a628ea6eb31d2c90e8df174671e4e7a0" }, @@ -16,40 +16,41 @@ "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp_luasnip": { "branch": "master", "commit": "18095520391186d634a0045dacaa346291096566" }, "crates.nvim": { "branch": "main", "commit": "3fc7ddac13ddf65914a733ef074317c4c72ef05b" }, - "fidget.nvim": { "branch": "main", "commit": "9dc6d15fdb877b2fb09ea0ba2dfde9beccb5965a" }, + "fidget.nvim": { "branch": "main", "commit": "688b4fec4517650e29c3e63cfbb6e498b3112ba1" }, "fzy-lua-native": { "branch": "master", "commit": "085c7d262aa35cc55a8523e8c1618d398bf717a7" }, - "gitsigns.nvim": { "branch": "main", "commit": "f29f0b22fd66c910b892aae3bc18a4872c002738" }, + "gitsigns.nvim": { "branch": "main", "commit": "f388995990aba04cfdc7c3ab870c33e280601109" }, "gruvbox-material": { "branch": "master", "commit": "13b7eb4589d9ab0f388ca51047051f7158c930e5" }, "hex.nvim": { "branch": "master", "commit": "317915ffcb160a2039be5250825f658002435c39" }, "hop.nvim": { "branch": "v2", "commit": "90db1b2c61b820e230599a04fedcd2679e64bd07" }, - "lazy.nvim": { "branch": "main", "commit": "d13fe9353594bce58a5b9fc6d7166d183e0fc035" }, + "lazy.nvim": { "branch": "main", "commit": "f2cc9ef6acc7367c001b7507c82cab3ab7c29cae" }, "lspkind.nvim": { "branch": "master", "commit": "c68b3a003483cf382428a43035079f78474cd11e" }, - "lualine.nvim": { "branch": "master", "commit": "0050b308552e45f7128f399886c86afefc3eb988" }, - "markdown-preview.nvim": { "branch": "master", "commit": "02cc3874738bc0f86e4b91f09b8a0ac88aef8e96" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "e2b82cf4c68b453eeab5833d90c042ed4b49d0e1" }, - "mason.nvim": { "branch": "main", "commit": "f557094c77c4fa91c3613cfbd22cbcdbe0569793" }, - "mini.ai": { "branch": "main", "commit": "efeab91f9373d6d3c73314fda9e3366020d05157" }, + "lualine.nvim": { "branch": "master", "commit": "e99d733e0213ceb8f548ae6551b04ae32e590c80" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "93e58e100f37ef4fb0f897deeed20599dae9d128" }, + "mason.nvim": { "branch": "main", "commit": "f3d90e3b7580a2d1b47a1f9b905808e22a7fac87" }, + "mini.ai": { "branch": "main", "commit": "d50b4d87e38d21ca2c5facee9f8a205ddb768358" }, "mini.align": { "branch": "main", "commit": "b088ddab3495e5c1c84681e6db23dd3cc0660683" }, "mini.cursorword": { "branch": "main", "commit": "5729d3c62cadbd0e91c10396ae514ee6be588f61" }, "mini.surround": { "branch": "main", "commit": "6a4f31e2a380439315729f561d7e7898bde1fd52" }, - "neodev.nvim": { "branch": "main", "commit": "1b21ea60f5b67946282b0b0312773e85fc6f9b05" }, + "neodev.nvim": { "branch": "main", "commit": "a81e749d0fe8429cd340b2e40f274b344bef42ac" }, "neogen": { "branch": "main", "commit": "465af9d6c6fb7f360175991dcc23fc10917e3a06" }, - "null-ls.nvim": { "branch": "main", "commit": "d4594231a06cecce73a78a256b0d7c7ab51f7dd5" }, - "nvim-autopairs": { "branch": "master", "commit": "45ae3122a4c7744db41298b41f9f5a3f092123e6" }, - "nvim-cmp": { "branch": "main", "commit": "aae0c3e4e778ca4be6fabc52e388cbd5b844b7a5" }, + "null-ls.nvim": { "branch": "main", "commit": "a82aa08c0063843926947f3688b0e61fd71db680" }, + "nvim-autopairs": { "branch": "master", "commit": "bde7a1b4534e0a4c2451a738379cd628ba65eba7" }, + "nvim-cmp": { "branch": "main", "commit": "ea9eaff5739856f3187d228d2c1181ea49fd4697" }, "nvim-colorizer.lua": { "branch": "master", "commit": "760e27df4dd966607e8fb7fd8b6b93e3c7d2e193" }, - "nvim-lspconfig": { "branch": "master", "commit": "1712672e4da3003a0dd9f771d30389600b360f42" }, + "nvim-jdtls": { "branch": "master", "commit": "8fe3be1c08ab0bb55f2998fbc02f1a08f87a44bc" }, + "nvim-lspconfig": { "branch": "master", "commit": "649137cbc53a044bffde36294ce3160cb18f32c7" }, "nvim-navic": { "branch": "master", "commit": "7e9d2b2b601149fecdccd11b516acb721e571fe6" }, "nvim-notify": { "branch": "master", "commit": "bdd647f61a05c9b8a57c83b78341a0690e9c29d7" }, - "nvim-tree.lua": { "branch": "master", "commit": "ba1778e061f25814bc5940be886a7f41d7d7736e" }, - "nvim-treesitter": { "branch": "master", "commit": "7eb5f1a2e3949496f26c4084b521b30f2d08137a" }, - "nvim-treesitter-textobjects": { "branch": "master", "commit": "37e3c7b32b653f24d7aa2fa087a9c5a67ef07786" }, + "nvim-tree.lua": { "branch": "master", "commit": "08a0aa1a3b7411ee0a7887c8818528b1558cef96" }, + "nvim-treesitter": { "branch": "master", "commit": "0493aa026bd726b762004a7e78ccb19471e47daa" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "2f3583001e2bf793480f38cf0d055571787b0259" }, "nvim-ts-context-commentstring": { "branch": "main", "commit": "a0f89563ba36b3bacd62cf967b46beb4c2c29e52" }, - "nvim-web-devicons": { "branch": "master", "commit": "bd7a222287c5828cd0607cd0a5605e52f0460074" }, + "nvim-web-devicons": { "branch": "master", "commit": "bb6d4fd1e010300510172b173ab5205d37af084f" }, + "peek.nvim": { "branch": "master", "commit": "ade044b0c1beadd918f867264d1a801e675ec1d7" }, "plenary.nvim": { "branch": "master", "commit": "9a0d3bf7b832818c042aaf30f692b081ddd58bd9" }, "rust-tools.nvim": { "branch": "master", "commit": "bd1aa99ffb911a1cf99b3fcf3b44c0391c57e3ef" }, - "schemastore.nvim": { "branch": "main", "commit": "b37874a63ceac681a15b83d5c8e67f58fe571341" }, - "smart-splits.nvim": { "branch": "master", "commit": "fdd158ce7554dc830fb86e0fe952cd9476cdf726" }, + "schemastore.nvim": { "branch": "main", "commit": "a4798a9fb5fd3ac8e132065597b397cab347d3ca" }, + "smart-splits.nvim": { "branch": "master", "commit": "b38431f1f68bc43d6bf9d1edb21c2bcb06b1197c" }, "sqlite.lua": { "branch": "master", "commit": "93ff5824682ecc874200e338fd8ca9ccd08508f8" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "580b6c48651cabb63455e97d7e131ed557b8c7e2" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "62ea5e58c7bbe191297b983a9e7e89420f581369" }, diff --git a/lua/plugins/lsp/init.lua b/lua/plugins/lsp/init.lua index 4bf3e967..06da8cb8 100644 --- a/lua/plugins/lsp/init.lua +++ b/lua/plugins/lsp/init.lua @@ -25,6 +25,7 @@ return { "b0o/schemastore.nvim", "jose-elias-alvarez/null-ls.nvim", "jose-elias-alvarez/typescript.nvim", + "mfussenegger/nvim-jdtls", }, config = function() -- It's important that you set up the plugins in the following order: diff --git a/lua/plugins/lsp/jdtls/opts.lua b/lua/plugins/lsp/jdtls/opts.lua deleted file mode 100644 index d644aa58..00000000 --- a/lua/plugins/lsp/jdtls/opts.lua +++ /dev/null @@ -1,24 +0,0 @@ ---===================================================================== --- --- opts.lua - --- --- Created by liubang on 2022/09/18 20:36 --- Last Modified: 2022/09/18 20:36 --- ---===================================================================== -local M = {} - -M.extendedClientCapabilities = { - progressReportProvider = true, - classFileContentsSupport = true, - generateToStringPromptSupport = true, - hashCodeEqualsPromptSupport = true, - advancedExtractRefactoringSupport = true, - advancedOrganizeImportsSupport = true, - generateConstructorsPromptSupport = true, - generateDelegateMethodsPromptSupport = true, - moveRefactoringSupport = true, - inferSelectionSupport = { "extractMethod", "extractVariable", "extractConstant" }, -} - -return M diff --git a/lua/plugins/lsp/jdtls/setup.lua b/lua/plugins/lsp/jdtls/setup.lua deleted file mode 100644 index b04b4441..00000000 --- a/lua/plugins/lsp/jdtls/setup.lua +++ /dev/null @@ -1,400 +0,0 @@ ---===================================================================== --- --- init.lua - --- --- Created by liubang on 2022/04/05 01:46 --- Last Modified: 2022/04/05 01:46 --- ---===================================================================== - -local M = {} -local highlight_ns = vim.api.nvim_create_namespace "jdtls_hl" - -function M.open_jdt_link(uri) - local client - for _, c in ipairs(vim.lsp.get_active_clients()) do - if - c.config.init_options - and c.config.init_options.extendedClientCapabilities - and c.config.init_options.extendedClientCapabilities.classFileContentsSupport - then - client = c - break - end - end - assert(client, "Must have a buffer open with a language client connected to eclipse.jdt.ls to load JDT URI") - local buf = vim.api.nvim_get_current_buf() - local params = { - uri = uri, - } - local response = nil - local cb = function(err, result) - response = { err, result } - end - local ok, request_id = client.request("java/classFileContents", params, cb, buf) - assert(ok, "Request to `java/classFileContents` must succeed to open JDT URI. Client shutdown?") - local timeout_ms = 5000 - local wait_ok, reason = vim.wait(timeout_ms, function() - return response - end) - local log_path = vim.fn.stdpath "cache" .. "/lsp.log" - local buf_content - if wait_ok and #response == 2 and response[2] then - local content = response[2] - if content == "" then - buf_content = { - "Received response from server, but it was empty. Check the log file for errors", - log_path, - } - else - buf_content = vim.split(response[2], "\n", true) - end - else - local error_msg - if not wait_ok then - client.cancel_request(request_id) - local wait_failure = { - [-1] = "timeout", - [-2] = "interrupted", - [-3] = "error", - } - error_msg = wait_failure[reason] - else - error_msg = response[1] - end - buf_content = { - "Failed to load content for uri", - uri, - "", - "Error was: ", - } - vim.list_extend(buf_content, vim.split(vim.inspect(error_msg), "\n")) - vim.list_extend(buf_content, { "", "Check the log file for errors", log_path }) - end - vim.api.nvim_buf_set_option(buf, "modifiable", true) - vim.api.nvim_buf_set_lines(buf, 0, -1, false, buf_content) - vim.api.nvim_buf_set_option(0, "filetype", "java") - vim.api.nvim_buf_set_option(buf, "modifiable", false) -end - -local function find_last(str, pattern) - local idx = nil - while true do - local i = string.find(str, pattern, (idx or 0) + 1) - if i == nil then - break - else - idx = i - end - end - return idx -end - -local function java_generate_to_string_prompt(_, outer_ctx) - local params = outer_ctx.params - vim.lsp.buf_request(0, "java/checkToStringStatus", params, function(err, result, ctx) - if err then - print("Could not execute java/checkToStringStatus: " .. err.message) - return - end - if not result then - return - end - if result.exists then - local choice = vim.fn["quickui#confirm#open"]( - string.format("Method 'toString()' already exists in '%s'. Do you want to replace it?", result.type), - "&Replace\n&Cancel", - 1, - "Confirm" - ) - if choice < 1 or choice == 2 then - return - end - end - local lines = {} - for _, field in pairs(result.fields) do - table.insert(lines, string.format("%s: %s", field.name, field.type)) - end - local idxs = vim.fn["quickui#checkbox#open"](lines, { - title = "Select Fields", - }) - local fields = {} - for _, idx in pairs(idxs) do - table.insert(fields, result.fields[tonumber(idx) + 1]) - end - vim.lsp.buf_request(ctx.bufnr, "java/generateToString", { context = params, fields = fields }, function(e, edit) - if e then - print("Could not execute java/generateToString: " .. e.message) - return - end - if edit then - vim.lsp.util.apply_workspace_edit(edit, "utf-16") - end - end) - end) -end - -local function java_generate_constructors_prompt(_, outer_ctx) - vim.lsp.buf_request(0, "java/checkConstructorsStatus", outer_ctx.params, function(err0, status, ctx) - if err0 then - print("Could not execute java/checkConstructorsStatus: " .. err0.message) - return - end - if not status or not status.constructors or #status.constructors == 0 then - return - end - local constructors = status.constructors - if #status.constructors > 1 then - local lines = {} - for _, x in pairs(status.constructors) do - table.insert(lines, string.format("%s(%s)", x.name, table.concat(x.parameters, ","))) - end - local idxs = vim.fn["quickui#checkbox#open"](lines, { - title = "Select Constructors", - }) - local selected = {} - for _, idx in pairs(idxs) do - table.insert(selected, constructors[tonumber(idx) + 1]) - end - constructors = selected - end - - local fields = status.fields - if fields then - local lines = {} - for _, x in pairs(fields) do - table.insert(lines, string.format("%s: %s", x.name, x.type)) - end - local idxs = vim.fn["quickui#checkbox#open"](lines, { - title = "Select Parameters", - }) - local selected = {} - for _, idx in pairs(idxs) do - table.insert(selected, fields[tonumber(idx) + 1]) - end - fields = selected - end - - local params = { - context = outer_ctx.params, - constructors = constructors, - fields = fields, - } - vim.lsp.buf_request(ctx.bufnr, "java/generateConstructors", params, function(err1, edit) - if err1 then - print("Could not execute java/generateConstructors: " .. err1.message) - elseif edit then - vim.lsp.util.apply_workspace_edit(edit, "utf-16") - end - end) - end) -end - -local function java_generate_delegate_methods_prompt(_, outer_ctx) - vim.lsp.buf_request(0, "java/checkDelegateMethodsStatus", outer_ctx.params, function(err0, status, ctx) - if err0 then - print("Could not execute java/checkDelegateMethodsStatus: ", err0.message) - return - end - if not status or not status.delegateFields or #status.delegateFields == 0 then - print "All delegatable methods are already implemented." - return - end - - local field - if #status.delegateFields == 1 then - field = status.delegateFields[1] - elseif #status.delegateFields > 1 then - local lines = {} - for _, x in pairs(status.delegateFields) do - table.insert(lines, string.format("%s: %s", x.field.name, x.field.type)) - end - local idx = vim.fn["quickui#listbox#inputlist"](lines, { - index = -1, - title = "Select target to generate delegate for", - }) - field = status.delegateFields[idx + 1] - end - - if not field then - return - end - if #field.delegateMethods == 0 then - print "All delegatable methods are already implemented." - return - end - - local lines = {} - for _, x in pairs(field.delegateMethods) do - table.insert(lines, string.format("%s(%s)", x.name, table.concat(x.parameters, ","))) - end - local idxs = vim.fn["quickui#checkbox#open"](lines, { title = "Generate delegate for methods" }) - local methods = {} - for _, idx in pairs(idxs) do - table.insert(methods, field.delegateMethods[tonumber(idx) + 1]) - end - if not methods or #methods == 0 then - return - end - - local params = { - context = outer_ctx.params, - delegateEntries = vim.tbl_map(function(x) - return { - field = field.field, - delegateMethod = x, - } - end, methods), - } - vim.lsp.buf_request(ctx.bufnr, "java/generateDelegateMethods", params, function(err1, workspace_edit) - if err1 then - print("Could not execute java/generateDelegateMethods", err1.message) - elseif workspace_edit then - vim.lsp.util.apply_workspace_edit(workspace_edit, "utf-16") - end - end) - end) -end - -local function java_hash_code_equals_prompt(_, outer_ctx) - local params = outer_ctx.params - vim.lsp.buf_request(0, "java/checkHashCodeEqualsStatus", params, function(_, result, ctx) - if not result or not result.fields or #result.fields == 0 then - print(string.format("The operation is not applicable to the type %", result.type)) - return - end - local lines = {} - for _, x in pairs(result.fields) do - table.insert(lines, string.format("%s: %s", x.name, x.type)) - end - local idxs = vim.fn["quickui#checkbox#open"](lines, { title = "Select Fields" }) - local fields = {} - for _, idx in pairs(idxs) do - table.insert(fields, result.fields[tonumber(idx) + 1]) - end - vim.lsp.buf_request( - ctx.bufnr, - "java/generateHashCodeEquals", - { context = params, fields = fields }, - function(e, edit) - if e then - print("Could not execute java/generateHashCodeEquals: " .. e.message) - end - if edit then - vim.lsp.util.apply_workspace_edit(edit, "utf-16") - end - end - ) - end) -end - -local function java_action_organize_imports(_, ctx) - vim.lsp.buf_request(0, "java/organizeImports", ctx.params, function(err, resp) - if err then - print("Error on organize imports: " .. err.message) - return - end - if resp then - vim.lsp.util.apply_workspace_edit(resp, "utf-16") - end - end) -end - -local function java_choose_imports(resp) - local uri = resp[1] - local selections = resp[2] - local choices = {} - for _, selection in ipairs(selections) do - local start = selection.range.start - - local buf = vim.uri_to_bufnr(uri) - vim.api.nvim_win_set_buf(0, buf) - vim.api.nvim_win_set_cursor(0, { start.line + 1, start.character }) - vim.api.nvim_command "normal! zvzz" - vim.api.nvim_buf_add_highlight( - 0, - highlight_ns, - "IncSearch", - start.line, - start.character, - selection.range["end"].character - ) - vim.api.nvim_command "redraw" - local candidates = selection.candidates - local fqn = candidates[1].fullyQualifiedName - local type_name = fqn:sub(find_last(fqn, "%.") + 1) - local choice - if #candidates == 1 then - choice = candidates[1] - elseif #candidates > 1 then - local lines = {} - for _, x in pairs(candidates) do - table.insert(lines, x.fullyQualifiedName) - end - local idx = vim.fn["quickui#listbox#inputlist"](lines, { - index = -1, - title = "Choose type " .. type_name .. " to import", - }) - choice = candidates[idx + 1] - end - - vim.api.nvim_buf_clear_namespace(0, highlight_ns, 0, -1) - table.insert(choices, choice) - end - return choices -end - -M.commands = { - ["java.action.generateToStringPrompt"] = java_generate_to_string_prompt, - ["java.action.hashCodeEqualsPrompt"] = java_hash_code_equals_prompt, - ["java.action.organizeImports"] = java_action_organize_imports, - ["java.action.organizeImports.chooseImports"] = java_choose_imports, - ["java.action.generateConstructorsPrompt"] = java_generate_constructors_prompt, - ["java.action.generateDelegateMethodsPrompt"] = java_generate_delegate_methods_prompt, -} - -local function make_code_action_params(from_selection) - local params - if from_selection then - params = vim.lsp.util.make_given_range_params() - else - params = vim.lsp.util.make_range_params() - end - local bufnr = vim.api.nvim_get_current_buf() - params.context = { - diagnostics = vim.lsp.diagnostic.get_line_diagnostics(bufnr), - } - return params -end - -function M.organize_imports() - java_action_organize_imports(nil, { params = make_code_action_params(false) }) -end - -function M.setup() - if vim.lsp.commands then - for k, v in pairs(M.commands) do - vim.lsp.commands[k] = v - end - end - if not vim.lsp.handlers["workspace/executeClientCommand"] then - vim.lsp.handlers["workspace/executeClientCommand"] = function(_, params, ctx) - local fn = M.commands[params.command] - if fn then - local ok, result = pcall(fn, params.arguments, ctx) - if ok then - return result - else - return vim.lsp.rpc_response_error(vim.lsp.protocol.ErrorCodes.InternalError, result) - end - else - return vim.lsp.rpc_response_error( - vim.lsp.protocol.ErrorCodes.MethodNotFound, - "Command " .. params.command .. " not supported on client" - ) - end - end - end -end - -return M diff --git a/lua/plugins/lsp/servers/init.lua b/lua/plugins/lsp/servers/init.lua index 4ab7f9da..9cc9c50f 100644 --- a/lua/plugins/lsp/servers/init.lua +++ b/lua/plugins/lsp/servers/init.lua @@ -18,6 +18,7 @@ for _, server in ipairs { "lua_ls", "tsserver", "null-ls", + "jdtls", } do require("plugins.lsp.servers." .. server).setup() end @@ -36,6 +37,7 @@ for _, server in ipairs { "cmake", "texlab", "vimls", + "lemminx", -- for xml } do lspconfig[server].setup(c.default()) end diff --git a/lua/plugins/lsp/servers/jdtls.lua b/lua/plugins/lsp/servers/jdtls.lua new file mode 100644 index 00000000..026d8280 --- /dev/null +++ b/lua/plugins/lsp/servers/jdtls.lua @@ -0,0 +1,88 @@ +--===================================================================== +-- +-- jdtls.lua - +-- +-- Created by liubang on 2023/02/18 02:27 +-- Last Modified: 2023/02/18 02:27 +-- +--===================================================================== + +local M = {} +local c = require "plugins.lsp.customs" + +local real_setup = function() + local settings = { + ["java.format.settings.profile"] = "GoogleStyle", + java = { + signatureHelp = { enabled = true }, + contentProvider = { preferred = "fernflower" }, + completion = { + favoriteStaticMembers = { + "org.hamcrest.MatcherAssert.assertThat", + "org.hamcrest.Matchers.*", + "org.hamcrest.CoreMatchers.*", + "org.junit.jupiter.api.Assertions.*", + "java.util.Objects.requireNonNull", + "java.util.Objects.requireNonNullElse", + "org.mockito.Mockito.*", + }, + }, + filteredTypes = { + "com.sun.*", + "io.micrometer.shaded.*", + "java.awt.*", + "jdk.*", + "sun.*", + }, + sources = { + organizeImports = { + starThreshold = 9999, + staticStarThreshold = 9999, + }, + }, + codeGeneration = { + toString = { + template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}", + }, + }, + configuration = { + runtimes = { + { + name = "JavaSE-17", + path = "/opt/app/java", + }, + }, + }, + }, + } + + local jdtls = require "jdtls" + local extendedClientCapabilities = jdtls.extendedClientCapabilities + extendedClientCapabilities.resolveAdditionalTextEditsSupport = true + + jdtls.setup.add_commands() + jdtls.start_or_attach(c.default { + cmd = { "jdtls" }, + flags = { + allow_incremental_sync = true, + }, + single_file_support = true, + on_init = function(client, _) + client.notify("workspace/didChangeConfiguration", { settings = settings }) + end, + init_options = { + extendedClientCapabilities = extendedClientCapabilities, + }, + }) +end + +function M.setup() + vim.api.nvim_create_autocmd("FileType", { + pattern = { "java", "pom" }, + callback = function(_) + real_setup() + end, + }) +end + +return M diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua index fa3685f6..88e6088c 100644 --- a/lua/plugins/lualine.lua +++ b/lua/plugins/lualine.lua @@ -66,6 +66,7 @@ function M.config() yamlls = "YAML", cssls = "CSS", emmet_ls = "EMMET", + jdtls = "Java", } --}}} @@ -106,6 +107,13 @@ function M.config() readonly = " \u{f023}", unnamed = "[No Name]", }, + cond = function() + local f = vim.fn.expand "%:p" + if f:len() > 6 and f:sub(0, 6) == "jdt://" then + return false + end + return true + end, }, { filesize,