diff --git a/init.lua b/init.lua index eee9f3c0..ff2be2e2 100644 --- a/init.lua +++ b/init.lua @@ -88,6 +88,14 @@ require('lazy').setup({ -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` { 'j-hui/fidget.nvim', tag = 'legacy', opts = {} }, + -- make signature of lsp better + { + "ray-x/lsp_signature.nvim", + event = "VeryLazy", + opts = {}, + config = function(_, opts) require 'lsp_signature'.setup(opts) end + }, + -- Additional lua configuration, makes nvim stuff amazing! 'folke/neodev.nvim', }, @@ -243,32 +251,37 @@ vim.o.hlsearch = false -- Make line numbers default vim.wo.number = true +vim.wo.relativenumber = true -- Enable mouse mode -vim.o.mouse = false +vim.o.mouse = 'a' -- Sync clipboard between OS and Neovim. -- Remove this option if you want your OS clipboard to remain independent. -- See `:help 'clipboard'` -- vim.o.clipboard = 'unnamedplus' --- Copy-paste -vim.keymap.set('v', 'p', '"_dP') +vim.keymap.set('n', 'p', '"_dP') +vim.keymap.set('n', 'p', '"+p') vim.keymap.set('n', 'y', '"+y') vim.keymap.set('v', 'y', '"+y') vim.keymap.set('n', 'Y', 'gg"+yG') vim.keymap.set('n', 'd', '"_d') vim.keymap.set('v', 'd', '"_d') + -- Needed to sync windows clipboard with wsl vim.g.clipboard = { name = 'WslClipboard', copy = { - ['+'] = 'clip.exe', - ['*'] = 'clip.exe', + ['+'] = '/mnt/c/Windows/System32/clip.exe', + ['*'] = '/mnt/c/Windows/System32/clip.exe', }, paste = { - ['+'] = 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))', - ['*'] = 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))', + ['+'] = + '/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))', + ['*'] = + '/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))', }, cache_enabled = 0, } @@ -282,6 +295,24 @@ vim.o.undofile = true vim.o.ignorecase = true vim.o.smartcase = true +-- Disable wordwrap be default +vim.opt.wrap = false + +-- Enable wordwrap when writing markdown +vim.cmd([[ +augroup markdown + autocmd! + autocmd FileType markdown set wrap + autocmd FileType markdown set textwidth=144 +augroup end +]]) + +-- Set column +vim.opt.colorcolumn = "144" + +-- Always have lines in the bottom of the file +vim.opt.scrolloff = 8 + -- Keep signcolumn on by default vim.wo.signcolumn = 'yes' @@ -330,11 +361,23 @@ require('telescope').setup { defaults = { path_display = { shorten = { len = 3, exclude = { 1, 2, 3, -3, -2, -1 } } }, + preview = { + hide_on_startup = false -- hide previewer when picker starts + }, + mappings = { i = { [''] = false, - [''] = false, + [''] = false, + [''] = require('telescope.actions.layout').toggle_preview, + [''] = require('telescope.actions').delete_buffer, + [''] = require('telescope.actions').file_vsplit, }, + n = { + [''] = false, -- + [''] = require('telescope.actions').delete_buffer, + [''] = require('telescope.actions').file_vsplit, + } }, }, } @@ -469,6 +512,38 @@ local servers = { -- rust_analyzer = {}, -- tsserver = {}, -- html = { filetypes = { 'html', 'twig', 'hbs'} }, + yamlls = { + yaml = { + schemaStore = { + -- You must disable built-in schemaStore support if you want to use + -- this plugin and its advanced options like `ignore`. + enable = false, + }, + schemas = { + ["https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json"] = + "**/*swagger.{yml,yaml}", + ["https://json.schemastore.org/liquibase-3.2.json"] = "**/*Changelog*.{yml,yaml}", + }, + format = { + enable = true, + singleQuote = false, + bracketSpacing = true + }, + validate = true, + completion = true, + http = { + proxy = "http://webproxy.nykreditnet.net:8080", + }, + }, + }, + cucumber_language_server = { + cucumber = { + -- features = { "**/lctest/**/*.feature" }, + -- glue = { + -- "**/lctest/**/stepdef/**/*.java", + -- } + } + }, lua_ls = { Lua = { workspace = { checkThirdParty = false }, @@ -523,6 +598,10 @@ cmp.setup { luasnip.lsp_expand(args.body) end, }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered() + }, mapping = cmp.mapping.preset.insert { [''] = cmp.mapping.select_next_item(), [''] = cmp.mapping.select_prev_item(), @@ -530,7 +609,7 @@ cmp.setup { [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete {}, [''] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, + behavior = cmp.ConfirmBehavior.Insert, select = true, }, [''] = cmp.mapping(function(fallback) diff --git a/lang_servers/nykredit_java_style.xml b/lang_servers/nykredit_java_style.xml new file mode 100755 index 00000000..4439c8bb --- /dev/null +++ b/lang_servers/nykredit_java_style.xml @@ -0,0 +1,380 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lua/custom/plugins/filetree.lua b/lua/custom/plugins/filetree.lua index cd8469c7..9394bd8d 100644 --- a/lua/custom/plugins/filetree.lua +++ b/lua/custom/plugins/filetree.lua @@ -15,7 +15,36 @@ return { follow_current_file = { enabled = true, -- This will find and focus the file in the active buffer every time leave_dirs_open = false - } + }, + group_empty_dirs = true, -- when true, empty folders will be grouped together + }, + -- If you don't want to use these columns, you can set `enabled = false` for each of them individually + file_size = { + enabled = false, + required_width = 64, -- min width of window required to show this column + }, + type = { + enabled = false, + required_width = 122, -- min width of window required to show this column + }, + last_modified = { + enabled = false, + required_width = 88, -- min width of window required to show this column + }, + created = { + enabled = false, + required_width = 110, -- min width of window required to show this column + }, + symlink_target = { + enabled = false, + }, + window = { + position = "left", + width = 60, + mapping_options = { + noremap = true, + nowait = true, + }, } } end, diff --git a/lua/custom/plugins/nvim-jdtls.lua b/lua/custom/plugins/nvim-jdtls.lua index 5d139783..f45d8a2d 100644 --- a/lua/custom/plugins/nvim-jdtls.lua +++ b/lua/custom/plugins/nvim-jdtls.lua @@ -16,6 +16,8 @@ return { local jdtls_pkg = mason_registry.get_package("jdtls") local jdtls_path = jdtls_pkg:get_install_path() local jdtls_bin = jdtls_path .. "/bin/jdtls" + local equinox_launcher = vim.fn.glob(jdtls_path .. "/plugins/org.eclipse.equinox.launcher_*.jar") + -- local equinox = jdtls_path .. "/plugins/org.eclipse.equinox.launcher_1.6.500.v20230717-2134.jar" local java_test_pkg = mason_registry.get_package("java-test") local java_test_path = java_test_pkg:get_install_path() @@ -27,7 +29,8 @@ return { local jar_patterns = { java_dbg_path .. "/extension/server/com.microsoft.java.debug.plugin-*.jar", - java_test_path .. "/extension/server/*.jar", + -- enable java test, and disable vscode_java_test when version of com.microsoft.java.test.plugin-*.jar is 0.40.0 or higher + -- java_test_path .. "/extension/server/*.jar", vscode_java_test_path .. "/*.jar" } @@ -59,14 +62,30 @@ return { staticStarThreshold = 9999, }, }, + references = { + includeDecompiledSources = true, + }, codeGeneration = { toString = { template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}" } }, + format = { + enabled = true, + settings = { + url = vim.fn.stdpath("config") .. "/lang_servers/nykredit-java-style.xml", + profile = "Nykredit", + }, + }, + autobuild = { + enabled = true + }, maven = { downloadSources = true, }, + rename = { + enabled = true + }, import = { maven = { enabled = true, @@ -78,6 +97,10 @@ return { }, }, configuration = { + updateBuildConfiguration = "interactive", + maven = { + userSettings = nil, + }, runtimes = { { name = "JavaSE-1.8", @@ -97,8 +120,10 @@ return { -- path = "/usr/lib/jvm/java-19-openjdk-amd64", -- }, } - } - } + }, + project = { + }, + }, } local function print_test_results(items) @@ -118,16 +143,23 @@ return { -- calculate workspace dir local workspace_folder = home .. "/.cache/jdtls/workspace/" .. project_name - local capabilities = require("cmp_nvim_lsp").default_capabilities() - local on_attach = function(_, buffer) - require('lsp.keymap').on_attach(_, buffer) + local capabilities = require("cmp_nvim_lsp").default_capabilities() + capabilities.workspace = { + configuration = true + } + + local on_attach = function(client, buffer) + vim.opt.omnifunc = 'v:v:lua.vim.lsp.omnifunc' + + require("jdtls").setup_dap({ config_overrides = {}, hotcodereplace = "auto" }) + require("jdtls.dap").setup_dap_main_class_configs() + require('lsp.keymap').on_attach(client, buffer) -- custom keymaps vim.keymap.set("n", "co", function() require("jdtls").organize_imports() end, { buffer = buffer, desc = "LSP: Organize Imports" }) - vim.keymap.set('n', 'ct', function() require('jdtls').test_class() end, { buffer = buffer, desc = 'LSP: Run test class' }) @@ -138,8 +170,32 @@ return { function() require("jdtls").pick_test({ bufnr = buffer, after_test = print_test_results }) end, { buffer = buffer, desc = "LSP: Run Single Test" }) - require("jdtls").setup_dap({ hotcodereplace = "auto" }) - require("jdtls.dap").setup_dap_main_class_configs() + vim.keymap.set("n", "gt", function() require('jdtls.tests').goto_subjects() end, + { buffer = buffer, desc = "LSP: [G]o to [T]est class" }) + + -- NOTE: Java specific keymaps with which key + vim.cmd( + "command! -buffer -nargs=? -complete=custom,v:lua.require'jdtls'._complete_compile JdtCompile lua require('jdtls').compile()" + ) + vim.cmd( + "command! -buffer -nargs=? -complete=custom,v:lua.require'jdtls'._complete_set_runtime JdtSetRuntime lua require('jdtls').set_runtime()" + ) + vim.cmd("command! -buffer JdtUpdateConfig lua require('jdtls').update_project_config()") + vim.cmd("command! -buffer JdtJol lua require('jdtls').jol()") + vim.cmd("command! -buffer JdtBytecode lua require('jdtls').javap()") + vim.cmd("command! -buffer JdtJshell lua require('jdtls').jshell()") + + -- Highlighter for variables and such + vim.cmd([[ + " hi LspReferenceRead cterm=bold ctermbg=red guibg=DarkGrey + " hi LspReferenceText cterm=bold ctermbg=red guibg=DarkGrey + " hi LspReferenceWrite cterm=bold ctermbg=red guibg=DarkGrey + augroup LspHighlight + autocmd! + autocmd CursorHold lua vim.lsp.buf.document_highlight() + autocmd CursorMoved lua vim.lsp.buf.clear_references() + augroup END + ]]) end -- get the mason install path @@ -148,14 +204,61 @@ return { bundles = bundles, extendedClientCapabilities = extendedClientCapabilities, }, + + -- cmd = { + -- -- + -- -- -- ?? + -- "/usr/lib/jvm/java-17-openjdk-amd64/bin/java", -- or '/path/to/java17_or_newer/bin/java' + -- -- depends on if `java` is in your $PATH env variable and if it points to the right version. + -- + -- "-Declipse.application=org.eclipse.jdt.ls.core.id1", + -- "-Dosgi.bundles.defaultStartLevel=4", + -- "-Declipse.product=org.eclipse.jdt.ls.core.product", + -- "-Dlog.protocol=true", + -- "-Dlog.level=ALL", + -- "-Xmx1g", + -- "-javaagent:" .. jdtls_path .. "/lombok.jar", + -- "--add-modules=ALL-SYSTEM", + -- "--add-opens", "java.base/java.util=ALL-UNNAMED", + -- "--add-opens", "java.base/java.lang=ALL-UNNAMED", + -- "--add-opens", "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", + -- "--add-opens", "jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", + -- "--add-opens", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", + -- "--add-opens", "jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", + -- "--add-opens", "jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", + -- "--add-opens", "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", + -- "--add-opens", "jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", + -- "--add-opens", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", + -- "--add-opens", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + -- "--add-opens", "jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", + -- + -- -- ?? + -- "-jar", + -- equinox_launcher, + -- -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ + -- -- Must point to the Change this to + -- -- eclipse.jdt.ls installation the actual version + -- + -- -- ?? + -- "-configuration", + -- jdtls_path .. "/config_linux", + -- -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^ + -- -- Must point to the Change to one of `linux`, `win` or `mac` + -- -- eclipse.jdt.ls installation Depending on your system. + -- + -- -- See `data directory configuration` section in the README + -- "-data", + -- workspace_folder, + -- }, cmd = { jdtls_bin, "--jvm-arg=-javaagent:" .. jdtls_path .. "/lombok.jar", + "--jvm-arg=-Dlog.level=ALL", + -- "--jvm-arg=--add-opens jdk.compiler/com.sun.javac.tree=ALL-UNNAMED", "-data", workspace_folder, }, - -- attach general lsp 'on_attach function' - -- on_attach = require("lsp.keymap").on_attach, + -- -- attach general lsp 'on_attach function' on_attach = on_attach, capabilities = capabilities, -- we naively believe that the whole project is versioned through git, and therefore diff --git a/lua/lsp/keymap.lua b/lua/lsp/keymap.lua index 9c520eb3..529cc4ad 100644 --- a/lua/lsp/keymap.lua +++ b/lua/lsp/keymap.lua @@ -1,8 +1,6 @@ - - -- This function gets run when an LSP connects to a particular buffer. return { - on_attach = function(_, bufnr) + on_attach = function(client, bufnr) -- NOTE: Remember that lua is a real programming language, and as such it is possible -- to define small helper and utility functions so you don't have to repeat yourself -- many times. @@ -43,5 +41,14 @@ return { vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) vim.lsp.buf.format() end, { desc = 'Format current buffer with LSP' }) + + require("lsp_signature").on_attach({ + bind = true, + padding = "", + handler_opts = { + border = "rounded", + }, + hint_prefix = "󱄑 ", + }, bufnr) end }