prabirshrestha / vim-lsp

async language server protocol plugin for vim and neovim
MIT License
3.07k stars 303 forks source link

Issue with Typescript language server and ESLint #1521

Closed raiansantos closed 6 months ago

raiansantos commented 7 months ago

Hey, I have the following configuration in my .vimrc, which sets up typescript and eslint language servers.

When I open a JS or TS file, on the first load I don't get any errors about the code, however after change to another buffer and come back to the previous one, TS returns a lot of errors saying that imports/exports are duplicated. Commenting out eslint stop the issue (what get me to believe that the project setup is OK. Also im not getting errors with VSCode or Vim-CoC).

Keeping ESLint and disabling all capabilities did not work (tried this to understand what capability was giving the issue). It seems that having multiple LSPs registered to the same filetype is giving me the issue.

Also tried to disable other plugins, no success. Commenting out all LSP related configurations (g:lsp_*) did not work as well.

let g:lsp_diagnostics_float_cursor = 1
let g:lsp_diagnostics_signs_error = {'text': '✗'}
let g:lsp_diagnostics_signs_warning = {'text': '‼'}
let g:lsp_diagnostics_signs_hint = {'text': '→'}
let g:lsp_document_code_action_signs_hint = {'text': '>'}
let g:lsp_document_code_action_signs_delay = 50
let g:lsp_use_native_client = 1
let g:lsp_use_event_queue = 1
let g:lsp_semantic_enabled = 1
let g:lsp_diagnostics_virtual_text_align = "right"
let g:lsp_inlay_hints_enabled = 0
let g:lsp_format_sync_timeout = 500
let g:lsp_log_verbose = 1
let g:lsp_log_file = expand('~/vim-lsp.log')

if executable('typescript-language-server')
  au User lsp_setup call lsp#register_server({
        \ 'name': 'typescript',
        \ 'cmd': {server_info->[&shell, &shellcmdflag, 'typescript-language-server --stdio']},
        \ 'root_uri':{server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'tsconfig.json'))},
        \ 'whitelist': ['javascript', 'javascriptreact', 'typescript', 'typescript.tsx', 'typescriptreact'],
        \ 'initialization_options': {
        \ },
        \ })
endif

if executable('vscode-eslint-language-server')
  au User lsp_setup call lsp#register_server({
        \ 'name': 'eslint',
        \ 'cmd': {server_info->[&shell, &shellcmdflag, 'vscode-eslint-language-server --stdio']},
        \ 'root_uri':{server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'package.json'))},
        \ 'allowlist': ['javascript', 'javascriptreact', 'typescript', 'typescript.tsx', 'typescriptreact'],
        \ 'workspace_config': {
        \   'validate': 'on',
        \   'packageManager': 'npm',
        \   'useESLintClass': v:false,
        \   'experimental': {
        \     'useFlatConfig': v:false,
        \   },
        \   'codeActionOnSave': {'enable': v:false, 'mode': 'all' },
        \   'format': v:false,
        \   'quiet': v:false,
        \   'onIgnoredFiles': 'off',
        \   'options': {},
        \   'rulesCustomizations': [],
        \   'run': 'onType',
        \   'problems': { 'shortenToSingleLine': v:false },
        \   'nodePath': v:null,
        \   'workingDirectories': [{'mode': 'auto'}],
        \   'workspaceFolder': {
        \     'uri': lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'package.json')),
        \   },
        \   'codeAction': {
        \     'disableRuleComment': {
        \       'enable': v:true,
        \       'location': 'separateLine',
        \     },
        \     'showDocumentation': {
        \       'enable': v:true,
        \     },
        \   },
        \ },
        \ })
endif
raiansantos commented 7 months ago

I was able to duplicate the issue with a simple create-react-app.

image

Some tech stuff:

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Dec 20 2023 11:27:57) Included patches: 1-2181

vim-lsp-ts.log .vimrc

raiansantos commented 6 months ago

It seems that keeping buffer opened with set hidden avoid the issue.