bufbuild / vscode-buf

Visual Studio Code integration for Buf.
Apache License 2.0
61 stars 13 forks source link

Activation rules prevent extension from loading when opening single proto file #4

Open scbizu opened 3 years ago

scbizu commented 3 years ago

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 ?

johanbrandhorst commented 3 years ago

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.

teogeos commented 3 years ago

Hello

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

buf lint works.

johanbrandhorst commented 3 years ago

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?

teogeos commented 3 years ago

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.

johanbrandhorst commented 3 years ago

Hm, it may have something to do with the activation rules: https://github.com/bufbuild/vscode-buf/blob/fa44b78bbb3322aec5f7c0bfef15e06fe573f6ae/package.json#L36-L39. It's unclear to me whether that would match a *.proto file on its own.

teogeos commented 3 years ago

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

johanbrandhorst commented 3 years ago

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.

teogeos commented 3 years ago

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

johanbrandhorst commented 3 years ago

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.

teogeos commented 3 years ago

Sorry I meant by "easy fix" that I just had to open the containing folder. I was unclear 😅.

doriable commented 3 years ago

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.