Skip to content
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

gopls removes all comments if 'C' package is imported #3518

Closed
roskee opened this issue Dec 19, 2024 · 1 comment
Closed

gopls removes all comments if 'C' package is imported #3518

roskee opened this issue Dec 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@roskee
Copy link

roskee commented Dec 19, 2024

Description

I have the following lspconfig in neovim

lspconfig.gopls.setup({
  on_attach = on_attach,
  capabilities = capabilities,
  cmd = { "gopls"},
  filetypes = {"go", "gomod", "gowork", "gotmpl"},
  root_dir = util.root_pattern("go.mod"),
  settings = {
    gopls = {
      completeUnimported = true,
      analyses = {
        unusedparams = true,
        unreachable = true,
      },
      hints = {
        parameterNames = true,
        assignVariableTypes = true,
        compositeLiteralFields = true,
        constantValues = true,
        functionTypeParameters = true,
      }
    }
  }
})

I created a main.go file with the following content

package main

// #include <stdio.h>
// void hello() {
//    printf("Hello from C\n");
//    fflush(stdout);
// }
import "C"
func main() {
	C.hello()
	C.hello()
}

The lsp shows an error saying 'regenerate cgo definitions'. I didn't mind the error but when I tried to save the file with :w the lsp removes all comments in the code including the c function before the import and even any other comments in the file. Am I missing something? I have saved the file with the old school vi and it compiles and executes fine.

@roskee roskee added the bug Something isn't working label Dec 19, 2024
@glepnir
Copy link
Member

glepnir commented Dec 19, 2024

upstream golang/go#35721

@glepnir glepnir closed this as completed Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants