bufbuild/vscode-buf

Importing highlighting doesn't find correct import path

MrEyratnz opened this issue · 6 comments

Example project structure:

.
└── proto/
    └── foo/
        └── bar/
            └── v1beta1/
                ├── baz.proto
                └── bat.proto

My buf.yaml has:

version: v1beta1
build:
  roots:
    - proto

In baz.proto, I'm trying to import bat.proto as import foo/bar/v1beta1/bat.proto;. The VS-Code extension is highlighting this as an error with message:

Import "foo/bar/v1beta1/bat.proto" was not found or had errors."

There are no individual errors in bat.proto and when using the buf cli, this passes both buf lint and buf build.

I tried changing the import to import proto/foo/bar/v1beta1/bat.proto; which resulted in:

Import "proto/proto/foo/bar/v1beta1/bat.proto" was not found or had errors."

It would appear that the root defined in the buf.yaml is only being pre-pended to the import path when it already starts with it.

Hi Ryan,

That's a curious error. All the extension is doing is running buf lint in the root of the repository. If your buf.yaml is in the root of your repository and manually running buf lint works, the extension really should work too. Could you tell me if there's any debug output from the extension?

@johanbrandhorst I'm not seeing anything in the extension output. I threw together an example here if its easier for you to play with. To reproduce, just trigger a save action on proto/foo/bar/baz.proto

Here's my buf version

$ buf --version
❯ 0.41.0

https://github.com/rmertzpfpt/buf-vscode-import-issue

I looked into this a bit more - the Import <$file> was not found or had errors. actually originates from the vscode-proto3 plugin (relevant issue here).

That plugin only supports protoc, so you would need to adjust your extension settings to account for the correct proto-path (proto in this case).

We eventually plan to support a more fully-featured IDE integration story, but that's outside the scope of vscode-buf for now (which is primarily concerned with linting behavior).

Given that this won't be fixed in the current iteration of vscode-buf, I'll close this as-is.

@amckinney Thanks so much for looking into this. I totally understand closing this issue - I appreciate the response and love what you all are doing at buf!

jogly commented

I know this issue isn't related to vscode-buf, but since I landed here for the same question, I'm just leaving this because it helped me:

Adding this to my settings.json:

  "protoc": {
    "options": ["-I=~/.cache/buf/v1/module/data/buf.build"]
  }

let me use vscode-proto3 with buf's module cache.

To add some more details; the caching of modules can be configured with the $BUF_CACHE_DIR or $XDG_CACHE_HOME environment variables and will default to $HOME/.cache on Linux and Mac and %LocalAppData% on Windows. See https://docs.buf.build/bsr/overview/#module-cache for the complete documentation.