on_attach
louis2610 opened this issue · comments
How to override lsp on_attach()
just wrap it in a function and then add your stuff?
just wrap it in a function and then add your stuff?
local on_attach = require("plugins.configs.lspconfig").on_attach
local capabilities = require("plugins.configs.lspconfig").capabilities
local lspconfig = require "lspconfig"
-- if you just want default config for the servers then put them in a table
local servers = { "html", "cssls", "tsserver", "clangd" }
local my_on_attach = function(client, bufnr)
on_attach(client, bufnr)
end
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
on_attach = my_on_attach,
capabilities = capabilities,
}
end
is it ok?
what are u trying to do tho, u dont seem to add new stuff to on_attach, then can just use default on_attach
what are u trying to do tho, u dont seem to add new stuff to on_attach, then can just use default on_attach
my_on_attach() not work
what are u trying to do tho, u dont seem to add new stuff to on_attach, then can just use default on_attach
my_on_attach() not work
no idea, your on_attach had nothing besides default on_attach,what do u expect
what are u trying to do tho, u dont seem to add new stuff to on_attach, then can just use default on_attach
my_on_attach() not work
no idea, your on_attach had nothing besides default on_attach,what do u expect
Below is my code:
local on_attach = require("plugins.configs.lspconfig").on_attach
local capabilities = require("plugins.configs.lspconfig").capabilities
local lspconfig = require "lspconfig"
-- if you just want default config for the servers then put them in a table
local servers = { "html", "cssls", "tsserver", "clangd" }
local my_on_attach = function(client, bufnr)
if client.supports_method "textDocument/documentHighlight" then
vim.cmd [[
hi! LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow
hi! LspReferenceText cterm=bold ctermbg=red guibg=LightYellow
hi! LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow
]]
vim.api.nvim_create_augroup("lsp_document_highlight", {
clear = false,
})
vim.api.nvim_clear_autocmds {
buffer = bufnr,
group = "lsp_document_highlight",
}
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
group = "lsp_document_highlight",
buffer = bufnr,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
group = "lsp_document_highlight",
buffer = bufnr,
callback = vim.lsp.buf.clear_references,
})
end
on_attach(client, bufnr)
end
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
on_attach = on_attach,
capabilities = capabilities,
}
end
please wrap it in ```lua, its unreadable
please wrap it in ```lua, its unreadable
local on_attach = require("plugins.configs.lspconfig").on_attach
local capabilities = require("plugins.configs.lspconfig").capabilities
local lspconfig = require "lspconfig"
-- if you just want default config for the servers then put them in a table
local servers = { "html", "cssls", "tsserver", "clangd" }
local my_on_attach = function(client, bufnr)
if client.supports_method "textDocument/documentHighlight" then
vim.cmd [[
hi! LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow
hi! LspReferenceText cterm=bold ctermbg=red guibg=LightYellow
hi! LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow
]]
vim.api.nvim_create_augroup("lsp_document_highlight", {
clear = false,
})
vim.api.nvim_clear_autocmds {
buffer = bufnr,
group = "lsp_document_highlight",
}
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
group = "lsp_document_highlight",
buffer = bufnr,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
group = "lsp_document_highlight",
buffer = bufnr,
callback = vim.lsp.buf.clear_references,
})
end
on_attach(client, bufnr)
end
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
on_attach = my_on_attach,
capabilities = capabilities,
}
end
not work too
seek help in our discord server