-
Notifications
You must be signed in to change notification settings - Fork 65
Protols Tips
This wiki contains general tips and opni-specific guides for using protols in vscode, as well as the standalone CLI.
You can find references to any message, enum, enum value, extension, or field. Simply right-click on the symbol you want to search for and select "Find References".
Examples (click to expand):
Finding references to an extension

Finding references to a field literal

Finding references to a message type

Some imports do not have associated source files on disk that can be opened normally in the editor. These include the "well-known" google/protobuf/* imports, as well as imports from Go modules that do not have sources available. In these cases, protols will generate a "synthetic" source file based on the available descriptor information.
When navigating to one of these imports, for example by ctrl-clicking on the import path:

or a symbol that is defined in the file:

the synthetic source file will be seamlessly generated and opened in a read-only editor. Synthetic sources are fully interactive, just like regular source files.
Some quick-fixes are available and can be interacted with to fix or generate code. Available quick-fixes include:
-
Remove unused imports

-
Add message definitions

A few helpful editor commands are available from the command palette:

- Restart Language Server: Restarts the language server subprocess
- Stop Language Server: Stops - and does not restart - the language server
- Reindex Workspaces: Clears all cached data and re-scans the workspace, without restarting the actual subprocess. Useful for debugging.
- Show Document AST: Opens a window next to the current document containing a textual representation of that document's protobuf AST. Auto-updates on save. Useful for debugging.
Protols will auto-format your code on save using a consistent style, similar to gofmt. In addition, the language server allows for a slightly more relaxed grammar than is defined by the protobuf spec (e.g. trailing commas, mismatched commas/semicolons, and certain empty declarations are allowed), which it will fix up during formatting. This provides a better experience while editing code, and makes common mistakes less frustrating to diagnose, like using a comma where a semicolon is expected (or vice versa), or leaving a trailing comma on the final entry of a list.
There are a handful of useful CLI commands built into the protols binary.
Similar to go vet, will perform validation and basic linting. Must be run from the workspace root.

Similar to go fmt, will auto-format any existing source files.

Decodes wire-format messages using type information from the workspace. Must be run from the workspace root.

Useful for inspecting binary encoded web requests - see below for an example demo:
Screencast.from.2023-10-21.17-25-11.mp4
Architecture
- Backends
- Core Components