diff --git a/.gitignore b/.gitignore index 005b535b606..ca1f63b7452 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ nvim spell/ lazy-lock.json +node_modules diff --git a/ftplugin/java.lua b/ftplugin/java.lua new file mode 100644 index 00000000000..b530f6fd7fa --- /dev/null +++ b/ftplugin/java.lua @@ -0,0 +1,47 @@ +local jdtls = require 'jdtls' + +-- 1. Root and Workspace +local root_markers = { '.git', 'mvnw', 'gradlew', 'pom.xml', 'build.gradle' } +local root_dir = require('jdtls.setup').find_root(root_markers) +local project_name = vim.fn.fnamemodify(root_dir, ':p:h:t') +local workspace_dir = vim.fn.stdpath 'data' .. '/jdtls-workspace/' .. project_name + +-- 2. Direct path to Mason packages (Avoids the 'nil' API error) +local mason_path = vim.fn.stdpath 'data' .. '/mason/packages/' +local bundles = { + vim.fn.glob(mason_path .. 'java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar', true), +} + +-- Add Java Test bundles +local test_jars = vim.fn.glob(mason_path .. 'java-test/extension/server/*.jar', true) +if test_jars ~= '' then + vim.list_extend(bundles, vim.split(test_jars, '\n')) +end + +-- 3. Configuration +local config = { + cmd = { + 'jdtls', + '-data', + workspace_dir, + -- Ensure jdtls is in your PATH. If not, use the full path to the executable: + -- vim.fn.stdpath("data") .. "/mason/bin/jdtls" + }, + root_dir = root_dir, + init_options = { + bundles = bundles, + }, + on_attach = function(client, bufnr) + -- This links the Debugger to the LSP session + jdtls.setup_dap { hotcodereplace = 'auto' } + require('jdtls.dap').setup_dap_main_class_configs() + + -- Sync Kickstart highlighting + if client.server_capabilities.semanticTokensProvider then + vim.lsp.semantic_tokens.start(bufnr, client.id) + end + end, +} + +-- 4. Start +jdtls.start_or_attach(config) diff --git a/init.lua b/init.lua index b98ffc6198a..ee0d24cfed9 100644 --- a/init.lua +++ b/init.lua @@ -91,7 +91,7 @@ vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -- Set to true if you have a Nerd Font installed and selected in the terminal -vim.g.have_nerd_font = false +vim.g.have_nerd_font = true -- [[ Setting options ]] -- See `:help vim.o` @@ -102,7 +102,7 @@ vim.g.have_nerd_font = false vim.o.number = true -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! --- vim.o.relativenumber = true +vim.o.relativenumber = true -- Enable mouse mode, can be useful for resizing splits for example! vim.o.mouse = 'a' @@ -120,6 +120,11 @@ end) -- Enable break indent vim.o.breakindent = true +vim.o.expandtab = true -- Convert tabs to spaces +vim.o.shiftwidth = 4 -- Number of spaces to use for each step of (auto)indent +vim.o.softtabstop = 4 -- Number of spaces a counts for while performing editing operations +vim.o.autoindent = true -- Indent a new line the same amount as the line just typed +vim.o.smartindent = true -- Smart indentation with braces -- Save undo history vim.o.undofile = true @@ -151,6 +156,7 @@ vim.o.splitbelow = true -- and `:help lua-options-guide` vim.o.list = true vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } +vim.opt.tabstop = 4 -- Preview substitutions live, as you type! vim.o.inccommand = 'split' @@ -233,7 +239,6 @@ end ---@type vim.Option local rtp = vim.opt.rtp rtp:prepend(lazypath) - -- [[ Configure and install plugins ]] -- -- To check the current status of your plugins, run @@ -247,7 +252,14 @@ rtp:prepend(lazypath) -- NOTE: Here is where you install your plugins. require('lazy').setup({ -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link). - 'NMAC427/guess-indent.nvim', -- Detect tabstop and shiftwidth automatically + { + 'NMAC427/guess-indent.nvim', + config = function() + require('guess-indent').setup { + auto_cmd = true, + } + end, + }, -- NOTE: Plugins can also be added by using a table, -- with the first argument being the link and the following @@ -271,18 +283,6 @@ require('lazy').setup({ -- options to `gitsigns.nvim`. -- -- See `:help gitsigns` to understand what the configuration keys do - { -- Adds git related signs to the gutter, as well as utilities for managing changes - 'lewis6991/gitsigns.nvim', - opts = { - signs = { - add = { text = '+' }, - change = { text = '~' }, - delete = { text = '_' }, - topdelete = { text = '‾' }, - changedelete = { text = '~' }, - }, - }, - }, -- NOTE: Plugins can also be configured to run Lua code when they are loaded. -- @@ -344,13 +344,22 @@ require('lazy').setup({ -- Document existing key chains spec = { - { 's', group = '[S]earch' }, + { 'f', group = '[F]ind' }, + { 's', group = '[S]ession' }, { 't', group = '[T]oggle' }, { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, }, }, }, + { + 'folke/persistence.nvim', + event = 'BufReadPre', -- this will only start session saving when an actual file was opened + opts = { + -- add any custom options here + }, + }, + -- NOTE: Plugins can specify dependencies. -- -- The dependencies are proper plugin specifications as well - anything @@ -412,7 +421,6 @@ require('lazy').setup({ -- i = { [''] = 'to_fuzzy_refine' }, -- }, -- }, - -- pickers = {} extensions = { ['ui-select'] = { require('telescope.themes').get_dropdown(), @@ -426,17 +434,38 @@ require('lazy').setup({ -- See `:help telescope.builtin` local builtin = require 'telescope.builtin' - vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) - vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) - vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) - vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) - vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) - vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) - vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) - vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) - vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) + vim.keymap.set('n', 'fh', builtin.help_tags, { desc = '[H]elp' }) + vim.keymap.set('n', 'fk', builtin.keymaps, { desc = '[K]eymaps' }) + vim.keymap.set('n', 'ff', builtin.find_files, { desc = '[F]iles' }) + vim.keymap.set('n', 'fs', builtin.builtin, { desc = '[S]elect Telescope' }) + vim.keymap.set('n', 'fw', builtin.grep_string, { desc = 'current [W]ord' }) + vim.keymap.set('n', 'fg', builtin.live_grep, { desc = 'by [G]rep' }) + vim.keymap.set('n', 'fd', builtin.diagnostics, { desc = '[D]iagnostics' }) + vim.keymap.set('n', 'fr', builtin.resume, { desc = '[R]esume' }) + vim.keymap.set('n', 'f.', builtin.oldfiles, { desc = 'Recent Files ("." for repeat)' }) vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + -- Session + -- load the session for the current directory + vim.keymap.set('n', 'ss', function() + require('persistence').load() + end, { desc = '[s]ession for the current dir' }) + + -- select a session to load + vim.keymap.set('n', 'sw', function() + require('persistence').select() + end, { desc = '[w]hich session to load' }) + + -- load the last session + vim.keymap.set('n', 'sl', function() + require('persistence').load { last = true } + end, { desc = '[l]ast session' }) + + -- stop Persistence => session won't be saved on exit + vim.keymap.set('n', 'sd', function() + require('persistence').stop() + end, { desc = "[d]on't save this session" }) + -- Slightly advanced example of overriding default behavior and theme vim.keymap.set('n', '/', function() -- You can pass additional configuration to Telescope to change the theme, layout, etc. @@ -448,33 +477,19 @@ require('lazy').setup({ -- It's also possible to pass additional configuration options. -- See `:help telescope.builtin.live_grep()` for information about particular keys - vim.keymap.set('n', 's/', function() + vim.keymap.set('n', 'f/', function() builtin.live_grep { grep_open_files = true, prompt_title = 'Live Grep in Open Files', } - end, { desc = '[S]earch [/] in Open Files' }) + end, { desc = '[/] in Open Files' }) -- Shortcut for searching your Neovim configuration files - vim.keymap.set('n', 'sn', function() + vim.keymap.set('n', 'fn', function() builtin.find_files { cwd = vim.fn.stdpath 'config' } - end, { desc = '[S]earch [N]eovim files' }) + end, { desc = '[N]eovim files' }) end, }, - - -- LSP Plugins - { - -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins - -- used for completion, annotations and signatures of Neovim apis - 'folke/lazydev.nvim', - ft = 'lua', - opts = { - library = { - -- Load luvit types when the `vim.uv` word is found - { path = '${3rd}/luv/library', words = { 'vim%.uv' } }, - }, - }, - }, { -- Main LSP Configuration 'neovim/nvim-lspconfig', @@ -671,9 +686,11 @@ require('lazy').setup({ -- - settings (table): Override the default settings passed when initializing the server. -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ local servers = { - -- clangd = {}, - -- gopls = {}, - -- pyright = {}, + clangd = {}, + gopls = {}, + pyright = {}, + prettier = {}, + tailwindcss = {}, -- rust_analyzer = {}, -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs -- @@ -716,12 +733,20 @@ require('lazy').setup({ local ensure_installed = vim.tbl_keys(servers or {}) vim.list_extend(ensure_installed, { 'stylua', -- Used to format Lua code + 'markdownlint', + 'hadolint', + 'clangd', }) require('mason-tool-installer').setup { ensure_installed = ensure_installed } require('mason-lspconfig').setup { ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer) automatic_installation = false, + automatic_enable = { + exclude = { + 'jdtls', + }, + }, handlers = { function(server_name) local server = servers[server_name] or {} @@ -742,12 +767,12 @@ require('lazy').setup({ cmd = { 'ConformInfo' }, keys = { { - 'f', + 'o', function() require('conform').format { async = true, lsp_format = 'fallback' } end, mode = '', - desc = '[F]ormat buffer', + desc = 'F[o]rmat buffer', }, }, opts = { @@ -769,7 +794,9 @@ require('lazy').setup({ formatters_by_ft = { lua = { 'stylua' }, -- Conform can also run multiple formatters sequentially - -- python = { "isort", "black" }, + python = { 'isort', 'black' }, + go = { 'goimports', 'gofmt' }, + css = { 'prettier' }, -- -- You can use 'stop_after_first' to run the first available formatter from the list -- javascript = { "prettierd", "prettier", stop_after_first = true }, @@ -886,6 +913,7 @@ require('lazy').setup({ config = function() ---@diagnostic disable-next-line: missing-fields require('tokyonight').setup { + transparent = true, styles = { comments = { italic = false }, -- Disable italics in comments }, @@ -973,18 +1001,18 @@ require('lazy').setup({ -- Here are some example plugins that I've included in the Kickstart repository. -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- - -- require 'kickstart.plugins.debug', - -- require 'kickstart.plugins.indent_line', - -- require 'kickstart.plugins.lint', - -- require 'kickstart.plugins.autopairs', - -- require 'kickstart.plugins.neo-tree', - -- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps + require 'kickstart.plugins.debug', + require 'kickstart.plugins.indent_line', + require 'kickstart.plugins.lint', + require 'kickstart.plugins.autopairs', + require 'kickstart.plugins.neo-tree', + require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` -- This is the easiest way to modularize your config. -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, -- -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` -- Or use telescope! diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 8e332bf2ff9..211fdb07275 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -23,6 +23,9 @@ return { -- Add your own debuggers here 'leoluz/nvim-dap-go', + + -- java + 'mfussenegger/nvim-jdtls', }, keys = { -- Basic debugging keymaps, feel free to change to your liking! @@ -95,6 +98,9 @@ return { ensure_installed = { -- Update this to ensure that you have the debuggers for the langs you want 'delve', + 'cpptools', + 'java-debug-adapter', + 'java-test', }, } @@ -136,6 +142,16 @@ return { dap.listeners.before.event_terminated['dapui_config'] = dapui.close dap.listeners.before.event_exited['dapui_config'] = dapui.close + dap.configurations.java = { + { + type = 'java', + request = 'launch', + name = 'Debug (Launch) - Current File', + mainClass = '${file}', -- This tells it to just try the current file + projectName = 'temp-project', + }, + } + -- Install golang specific config require('dap-go').setup { delve = { diff --git a/lua/kickstart/plugins/lint.lua b/lua/kickstart/plugins/lint.lua index dec42f097c6..219b1e60176 100644 --- a/lua/kickstart/plugins/lint.lua +++ b/lua/kickstart/plugins/lint.lua @@ -7,6 +7,7 @@ return { local lint = require 'lint' lint.linters_by_ft = { markdown = { 'markdownlint' }, + dockerfile = { 'hadolint' }, } -- To allow other plugins to add linters to require('lint').linters_by_ft, diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000000..0e961e54421 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,28 @@ +{ + "name": "nvim", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "devDependencies": { + "prettier": "3.7.4" + } + }, + "node_modules/prettier": { + "version": "3.7.4", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.7.4.tgz", + "integrity": "sha512-v6UNi1+3hSlVvv8fSaoUbggEM5VErKmmpGA7Pl3HF8V6uKY7rvClBOJlH6yNwQtfTueNkGVpOv/mtWL9L4bgRA==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000000..a63f0e59873 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "devDependencies": { + "prettier": "3.7.4" + } +}