neovim: faster startup on win32
694ad9772316a3bada33f33420cf9c32c1a42106
Oliver Krylow <o.krylow@isp-insoft.de> ·
unsigned
- Parent 1: b6f4c75d4b46
bugabingas dorkfiles
694ad9772316a3bada33f33420cf9c32c1a42106
Oliver Krylow <o.krylow@isp-insoft.de> ·
unsigned
+21 / −427 text lines
+3 / −0 text lines
deleted file mode 100644No text changes.
deleted file mode 100644+0 / −5 text lines
deleted file mode 100644No text changes.
deleted file mode 100644+0 / −10 text lines
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rule.jsonid: vim.validation.deprecationlanguage: Luaseverity: errormessage: Add your rule message here....rule: pattern: vim.validate { $VALUE = { $VALUE, $TYPE } }fix: vim.validate('$VALUE', $VALUE, $TYPE)note: vim.validate API in neovim 0.11 got deprecated in favor of new signaturedeleted file mode 100644No text changes.
+0 / −1 text lines
+0 / −2 text lines
deleted file mode 100644+0 / −263 text lines
local puk = require 'std.puk'local project = require 'std.project'local auto = require 'std.auto'local map = require 'std.map'local dbg = require 'std.dbg'local localrc = require 'std.localrc'local table = require 'std.table'local jdtls_ss_id = nillocal create_config = function(syntax_server_mode, path) local data_path = vim.fn.stdpath 'data' if type(data_path) == 'table' then data_path = data_path[1] end local home = vim.fs.abspath '~' local tools_path = vim.fs.joinpath(home, 'Tools') local jdtls_jre_path = vim.fs.find(function(name) return name:match 'graalvm%-community%-openjdk%-25.*' end, { path = tools_path, type = 'directory' })[1] local jdtls_install_path = vim.fs.find(function(name) return name:match 'jdt%-language%-server%-1%.49.*' end, { path = tools_path, type = 'directory' })[1] local plugins_path = vim.fs.joinpath(jdtls_install_path, 'plugins') local launcher_path = vim.fs.find(function(name) return name:match 'org%.eclipse%.equinox%.launcher_.*' end, { path = plugins_path, type = 'file' })[1] local project_local_settings = localrc('.jdtls.lua', 'table') or {} project_local_settings.jdtls = project_local_settings.jdtls or {} local find_runtimes = function() local runtimes = {} table.insert(runtimes, { name = 'JavaSE-25', path = jdtls_jre_path, sources = vim.fs.joinpath(jdtls_jre_path, 'lib', 'src.zip'), default = true, }) if (project_local_settings.jdtls.runtimes) then return table.deep_extend('force', runtimes, project_local_settings.jdlts.runtimes) else return runtimes end end local root_dir = project.find_java_project_root(path) local jdlts_config_dir if syntax_server_mode then jdlts_config_dir = vim.fn.has 'win32' and 'config_ss_win' or 'config_ss_linux' else jdlts_config_dir = vim.fn.has 'win32' and 'config_win' or 'config_linux' end local config_dir = vim.fs.joinpath(jdtls_install_path, jdlts_config_dir) local workspace_dir = vim.fs.joinpath(data_path, 'jdtls-workspace', vim.fs.basename(root_dir)) local compiler_options_path = vim.fs.joinpath(home, '.config', 'jdlts', 'compiler_options.properties') local cmd = { vim.fs.joinpath(jdtls_jre_path, 'bin', 'java'), '-Declipse.application=org.eclipse.jdt.ls.core.id1', '-Dosgi.bundles.defaultStartLevel=4', '-Declipse.product=org.eclipse.jdt.ls.core.product', '-Dlog.level=ERROR', '-Xmx8G', '--add-modules=ALL-SYSTEM', '--add-opens', 'java.base/java.util=ALL-UNNAMED', '--add-opens', 'java.base/java.lang=ALL-UNNAMED', '--add-modules', 'jdk.incubator.vector', '--enable-native-access=ALL-UNNAMED', '-jar', launcher_path, '-configuration', config_dir, '-data', workspace_dir, } if syntax_server_mode then table.insert(cmd, 2, '-Dsyntaxserver=true') end local runtimes = find_runtimes() local config = { name = syntax_server_mode and 'jdtls_ss' or 'jdtls', cmd = cmd, root_dir = root_dir, settings = { java = { autobuild = { enabled = true }, cleanup = { actionsOnSave = { 'qualifyMembers', 'qualifyStaticMembers', 'addOverride', 'addDeprecated', 'stringConcatToTextBlock', 'invertEquals', 'addFinalModifier', 'instanceofPatternMatch', 'switchExpression', }, }, codeGeneration = { generateComments = false, hashCodeEquals = { useJava7Objects = true }, toString = { template = '${object.className}{${member.name()}=${member.value()}, ${otherMembers}}', }, useBlocks = true, }, codeAction = { sortMembers = { avoidVolatileChanges = true } }, completion = { enabled = true, favortiteStaticMembers = { 'org.junit.Assert.*', 'org.junit.Assume.*', 'org.junit.jupiter.api.Assertions.*', 'org.junit.jupiter.api.Assumptions.*', 'org.junit.jupiter.api.DynamicContainer.*', 'org.junit.jupiter.api.DynamicTest.*', 'org.assertj.core.api.Assertions.*', 'org.assertj.core.api.Assumptions.*', 'java.util.Objects.requireNonNull', 'java.util.Objects.requireNonNullElse', 'java.time.temporal.ChronoUnit.*', 'java.lang.System.Logger', 'java.lang.System.Logger.Level.*', }, filteredTypes = { -- Swing and AWT 'javax.swing.*', 'java.awt.*', -- CORBA 'org.omg.*', -- Applet 'java.applet.*', -- Legacy JAF 'javax.activation.*', -- Legacy Security 'java.security.acl.*', 'javax.security.auth.callback.*', -- Legacy XML/SOAP 'javax.xml.soap.*', 'javax.xml.rpc.*', -- RMI 'java.rmi.*', -- Legacy Collections 'java.util.Vector', 'java.util.Hashtable', 'java.util.Stack', 'java.util.Dictionary', -- Deprecated Classes 'java.util.Date', 'java.util.Calendar', 'java.util.Observable', 'java.util.Observer', -- Niche Packages 'javax.annotation.*', 'javax.jws.*', 'java.beans.*', 'javax.management.*', }, guessMethodArguments = false, importOrder = { 'net', 'de', 'org', 'com', 'javax', 'java', }, matchCase = 'FIRSTLETTER', maxResults = 5, overwrite = true, postfix = { enabled = true }, }, configuration = { runtimes = runtimes, updateBuildConfiguration = 'interactive', }, contentProvider = { preferred = nil }, eclipse = { downloadSources = true }, errors = { incompleteClassPath = { severity = 'error' } }, executeCommand = { enabled = true }, foldingRange = { enabled = false }, format = { enabled = true }, home = jdtls_jre_path, implementationsCodeLens = { enabled = true }, import = { maven = { enabled = true }, gradle = { enabled = true, annotationProcessing = true, wrapper = { enabled = true }, }, exclusions = { '**/output/**', '**/target/**', '**/node_modules/**', '**/.metadata/**', '**/archetype-resources/**', '**/META-INF/maven/**', }, }, inlayHints = { parameterNames = { enabled = 'all' } }, jdt = { ls = { androidSupport = false, lombokSupport = false, protofBufSupport = true, }, }, maven = { notCoveredPluginExecutionSeverity = 'error' }, maxConcurrentBuilds = 16, project = { encoding = 'SETDEFAULT', outputPath = project_local_settings.jdtls.outputPath, referencedLibraries = project_local_settings.jdtls.referencedLibraries, resourceFilters = project_local_settings.jdtls.resourceFilters, sourcePaths = project_local_settings.jdtls.sourcePaths, }, referencesCodeLens = { enabled = true }, references = { includeAccessors = true, includeDecompiledSources = true, }, rename = { enabled = true }, saveActions = { origanizeImports = true }, selectionRange = { enabled = true }, settings = { url = compiler_options_path, }, signatureHelp = { enabled = true }, sources = { organizeImports = { starThreshold = 9999, staticStarThreshold = 9999, }, }, symbols = { includeSourceMethodDeclarations = true }, trace = { server = dbg.get() and 'verbose' or 'off' }, edit = { validateAllOpenBuffersOnChanges = false }, }, }, handlers = { ['language/status'] = function(_, status) if status.message == 'ServiceReady' and jdtls_ss_id ~= nil then vim.notify('Stopping jdtls_ss: ' .. jdtls_ss_id) vim.lsp.stop_client(jdtls_ss_id, false) end end, }, } return configendauto 'start_jdtls' { pattern = 'java', events = 'FileType', description = 'Starts jdlts (with syntax mode initially)', command = function() local path = vim.api.nvim_buf_get_name(0) jdtls_ss_id = vim.lsp.start(create_config(true, path)) --TODO: figure out a way to choose between ss and full mode on demand. -- using the full server in script files is annoying puk 'jdtls'.start_or_attach(create_config(false, path)) end,}+0 / −3 text lines
+0 / −15 text lines
local togglers = require 'bugabinga.options.togglers'for _, toggler in ipairs(togglers) do local option_name = toggler.options[1].name local first_char = string.sub(option_name, 1, 1) map.normal { description = 'Toggle ' .. option_name .. ' option', category = 'options', keys = '<leader>t' .. first_char, command = function() toggler:toggle() end, }enddeleted file mode 100644+0 / −71 text lines
local icon = require 'std.icon'local togglers = {}local toggle_on_icon = icon.toggle_onlocal toggle_off_icon = icon.toggle_offlocal get_option = function(name) return vim.api.nvim_get_option_value(name, {}) endlocal set_option = function(name, value) vim.api.nvim_set_option_value(name, value, {}) endlocal toggle = function(self) vim.iter(self.options) :each(function(option) local current_value = get_option(option.name) if current_value == option.default then set_option(option.name, option.alternative) vim.notify(self.display_name .. ' ' .. toggle_on_icon) else set_option(option.name, option.default) vim.notify(self.display_name .. ' ' .. toggle_off_icon) end end)endlocal toggler_tostring = function(self) local all_default = vim.iter(self.options) :all(function(option) return get_option(option.name) == option.default end) return self.display_name .. ' ' .. (all_default and toggle_off_icon or toggle_on_icon)endlocal make_toggler = function(display_name, options) return { display_name = display_name, options = options, toggle = toggle, tostring = toggler_tostring }endlocal make_option = function(name, alternative) local option_value = get_option(name) alternative = alternative or not option_value return { name = name, default = option_value, alternative = alternative }endlocal add_toggler = function(display_name, options) table.insert(togglers, make_toggler(display_name, options))endadd_toggler(icon.spelling, { make_option 'spell' })add_toggler(icon.linenumber, { make_option 'number', make_option 'relativenumber' })add_toggler(icon.linehighlight, { make_option 'cursorline' })add_toggler(icon.wrap, { make_option 'wrap' })add_toggler(icon.list, { make_option 'list' })add_toggler(icon.virtual, { make_option('virtualedit', 'all') })local tostring = function(self) return vim.iter(self) :map(toggler_tostring) :fold('', function(buffer, text) return buffer .. (buffer == '' and '' or ' ') .. text end)endreturn setmetatable(togglers, { __tostring = tostring})+1 / −1 text lines
+16 / −13 text lines
-- Check if 'reg.exe' is executable if vim.fn.executable 'reg.exe' ~= 0 then -- Execute command to check if the win32 appearance is set to Dark local appsUseLightTheme = vim.fn.system { 'reg.exe', 'Query', 'HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize', '/v', 'AppsUseLightTheme' } if appsUseLightTheme:find '0x1' then background = 'light' end end return 'light' -- This takes around 100ms, too long for code in my startup path -- -- Check if 'reg.exe' is executable -- if vim.fn.executable 'reg.exe' ~= 0 then -- -- Execute command to check if the win32 appearance is set to Dark -- local result = vim.system( -- { 'reg.exe', 'Query', 'HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize', '/v', -- 'AppsUseLightTheme' }, { text = true, timeout = 2000 } ):wait() -- if result.code == 0 and result.stdout and result.stdout:find '0x1' then -- background = 'light' -- end -- end+0 / −8 text lines
deleted file mode 100644+0 / −6 text lines
deleted file mode 100644+0 / −8 text lines
UX Improvements- Status line: You're using laststatus = 3 (global status) but no custom statusline - consider integrating with incline.nvim or winbar- Tabline: With showtabline = 2, consider a custom tabline showing LSP diagnostics or git status- Keymap consistency: Your LSP mappings use gr prefix well - consider extending to other areas (debugging, git)Code Organization- Error handling: Add more robust error handling in LSP attaches and plugin loads- finish cheatsheet (DONE - improved to dynamically collect keymaps from buffer)+1 / −0 text lines
+0 / −2 text lines
+0 / −19 text lines