bufbuild/vscode-buf

Activation rules prevent extension from loading when opening single proto file

scbizu opened this issue ยท 11 comments

I already installed buf but when I lints my proto file It says

Command 'Linters: Lint protobuf files using Buf' resulted in an error (command 'vscode-buf.lint' not found)

Anything I miss ?

Hi @scbizu, this is indeed a bug, I've reproduced it and I have a fix ready, it'll be available with v0.0.3.

Hello

The issue seems to have reappeared, I have it too:

  • VSCode v1.56.2
  • Buf v0.42.1
  • Buf VSCode extension v0.1.1

buf lint works.

Strange, I can see the command in my editor, and the "Feature Contributions" page lists the command too:
image

Do you see the same thing in your editor?

Ok, got it to work.

For some reason if I just open the proto file from VSCode and lint it doesn't work. I have to open the containing folder to get linting.

Hm, it may have something to do with the activation rules:

vscode-buf/package.json

Lines 36 to 39 in fa44b78

"activationEvents": [
"workspaceContains:**/*.proto",
"workspaceContains:**/buf.yaml"
],
. It's unclear to me whether that would match a *.proto file on its own.

It's the activation rules that gave me the hint indeed, but it was a guess, no idea if it's really the cause.

Thanks for the update, I've reopened and renamed the issue. I don't have time to fix this anytime soon but I'd be happy to review a fix.

Ok, thanks, at least there is an easy fix.

I had a quick look at the available events and I'm not convinced it's so easy: https://code.visualstudio.com/api/references/activation-events. I can't see an event for "file name" or similar, it looks to me like we'd have to use * which is a bit frowned upon.

Sorry I meant by "easy fix" that I just had to open the containing folder. I was unclear ๐Ÿ˜….

We have a couple of options on how we can handle this:

  1. We can use onStartupFinished flag under activation events (which is recommended over *). This will give the user of the extension access to the buf.lint command regardless of the contents of the vscode workspace, and will load after start-up (as opposed to during start-up, such as *). The benefits of having buf.lint command available and the extension loaded in any workspace is that users can also define custom tasks, etc. using the command. The downside, is of course, that the extension will be loaded even when it may not be strictly necessary. That being said, this is a pretty common pattern and is used in vscode-eslint, for example: https://github.com/microsoft/vscode-eslint/blob/55871979d7af184bf09af491b6ea35ebd56822cf/package.json#L27-L29
  2. We can just enforce that users must open a directory as a workspace. This is not the best user experience, however it will save on the overhead of the extension starting up unnecessarily.