Zig Language ExtrasThis extension adds few commands for Zig development:
It also displays code lenses above tests to run or debug single test, and code lens at the first line of the file to run all tests. It depends on several extensions:
The main reason I decided to make this is to create fine vscode problems description from zig command output. When running tests there can be few different versions of the output. Build can fail, test can fail, assert can be risen while running the test. All of those have different output and it is hard to make single regexp which will work for all. So I make it more procedural way by analyzing zig command output line by line. Most of the commands are expecting folder structure built with 'zig init-exe' or 'zig init-lib'. With build.zig in the root and files under src. Folder with the build.zig is expected to be root of the vscode workspace. Testing'Test workspace' runs 'Run file tests' runs all tests in the current file 'Run single tests' tries to find test name from the current position. It first searches up from the current position to find name of the test. If not found then it searches down. If you are positioned in the test, that will run that test. If you are in the code and the tests are below you code this will find first test. If you need to use additional test command arguments set
Building'Build workspace' command runs DebuggingThere are two debugging commands. 'Debug test' builds binary for the test (binary location: zig-out/debug/test) and starts debugger on that binary. Put a breakpoint in you test before running command. 'Debug binary' first builds workspace and then starts binary zig-out/bin/{name}. If current file is in src folder name is set to the folder name above src folder which is expected to be root of your workspace. If the current file is in some other folder then the name of the current file is used as name of the binary except if that file is named main.zig then folder name of that file is used as expected binary name. You can modify debugger via settings: The default debugger types for each platform are as follows:
Keybinding tipWhen adding keybinding you can restrict usage on Zig language files:
Extension developmentZig command output parser is in src/parser.ts and the corresponding tests in the src/test/suite/parser.test.ts. Parser test cases are in files located in src/test/suite/testdata. Each case in .txt file has corresponding expected parser output in _expected.json file. Parser test loads all txt files and expects to get parsing result as in expected file. Parser has no dependency on vscode so it is possible to test without running vscode:
CreditsCode lenses implementation is taken from Jarred-Sumner's pull request to original vscode-zig extension. |