空格键在Nvim和Jdtls中的延迟

huangapple go评论83阅读模式
英文:

space bar lag in Nvim & Jdtls

问题

以下是代码的翻译部分:

我一直在开发一个Spring Boot项目,想要使用jdtls,但每当我按下空格键时,会出现延迟,这让我很烦恼。我尝试减少插件的数量,只保留了LSP,但仍然没有解决问题。

问题只出现在空格键上,其他操作似乎都很快。

我的LSP配置

local lsp = require('lsp-zero')

lsp.preset('recommended')

lsp.ensure_installed({
	'tsserver',
	'eslint',
    'jdtls',
})

local cmp = require('cmp')
local cmp_select = {behavior = cmp.SelectBehavior.Select}
local cmp_mappings = lsp.defaults.cmp_mappings({
	['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
	['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
	['<C-y>'] = cmp.mapping.confirm({ select = true }),
	['<C-Space>'] = cmp.mapping.complete(),
})

lsp.set_preferences({
	sign_icons = { }
})

lsp.on_attach(function(client, bufnr)
	local opts = {buffer = bufnr, remap = false}

	vim.keymap.set('n', 'gd', function() vim.lsp.buf.definition() end, opts)
    vim.keymap.set('n', '<leader>vf', function () vim.lsp.buf.implementation() end, opts)
	vim.keymap.set('n', 'K', function() vim.lsp.buf.hover() end, opts)
	vim.keymap.set('n', '<leader>vws', function() vim.lsp.buf.workspace_symbol() end, opts)
	vim.keymap.set('n', 'gz', function() vim.diagnostic.open_float() end, opts)
	vim.keymap.set('n', '<d', function() vim.diagnostic.goto_next() end, opts)
	vim.keymap.set('n', '>d', function() vim.diagnostic.goto_prev() end, opts)
	vim.keymap.set('n', '<leader>vca', function() vim.lsp.buf.code_action() end, opts)
	vim.keymap.set('n', '<leader>vrr', function() vim.lsp.buf.references() end, opts)
	vim.keymap.set('n', '<leader>vrn', function() vim.lsp.buf.rename() end, opts)
	vim.keymap.set('i', '<leader>h', function() vim.lsp.buf.signature_help() end, opts)
end)

lsp.setup()

我的Java设置:

local config = {
cmd = {
"java", -- 或绝对路径'/path/to/java11_or_newer/bin/java'
"-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",
"-Xms1g",
"--add-modules=ALL-SYSTEM",
"--add-opens",
"java.base/java.util=ALL-UNNAMED",
"--add-opens",
"java.base/java.lang=ALL-UNNAMED",
"-jar",
"/path/to/jdtls_install_location/plugins/org.eclipse.equinox.launcher_VERSION_NUMBER.jar",
"-configuration", "/path/to/jdtls_install_location/config_SYSTEM",
"-data", "/Users/YOUR_MACHINE_NAME/local/share/nvim/java"
},
settings = {
java = {
signatureHelp = {enabled = true},
import = {enabled = true},
rename = {enabled = true}
}
},
init_options = {
bundles = {}
}
}


<details>
<summary>英文:</summary>

I&#39;ve been working on a springboot project and wanted to use jdtls but I had lag whenever I hit the space bar it became annoying I tried reducing my plugins to the point where I only have my lsp installed but it didn&#39;t work.

the problem only applies to the space bar everything else seems snappy

my lsp config

local lsp = require('lsp-zero')

lsp.preset('recommended')

lsp.ensure_installed({
'tsserver',
'eslint',
'jdtls',
})

local cmp = require('cmp')
local cmp_select = {behavior = cmp.SelectBehavior.Select}
local cmp_mappings = lsp.defaults.cmp_mappings({
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
['<C-y>'] = cmp.mapping.confirm({ select = true }),
['<C-Space>'] = cmp.mapping.complete(),
})

lsp.set_preferences({
sign_icons = { }
})

lsp.on_attach(function(client, bufnr)
local opts = {buffer = bufnr, remap = false}

vim.keymap.set(&#39;n&#39;, &#39;gd&#39;, function() vim.lsp.buf.definition() end, opts)
vim.keymap.set(&#39;n&#39;, &#39;&lt;leader&gt;vf&#39;, function () vim.lsp.buf.implementation() end, opts)
vim.keymap.set(&#39;n&#39;, &#39;K&#39;, function() vim.lsp.buf.hover() end, opts)
vim.keymap.set(&#39;n&#39;, &#39;&lt;leader&gt;vws&#39;, function() vim.lsp.buf.workspace_symbol() end, opts)
vim.keymap.set(&#39;n&#39;, &#39;gz&#39;, function() vim.diagnostic.open_float() end, opts)
vim.keymap.set(&#39;n&#39;, &#39;&lt;d&#39;, function() vim.diagnostic.goto_next() end, opts)
vim.keymap.set(&#39;n&#39;, &#39;&gt;d&#39;, function() vim.diagnostic.goto_prev() end, opts)
vim.keymap.set(&#39;n&#39;, &#39;&lt;leader&gt;vca&#39;, function() vim.lsp.buf.code_action() end, opts)
vim.keymap.set(&#39;n&#39;, &#39;&lt;leader&gt;vrr&#39;, function() vim.lsp.buf.references() end, opts)
vim.keymap.set(&#39;n&#39;, &#39;&lt;leader&gt;vrn&#39;, function() vim.lsp.buf.rename() end, opts)
vim.keymap.set(&#39;i&#39;, &#39;&lt;leader&gt;h&#39;, function() vim.lsp.buf.signature_help() end, opts)

end)

lsp.setup()

my java settings

local config = {
cmd = {
--
"java", -- Or the absolute path '/path/to/java11_or_newer/bin/java'
"-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",
"-Xms1g",
"--add-modules=ALL-SYSTEM",
"--add-opens",
"java.base/java.util=ALL-UNNAMED",
"--add-opens",
"java.base/java.lang=ALL-UNNAMED",
--
"-jar",
"/path/to/jdtls_install_location/plugins/org.eclipse.equinox.launcher_VERSION_NUMBER.jar",
"-configuration", "/path/to/jdtls_install_location/config_SYSTEM",
"-data", "/Users/YOUR_MACHINE_NAME/local/share/nvim/java"
},
settings = {
java = {
signatureHelp = {enabled = true},
import = {enabled = true},
rename = {enabled = true}
}
},
init_options = {
bundles = {}
}
}


</details>


# 答案1
**得分**: 0

终于找到了解决问题的方法。

问题的罪魁祸首是我LSP配置中插入模式的键位映射。

我使用以下命令找到了它:

verbose imap<space>


移除了这个键绑定之后,问题似乎解决了。

<details>
<summary>英文:</summary>

finally found a fix to the issue

the culprit was a keymap in insert mode in my lsp config.

I found it using the command

verbose imap<space>


after removing the keybind the problem seems to go away

</details>



huangapple
  • 本文由 发表于 2023年2月14日 22:09:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75449026.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定