Giter Site home page Giter Site logo

ziglang / vscode-zig Goto Github PK

View Code? Open in Web Editor NEW
476.0 8.0 55.0 676 KB

Zig language support for VSCode

Home Page: https://marketplace.visualstudio.com/items?itemName=ziglang.vscode-zig

License: MIT License

TypeScript 98.05% JavaScript 1.95%
zig visual-studio-code

vscode-zig's Introduction

vscode-zig

VSCode Extension CI

Zig support for Visual Studio Code.

Syntax Highlighting, Code Completion

Features

  • 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

vscode-zig's People

Contributors

alexrp avatar aspizu avatar dependabot[bot] avatar emekoi avatar gernest avatar hejsil avatar hryx avatar jarred-sumner avatar jrmlhermitte avatar leecannon avatar leighmcculloch avatar litomore avatar markfirmware avatar mnxn avatar ngrilly avatar not-fl3 avatar papidb avatar rhagenson avatar scurest avatar sebastianhoffmann avatar superauguste avatar swoogan avatar techatrix avatar tiehuis avatar tokyo4j avatar unlsycn avatar vexu avatar wackbyte avatar xackus avatar yzrmn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-zig's Issues

Folding does not work

I don't know if this is a bug or a VSCode's specification, but parentheses with no content cannot be collapsed.

範囲を選択_005

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

Default tasks?

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
            }
        }
    ]
}

Navigation stops working on builder-style expressions

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();

Conflicts with Windows Defender

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.

Prioritize implementing "Go to Definition"

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.

syntax highlighting only highlights `()` and `{}`

Vscode version:

1.70.2
e4503b30fc78200f846c62cf8091b76ff5547662
x64

vscode-zig version: latest (0.2.5)
screenshot of the issue:
image
(this is for the whole file and every file, i just screenshot a small portion of it)

Formatting provider re-enables itself

"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.

does not respect `"editor.formatOnSave": false`

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.

Collapsible doc comments

Doc comments are not currently marked as collapsible.

Doc comments can get fairly long, in these instances it would be useful for them to collapsible.

image

Extremely Slow Formatting

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

master does not compile

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.

Support Native Debugging out of the box

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.

Problem has incorrect path if zig build outputs ./a/relative/path

I see the following occurring:

  • This extension runs the 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).
  • That directory is my home directory normally, when I start VSCode from Ubuntu's starter.
  • In that case only, for a reason I don't know, 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,
    ^
  • This extension gets confused by those relative file names: it seems to ignore the leading dot (.), thinks the problem is in the file /whatever/my/project/dir/somefile.zig (absolute path) which does not exist of course.
  • Therefore the problems are not shown in the editors, and clicking on them does not work (and gives me a confusion 'Create FIle' option).

When I start VSCode (code) from the command line, from my workspace directory, things work perfectly fine.

So there seem two bugs here:

  • The lesser one is that I would prefer zig build to be run with the workspace directory as the current directory, so that the workspace's zig-cache/ directory is used.
  • The larger one is that relative paths starting with . 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.

Proposal: Add setting for "build on save" and default to off

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.

Build On Save doesn't work if Ast Check Provider is ZLS

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.

maybeDoASTGenErrorCheck(change: vscode.TextDocumentChangeEvent) {
if (change.document.languageId !== "zig") return;
if (vscode.workspace.getConfiguration("zig").get<string>("astCheckProvider", "zls") !== "extension") {
this.astDiagnostics.clear();
return;
}
if (change.document.isClosed) {
this.astDiagnostics.delete(change.document.uri);
}
this.doASTGenErrorCheck(change);
if (!change.document.isUntitled) {
let config = vscode.workspace.getConfiguration("zig");
if (
config.get<boolean>("buildOnSave") &&
this.dirtyChange.has(change.document.uri) &&
this.dirtyChange.get(change.document.uri) !== change.document.isDirty &&
!change.document.isDirty
) {
this.doCompile(change.document);
}
this.dirtyChange.set(change.document.uri, change.document.isDirty);
}
}

Problem matcher gets incorrect paths

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
                },
            }
        }
    ]
}

Produce .vsix

Is this the correct way to produce .vsix?

npm install
tsc src/extension.ts
npm vsce package

Existence of two formatters causing formatting to not work

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.

Extreme CPU usage on find/replace in multiple files

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.

does not respect "editor.tabSize": 2

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.

Ubuntu snap install of zig fails to format

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"
}

Full stops at the end of comments invoke auto-complete.

image

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```

VSCodium 1.41.1: "Error: Method not implemented. at ZigCompilerProvider.provideCodeActions"

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.

Build error for automatically created `build_runner.zig` file from `zls`

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:

image

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

Couldn't find Zig Language Server

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"

Error on format

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
}

@cImport's auto translated navigation doesn't work anymore

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.