Zig support for Visual Studio Code.
- install and manage Zig version
- syntax highlighting
- basic compiler linting
- automatic formatting
- optional Zig Language Server features
- completions
- goto definition/declaration
- document symbols
- ... and many more
Zig language support for VSCode
Home Page: https://marketplace.visualstudio.com/items?itemName=ziglang.vscode-zig
License: MIT License
Zig support for Visual Studio Code.
As @leecannon said in zigtools/zls#1020 (comment), this is required for ZLS' new backwards compatibility model.
In essence, we would add a new "Install versioned release of ZLS" command which would allow someone to select a version from our releases page.
Using zig fmt
. See https://github.com/ziglang/zig.vim for an approximate example of what settings are required. Will differ as I'm not sure of the usual vscode plugin apis.
@xackus when it is convenient, could you update https://github.com/xackus/vscode-zig/tree/lsp to vscode-zig 0.2.4? I would like to test zig-lsp. Thanks, Mark.
Repro:
if (c == '\\') {
\\}
// ^ auto-inserted
I don't know if this is a bug or a VSCode's specification, but parentheses with no content cannot be collapsed.
Version: 1.77.3
Commit: 704ed70d4fd1c6bd6342c436f1ede30d1cff4710
Date: 2023-04-12T09:16:52.732Z
Electron: 19.1.11
Chromium: 102.0.5005.196
Node.js: 16.14.2
V8: 10.2.154.26-electron.0
OS: Linux x64 6.2.10-arch1-1
Sandboxed: No
// normal comment
fn foo() void {}
/// doc comment
fn foo() void {}
It helps to show that they will be parsed differently.
The grammars should line up when we're done finalizing them.
The zig build
command for the workspace should be available from the command palette.
I was implementing setTrace
in zls, and I noticed this. VSCode seems to always send "trace": "off"
regardless of the "zig.trace.server"
setting.
Is providing some default tasks something a vscode extension does?
Maybe something like
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "zig build-exe",
"type": "process",
"command": "zig",
"args": [
"build-exe",
"${file}"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "silent",
"showReuseMessage": false,
"clear": true
}
},
{
"label": "zig run",
"type": "process",
"command": "zig",
"args": [
"run",
"${file}"
],
"group": "build",
"presentation": {
"showReuseMessage": false,
"clear": true
}
},
{
"label": "zig test",
"type": "process",
"command": "zig",
"args": [
"test",
"${file}"
],
"group": {
"kind": "test",
"isDefault": true
},
"presentation":{
"showReuseMessage": false,
"clear": true
}
}
]
}
For instance, cmd+click/F12 on remove()
works if code is formatted the normal way:
builder.add().remove().process().finalize();
But not if there are lines breaks:
var x = builder.
add().
remove().
process().
finalize();
When using compiled extension on windows, Antimalware Service Executable (I think it's windows defender) uses maximum CPU resources. Insane CPU usage only appears when characters are deleted or added in VSCode.
Same happens on newest Insiders build.
All autosaving, autobuilding features are disabled.
Similar to zigtools/zls-vscode#20
This will help in using gitpod
One of the things that people have to fight with when learning zig is simply where everything is.
Having "Go to Definition" functioning would help that a lot.
Thanks.
According to marketplace last updated field, the plug-in is not being updated.
For example, the "problem matcher" feature is simply unavailable.
"zig.formattingProvider": "off"
and restarting the editor works for an indeterminate amount of time before falling back to auto-formatting on save regardless of setting.
After it starts trying to format on save again, it requires restarting or reloading the editor to prevent it again for a short time.
I suspect that whatever is powering the formatter inside the extension is crashing and then relaunches itself but ignoring any pre-existing settings once it relaunches, however this is just a theory and have no evidence for it.
I am finding the format on save functionality to be quite slow when editing 10k line files on my 2019 x86 macbook (#63) and would like to turn off auto formatting on save and go back to just having a keybinding which triggers formatting, but can't seem to figure out how to do so. My settings.json
includes "editor.formatOnSave": false
but the Zig plugin seems to disregard this.
Hello, I have files that are not even over 200 lines which format almost instantly when running zig fmt ..
but with this extension VS Code hangs for at least 3 seconds every time. I'm not sure what is causing this but it is consistently slow on my machine despite the CLI having performant results. I am on Windows
I just cloned this repository and tried to compile it. I was met with the following errors:
src/extension.ts:16:57 - error TS2345: Argument of type 'ZigCompilerProvider' is not assignable to parameter of type 'CodeActionProvider'.
Property 'provideCodeActions' is missing in type 'ZigCompilerProvider'.
16 vscode.languages.registerCodeActionsProvider('zig', compiler);
~~~~~~~~
src/zigCompilerProvider.ts:7:22 - error TS2420: Class 'ZigCompilerProvider' incorrectly implements interface 'CodeActionProvider'.
Property 'provideCodeActions' is missing in type 'ZigCompilerProvider'.
7 export default class ZigCompilerProvider implements vscode.CodeActionProvider {
It appears that commit 503243d introduced this problem to fix another issue, #29.
For it to compile, the class needs to be implement provideCodeActions
. A simple fix would be to return an empty array.
The GCC matcher (provided by the official C++ package) seems just about right, as far as I can tell. It might be nice to have a custom one for zig.
zn42 on reddit mentioned their process for getting native debugging with breakpoints and the like working in vscode.
https://www.reddit.com/r/Zig/comments/cl0x6k/debugging_zig_in_vscode/
This issue is for determining how might be best to implement this in this extension. I think it is fine for us to depend on other extensions for this, and I'd consider this debugging support to be opt-in if so. If we were even just to automate the setup that would go a long way to being more usable for the end-user.
I don't have any specific ideas in mind, and we don't necessarily need to do it the way suggested in the mentioned post, but it provides a good basis.
I see the following occurring:
zig build
command in VSCode's current directory, using all absolute names (the binary by doing its own PATH lookup presumably, the --build-file
because of the VSCode default ${workspaceDirectory}/build.zig
).zig build
outputs file names in compile errors as ./whatever/my/project/dir/somefile.zig
, so relative to my home directory. (Otherwise it outputs them as absolute file paths.) So only when zig build
is started in the home directory, the output looks like this:./projects/zig-mm/src/verify.zig:110:5: error: enum field not found: 'Constan'
Constan: void,
^
.
), thinks the problem is in the file /whatever/my/project/dir/somefile.zig
(absolute path) which does not exist of course.When I start VSCode (code
) from the command line, from my workspace directory, things work perfectly fine.
So there seem two bugs here:
zig build
to be run with the workspace directory as the current directory, so that the workspace's zig-cache/
directory is used..
should be correctly resolved.This is with version 0.2.5, which VSCode says is the latest one currently, and with Zig 0.7.0.
As it stands, the extension always builds on save. I would like to add a configuration setting so that the user can toggle the feature. However, I propose that it be off by default. This is subjective, but I feel that compiling on every save should be opt-in.
If you set buildOnSave
to true
and astCheckProvider
to zls
(default), the code that implements build on Save will not be run.
The condition on line 38 causes an early return.
vscode-zig/src/zigCompilerProvider.ts
Lines 36 to 61 in 5650df5
It seems like the problem matcher used when running the Zig: Build Workspace
command is returning incorrect paths.
The paths are incorrectly absolute paths, for example an error with the path ./src/buffer.zig
is shown in the problem tab with the path /src/buffer.zig
; then trying to click on the problem results in vscode failing to open the file /src/buffer.zig
.
Weirdly copying the problem matcher from this repository into my own task.json works perfectly, so the issue does not seem to be a bad regex pattern.
Working task.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "zig build",
"type": "process",
"command": "zig",
"args": [
"build"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "never",
"showReuseMessage": false,
"clear": true,
"revealProblems": "onProblem"
},
"problemMatcher": {
"owner": "zig",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "([^\\s]*):(\\d+):(\\d+):\\s+(?:fatal\\s+)?(error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
},
}
}
]
}
Is this the correct way to produce .vsix?
npm install
tsc src/extension.ts
npm vsce package
Because both the language client and the extension register a formatter, VSCode chooses to use... neither! The solution is probably adding an enum selector option in the config and then figuring out how to set the formatting provider we expose internally.
I cloned a git repo and it automatically converted \n to \r\n in the process since I'm on Windows.
So I used the find/replace in files functionality of vscode to replace them back and when I did it launched around 100 zig.exes and completely annihilated my CPU.
I had to kill them all with taskkill /IM "zig.exe" /F
.
This version was never published
I have an issue with vscode-zig extension. I don't want to disable zig autoformating/formatOnSave but I want it to respect my vs code settings "editor.tabSize": 2
. But it always format using 4 spaces/tab-size irrespective of my setting. And I can't seem to find an option to tell vscode-zig extension to set tab size to 2 spaces. Please help me how to change vscode-zig formatter behavior to respect my vscode tabSize setting.
When I try to save my Zig files and have code auto formatted, it fails. My workaround at the moment is to not use the 'snap' version of Zig.
Whenever I save Zig code, this error output is generated and the file is not formatted.
Error: Command failed: /snap/bin/zig fmt --stdin
My setup:
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"
$ /snap/bin/zig version
0.5.0+5aa281250
$ cat .vscode/settings.json
{
"zig.zigPath": "/snap/bin/zig"
}
If I download Zig and run it from my home directory, it works as expected (and this is my workaround):
$ ~/bin/zig version
0.5.0+5aa281250
$ cat .vscode/settings.json
{
"zig.zigPath": "/home/rippy/bin/zig"
}
Please can someone tell me if this is a setting I need to change, a bug with the plugin or a bug with VSCode?
Plugin version: v0.2.6
VSCode version info:
Commit: 6261075646f055b99068d3688932416f2346dd3b
Date: 2022-11-09T04:27:29.066Z (6 days ago)
Electron: 19.0.17
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.22621
Sandboxed: No```
Just by navigating the cursor around in a .zig
file, also on edits or saves or undos, I get such stacktraces:
[2020-01-13 19:30:39.176] [exthost] [error] [tiehuis.zig] provider FAILED
[2020-01-13 19:30:39.176] [exthost] [error] Error: Method not implemented.
at ZigCompilerProvider.provideCodeActions (/home/_/.vscode/extensions/tiehuis.zig-0.2.3/out/zigCompilerProvider.js:20:15)
at /home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:576:562
at /home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:52:287
at new Promise (<anonymous>)
at Object.t.asPromise (/home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:52:259)
at P.provideCodeActions (/home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:576:533)
at /home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:595:972
at B._withAdapter (/home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:591:697)
at B.$provideCodeActions (/home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:595:950)
at p._doInvokeHandler (/home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:663:275)
at p._invokeHandler (/home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:662:971)
at p._receiveRequest (/home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:661:588)
at p._receiveOneMessage (/home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:660:468)
at /home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:658:691
at l.fire (/home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46:893)
at _.fire (/home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:189:274)
at /home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:820:285
at l.fire (/home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46:893)
at _.fire (/home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:189:274)
at t.PersistentProtocol._receiveMessage (/home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:193:629)
at /home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:190:824
at l.fire (/home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46:893)
at p.acceptChunk (/home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:186:737)
at /home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:186:89
at Socket.t (/home/_/a/vscodium/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:195:68)
at Socket.emit (events.js:200:13)
at addChunk (_stream_readable.js:294:12)
at readableAddChunk (_stream_readable.js:275:11)
at Socket.Readable.push (_stream_readable.js:210:10)
at Pipe.onStreamRead (internal/stream_base_commons.js:166:17)
Is it because it's WIP? Too new VSCode version? OS is Linux.
It seems the plugin (with auto-build on) will complain about build_runner.zig
having build errors (despite the project building without issue) and populate the "Problems" tab with an error about it:
This is a recent development that I've only noticed happening with the latest zls
and zig-0.8-dev
branches and it seems to happen in all of my repositories. Given the low impact (builds are still checked properly for errors and zls
works) I'll be leaving this on, but it probably ought to be looked at.
Version info:
OS: Windows 10
Zig: 0.8.0-dev.878+e4b8148e9
zls
: eefee4759c9f376d33efe9e7460d25a1aeb94345
Still get this error after reinstalling the extension and all of vscode multiple times. This is on windows. I get the same error whether I'm working on a project in WSL or on native windows. Trying different versions of the zig language extension didn't work either.
I deleted the .vscode-server and .vscode folders on WSL, and the .vscode folder in my windows users directory prior to reinstalling vscode. None of that helped.
Couldn't find Zig Language Server (ZLS) executable at "/home/<user>/.vscode-server/data/User/globalStorage/ziglang.vscode-zig/zls_install/zls"
Formatting leaves error on save in for loops
Before formating:
for(a) |b, i| {
// some_code
}
After formating:
for(a, 0..) |b, i| {
// some_code
}
Hi,
In one of the previous releases of the Zig extension it was possible to navigate to the auto Zig translated C code, for example:
const v = @cImport({
@cInclude("some_header.h");
});
Let's suppose some_header.h had a public definition of foo
it was possible to navigate to v.foo
with ctrl+left mouse and see the whole generated zig file. Now it doesn't work.
Any idea what could be wrong?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.