vim-lsp icon indicating copy to clipboard operation
vim-lsp copied to clipboard

gopls: syntax:Error:expected declaration, found 'package'

Open b97tsk opened this issue 2 years ago • 5 comments

vimrc:

set nocompatible

call plug#begin()
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
call plug#end()

let g:lsp_settings = {
  \ 'golangci-lint-langserver': {
  \   'initialization_options': {
  \     'command': [
  \       'golangci-lint', 'run', '--fast',
  \       '--max-issues-per-linter', '0',
  \       '--max-same-issues', '0',
  \       '--out-format', 'json',
  \     ],
  \   }
  \ }
\ }
let g:lsp_settings_filetype_go = ['gopls', 'golangci-lint-langserver']

Steps to reproduce:

  1. Open any Go file.
  2. :bdelete current buffer.
  3. Press CTRL+^ to reopen the file.
  4. :LspDocumentDiagnostics

This won't happen if I:

  • Remove golangci-lint-langserver from vimrc:
set nocompatible

call plug#begin()
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
call plug#end()

let g:lsp_settings_filetype_go = ['gopls']
  • Or, just checkout the commit prior to a91419e and keep vimrc unchanged.

b97tsk avatar Mar 15 '22 09:03 b97tsk

So I reverted following change introduced in a91419e, and it works:

diff --git a/autoload/lsp.vim b/autoload/lsp.vim
index 679636a..497dc8c 100644
--- a/autoload/lsp.vim
+++ b/autoload/lsp.vim
@@ -217,7 +217,7 @@ function! s:register_events() abort
             autocmd TextChangedP * call s:on_text_document_did_change()
         endif
         if g:lsp_untitled_buffer_enabled
-            autocmd FileType * call s:on_filetype_changed(bufnr(expand('<afile>')))
+            autocmd FileType * call s:on_filetype_changed(bufnr('<afile>'))
         endif
     augroup END

And then I noticed g:lsp_untitled_buffer_enabled. Setting it to 0 also works.

It seems this is still an issue, so I'm not closing it.

b97tsk avatar Mar 17 '22 03:03 b97tsk

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 11 '22 04:06 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 12 '22 06:08 stale[bot]

@b97tsk is this still an issue?

prabirshrestha avatar Aug 14 '22 05:08 prabirshrestha

@prabirshrestha Yes, but feel free to close it. I don't mind to have let g:lsp_untitled_buffer_enabled = 0 in my vimrc. 😄

b97tsk avatar Aug 15 '22 04:08 b97tsk

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 16 '22 03:10 stale[bot]