Conversation
This is a refactor of the overall extension structure. It also adjusts the commands to our internal spec. This commit does not update the unit + e2e tests yet.
| * | ||
| * COMMAND_TYPE_BUF commands are used to execute non-LSP server Buf CLI commands, e.g. `buf lint`. | ||
| */ | ||
| type CommandType = (typeof _commandType)[number]; |
There was a problem hiding this comment.
Care to explain why we're doing this typeof nonsense? I expect non-TS experts to have to look at this, so it'd be best to explain anything especially tricky looking (such as not using an enum).
There was a problem hiding this comment.
Basically to avoid enums. Enums generate some pretty horrendous javascript, and iterating over them is confusing at best (and erroneous at worst). This bypasses that by using string literals instead and let's typescript enforce validity that way. A slight sacrifice to that is this typescript logic to get the possible values of that array.
There was a problem hiding this comment.
I added a comment in status.ts and command.ts explaining basically what Paul communicated above so that we have some in-line documentation for why we do this.
If a yaml validation extension is installed, the user can use it to provide autocomplete in buf.yaml files.
This is a refactor of the LSP implementation for the extension:
BufContext -> BufState, export as a global, and centralise extension logic inBufState: rather than context, this is more of a state for the extension itself. It was previously instantiated and plumbed through all commands, but since the state is global, it made sense to change the pattern and export it was a global variable that could be imported wherever it was needed. Most of the extension state logic (e.g. managing thebufbinary and the language server) have also been centralised toBufState. Commands are now simple functions exposed to the user that call functions onBufState.BufContextsimplified theCommandstructure.find-bufandinstall-buf:find-bufandinstall-bufwere closely coupled, and we wanted to expose a clear command to our users in the form of an "install" command. Extension activation uses "install" as well.restart-bufandstop-buf, we now havestartLanguageServerandstopLanguageServer: this is a small semantic change, but it helps the commands map closer to the language server states,LANGUAGE_SERVER_STARTINGandLANGUAGE_SERVER_STOPPED. Also those commands only control LSP functionality usingbuf.string[]andas constas literal value types instead of enums: this is just a pattern that was preferred, and allows us to export/import less types.DEVELOPMENT.md. All tests are either using the VS Code testing CLI or Playwright. Also added testing for LSP functionality in Playwright..vscodeignoreto reduce the number of files we were including that were not needed at runtime.There will be a follow-up PR containing a new
CHANGELOGandREADME. We'll also be updating our lint + deps in a follow-up PR.