-
-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lsp format volar delete my code #4066
Comments
#3925 (comment) (and #3925 (comment)). |
It's formatted by To resolve I think you can,
|
if I use :LspStop tsserver then all my Lsp are inactive, so it won't work, lsp on the .ts and .js formatting extension still works but if on vue then volar will be active so that's an error, I've tried it. |
my config lsp local lspconfig = require 'lspconfig'
local util = require 'lspconfig.util'
local bind = vim.keymap.set
local borderLsp = "rounded"
-- local borderLsp = { "╔", "═", "╗", "║", "╝", "═", "╚", "║" }
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(
vim.lsp.handlers.hover, {
border = borderLsp
}
)
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
vim.lsp.handlers.signature_help, {
border = borderLsp
}
)
require('lspconfig.ui.windows').default_options.border = borderLsp
-- create underline
-- local hl_groups = { 'DiagnosticUnderlineError','DiagnosticUnderlineWarn','DiagnosticUnderlineInfo','DiagnosticUnderlineHint' }
-- for _, hl in ipairs(hl_groups) do
-- vim.cmd.highlight(hl .. ' gui=undercurl')
-- end
vim.cmd([[highlight ErrorMsg guibg=#3d0000 ]])
vim.cmd([[highlight WarningMsg guibg=#513A1A ]])
vim.cmd([[highlight DiagnosticHintLn guibg=#024649 ]])
vim.cmd([[highlight DiagnosticInfoLn guibg=#024649 ]])
local signsIcon = { ERROR = " ", WARN = " ", HINT = " ", INFO = " " }
vim.diagnostic.config({
float = { border = borderLsp },
-- virtual_text = true, --default true
-- underline = true,
-- severity_sort = true,
signs = {
text = {
[vim.diagnostic.severity.ERROR] = signsIcon.ERROR,
[vim.diagnostic.severity.WARN] = signsIcon.WARN,
[vim.diagnostic.severity.INFO] = signsIcon.INFO,
[vim.diagnostic.severity.HINT] = signsIcon.HINT,
},
-- linehl = {
-- [vim.diagnostic.severity.ERROR] = 'ErrorMsg',
-- [vim.diagnostic.severity.WARN] = 'WarningMsg',
-- [vim.diagnostic.severity.INFO] = 'DiagnosticInfoLn',
-- [vim.diagnostic.severity.HINT] = 'DiagnosticHintLn',
-- },
numhl = {
[vim.diagnostic.severity.ERROR] = 'ErrorMsg',
[vim.diagnostic.severity.WARN] = 'WarningMsg',
[vim.diagnostic.severity.INFO] = 'DiagnosticInfo',
[vim.diagnostic.severity.HINT] = 'DiagnosticHint',
},
}
})
-- deprecated
-- local on_attach = function(_, bufnr)
-- local opts = { buffer = bufnr, noremap = true, silent = true }
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
bind('n', 'gdc', vim.lsp.buf.declaration, opts)
bind('n', 'gdf', vim.lsp.buf.definition, opts)
bind('n', 'K', vim.lsp.buf.hover, opts)
bind('n', '<leader>vd', vim.diagnostic.open_float, opts)
bind('n', '[d', vim.diagnostic.goto_next, opts)
bind('n', ']d', vim.diagnostic.goto_prev, opts)
bind('n', '<leader>vca', vim.lsp.buf.code_action, opts)
bind('n', '<leader>vrr', vim.lsp.buf.references, opts)
-- bind('n', '<leader>vrr', "<cmd>Telescope lsp_references<CR>", opts)
bind('n', '<leader>vrn', vim.lsp.buf.rename, opts)
bind('i', '<C-h>', vim.lsp.buf.signature_help, opts)
bind('n', '<leader>hf', function()
vim.lsp.buf.format({ async = true})
end, opts)
end,
})
-- cmp
-- used to enable autocompletion
local capabilities = require("cmp_nvim_lsp").default_capabilities()
-- Enable the following language servers
local servers = {"tsserver","volar"}
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
-- on_attach = on_attach,
capabilities = capabilities,
}
end
lspconfig["tsserver"].setup({
-- on_attach = on_attach,
capabilities = capabilities,
root_dir = vim.loop.cwd,
init_options = {
hostInfo = "neovim",
plugins = {
{
name = "@vue/typescript-plugin",
location = "/home/rahman/.local/share/pnpm/global/5/node_modules/@vue/typescript-plugin",
languages = {"vue"}
},
},
},
filetypes = {
"javascript",
"typescript",
"vue"
},
})
-- local volar_path=''
local tslib_path='/home/rahman/.local/share/pnpm/global/5/node_modules/typescript/lib/'
lspconfig["volar"].setup({
-- on_attach = on_attach,
capabilities = capabilities,
filetypes = {'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue', 'json'},
root_dir = util.root_pattern 'package.json',
init_options = {
typescript = {
tsdk = tslib_path
-- Alternative location if installed as root:
-- tsdk = '/usr/local/lib/node_modules/typescript/lib'
},
}
})
-- luasnip setup
local luasnip = require 'luasnip'
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4), -- Up
['<C-f>'] = cmp.mapping.scroll_docs(4), -- Down
-- C-b (back) C-f (forward) for snippet placeholder navigation.
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }),
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}),
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
window = {
completion = cmp.config.window.bordered({
border = borderLsp
}),
documentation = cmp.config.window.bordered({
border = borderLsp
}),
},
} |
You are not showing crucial part of your configuration: what and how triggers formatting, which does not happen automatically so you must have configured it somehow. You can find how to filter out (also, what is it with people pasting screenshots here rather than code itself?) |
Not sure what do you mean but you should pass correct param into And this should not be the solution to your problem, it's just demonstrate where's the issue. |
Can it be made so that both work because we also need .ts/.js to make composable, because before there was no problem |
@bobbyrahmanda13 You are ignoring everything that is said in this issue while people are genuinely trying to help you. |
You have to config yourself to what you want. e.g. Use volar in |
Did anyone fix this? |
If you go through the threat, you will find the solution. ( maybe just a work around but works ). Btw it's tsserver not volar. |
Hey @johnsoncodehk, I see this is marked as completed, but I am still experiencing this on v2.0.13. Is this intended to be closed because it was fixed in volarjs/volar.js@d4fbbd7 or closed due to being an upstream issue? Thanks for all your hard work on this project! |
@codymikol Since you mentioned v2.0.13, this did not release the VSCode extension. Are you using another IDE? If so, please make sure to update |
Currently using neovim with mason, not sure how that manages the @vue/typescript plugin, I'll dig into that a little tonight. |
@johnsoncodehk I should have known how that in particular was set up since I made a little shim package to do that and completely forgot about it. 😅 But essentially, that is just takes the installed version of this language-tools repository and uses the @vue/typescript-plugin package for that version. So in my case I'm using the latest version of @vue/typescript-plugin, but I'm still experiencing this bug unfortunately :/ |
I'll do a little digging and see if I can find where exactly its happening. |
@johnsoncodehk Apologies, after digging into this, I was all of a sudden unable to replicate my issues. I think I must have blown the cobwebs out of something cached. You can close this again, sorry for the confusion. |
before:

after: :lua vim.lsp.buf.format()

The text was updated successfully, but these errors were encountered: