Custom server endpoint that returns the list of top-level steps#3219
Open
FrancoisAucoin wants to merge 1 commit into
Open
Custom server endpoint that returns the list of top-level steps#3219FrancoisAucoin wants to merge 1 commit into
FrancoisAucoin wants to merge 1 commit into
Conversation
…el steps defined in the specified workspace's root `build.zig` file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Quick summary
Commit message: Implemented a custom server endpoint that returns the list of top-level steps defined in the specified workspace's root
build.zigfile.Note: I made my changes relative to the 0.16.0 release tag, so I will need to rebase against the latest branch and fix the conflicts. But I still wanted to get some feedback to see whether the maintainers would consider this feature a contribution.
Detailed summary
Let me start by being transparent about why I worked on this feature: I thought that it would be cool to implement a task provider in the vscode-zig extension (here's my fork).
That being said, I browsed the ZLS codebase and realized that pretty much everything was already in place for this to work, as this project's custom build runner is doing the heavy lifting and storing the required information inside a structure called BuildConfig.
So here is how the feature works at a high level:
customZig/listBuildStepswith the followingparamsobject:{ workspaceUri: string };processMessagemethod's.otherprong, handles the new method;DocumentStore.BuildFileinstance from the server'sdocument_storeproperty; andBuildFileinstance'stryLockConfigmethod gets called and, upon success, returns a reference to aBuildConfigobject, from which the top-level steps (names and descriptions) are extracted and returned from the handler, which the server then sends as a response to the client.But to make this work decently, I had to make a few extra modifications:
DocumentStorenamed primeBuildFile, which internally calls the private getOrLoadBuildFile method for its side effects, because my understanding is that thebuild.zigfiles are analyzed lazily. Without this, no information would become available to the client until either the rootbuild.zigfile was opened in the editor, or a user action like code navigation was attempted. While the first call to the endpoint will likely return nothing, the client implementation would still, in theory, be able to prime the server with a dummy request upon connection. I know this isn't ideal, but that's how I solved the problem for now (but I am obviously open to suggestions).[]const []const u8type to a[]const BuildConfig.TopLevelStepInfotype, whereTopLevelStepInfois a simple structure with two fields:nameanddescription(the goal was to hold the step's description in addition to its name). This schema modification meant that a bunch of.jsonfiles used for the build runner's test cases also needed to be modified.How to test the feature (in VS Code)
As mentioned above, I have forked the official vscode-zig repository and implemented a task provider that directly uses this new ZLS endpoint.
To test out the feature:
npm installinside the project root.IMPORTANT: The new feature in my fork of the
vscode-zigextension is gated behind enablement flags that intentionally default tofalse. I chose this default because I didn't want the server's build runner to automatically spin up in the background without user consent. A user who wants this feature can easily enable it, but that should be their explicit choice.Additionally, you must configure the extension to point directly to the ZLS binary built from this branch. Your VS Code
settings.jsonshould look like this:{ "zig.zls.path": "/Users/your-username/path/to/your/zls-clone-at-the-pr-branch/zig-out/bin/zls", "zig.zls.enableBuildStepTaskProvider": true, "zig.zls.enableEagerAnalysis": true }Here is what the task picker looks like for a basic Zig project in VS Code:
If the current PR eventually ends up being approved, I will also submit a PR for my vscode-zig fork.
Thank you for your time!
Thank you for taking some of your precious time to look at this PR. I very much appreciate it! :)