vscode-zig icon indicating copy to clipboard operation
vscode-zig copied to clipboard

`@cInclude` does not complete C functions when `build.zig` is in a subdirectory

Open YDKK opened this issue 1 year ago • 1 comments

When build.zig is in a subdirectory, the included C functions are not completed.

Example directory structure:

  • build
    • build.zig
  • src
    • main.zig
    • test.h

In build.zig, add

exe.addIncludePath(.{
    .path = "../src",
});

test.h is

void some_func(int foo);

In main.zig, add

const c = @cImport({
    @cInclude("test.h");
});

Then, the C function (here some_func) is not completed following c..

The following content is output to the Zig Language Server output of VS Code.

error: (translate_c): failed zig translate-c command:
C:\Users\Admin\scoop\shims\zig.EXE translate-c --zig-lib-dir C:\Users\Admin\scoop\apps\zig\0.11.0\lib --cache-dir C:\Users\Admin\AppData\Local\Temp\zls -lc --listen=- C:\Users\Admin\AppData\Local\Temp\zls\cimport.h
error:error.Timeout

error: (store ): failed to translate cimport: error.Timeout
debug: (server): Took 57ms to process request-142-textDocument/completion on Thread 20716

I tried changing the zig.buildFilePath option of the extension to ${workspaceFolder}/build/build.zig, but it had no effect.

Everything works fine when I put build.zig in the root directory of the workspace.

Version info:

OS: Windows 11 Zig: 0.11.0 Zls: 0.11.0

YDKK avatar Oct 23 '23 05:10 YDKK

What is the motivation for placing the build.zig into a separate subdirectory? ZLS searches for the build.zig by looking into the parent directories of your zig files which will not include the build folder.

Keep in mind that the zig.buildFilePath option is used to selected the build.zig for the build workspace and build on save feature of the extension. ZLS has its own mechanism for identifying the associated build.zig of source files.

Techatrix avatar Dec 01 '23 17:12 Techatrix