Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode import "C" fails on modules

Please see the following screenshot:

vscode with golang import "C" error

It says:

could not import C (no package data for import path C)

I have attached an example project that reproduces the failure, here: https://github.com/microsoft/vscode/files/3783446/example-project.zip

I am using Go 1.13 with the latest versions of each extension for Go and C/C++. There is no compiler error, and this is specifically seemingly isolated as a "vscode problem".

Is there a way to fix this vscode problem?

like image 734
Ace Avatar asked Oct 22 '19 13:10

Ace


People also ask

What is the correct syntax for importing a module?

The syntax for importing a module is: import module_name Python raises a modulenotfounderror when it is unable to import a module. Python will try to find a module in either sys.modules or sys.path. When it cannot load the module, it will raise modulenotfounderror.

Is there a compiler error for this VSCode problem?

There is no compiler error, and this is specifically seemingly isolated as a "vscode problem". Is there a way to fix this vscode problem? Show activity on this post.

What is the difference between import and modulenotfounderror in Python?

ModuleNotFoundError is raised when python was not successful in importing a particular module. When an error occurs in importing a module while using: ‘import module_name,’ a ModuleNotFoundError is raised. But, when there is an error while using ‘from … import module_name’ command, python raises an ImportError.

Is VSCode now read-only?

It is now read-only. vscode is failing to import the "C" module when it is apart of a local module. all tooltips then stop working.


2 Answers

This is a bug in gopls tool distributed in the official golang packages.

Here are the issue links:

  • https://github.com/golang/go/issues/32898
  • https://go-review.googlesource.com/c/tools/+/202238/

info from issue report:

internal/lsp: use Go/cgo source files instead of generated files

Using CompiledGoFiles was causing metadata lookups to fail for cgo
packages because it includes generated files in the Go build cache
when the built-in 'go list' driver is used.  GoFiles includes both
Go and cgo original file names, allowing metadata lookups to
succeed.

like image 172
Ace Avatar answered Sep 25 '22 03:09

Ace


That's a bug with VSCode and I've written a medium article for this issue.

https://medium.com/@mourya.g9/setting-up-confluent-kafka-client-for-golang-with-vscode-7a27bb94220b. Hope this helps.

like image 28
mourya venkat Avatar answered Sep 25 '22 03:09

mourya venkat