Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
YDKK opened this issue Oct 23, 2023 · 1 comment
Open
Assignees
Labels
lsp Issue with language server integration

Comments

@YDKK
Copy link

YDKK commented Oct 23, 2023

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

@Vexu Vexu added the lsp Issue with language server integration label Oct 23, 2023
@Techatrix
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lsp Issue with language server integration
Projects
None yet
Development

No branches or pull requests

4 participants