#Can we get autocomplete working with cimport?

1 messages · Page 1 of 1 (latest)

brisk thorn
#

Im not sure if this is a me problem or a normal thing.

I don't know if there is a good/normal/best way to get going with sdl3? When I fetch this repo, which seems to have the most stars for sdl3, I dont get autocomplete with neovim/homebrew zig 0.14. (Autocomplete normally works, but here in this example when I then type c. I don't get the autocomplete popup.)

// zig fetch --save git+https://github.com/castholm/SDL.git
const c = @cImport({
    @cDefine("SDL_DISABLE_OLD_NAMES", {});
    @cInclude("SDL3/SDL.h");
    @cInclude("SDL3/SDL_revision.h");
    // For programs that provide their own entry points instead of relying on SDL's main function
    // macro magic, 'SDL_MAIN_HANDLED' should be defined before including 'SDL_main.h'.
    @cDefine("SDL_MAIN_HANDLED", {});
    @cInclude("SDL3/SDL_main.h");
});

Is there someting I need to do? Put something extra in the build.zig?

I just added this to the default zig init build file:

    const sdl_dep = b.dependency("sdl", .{
        .target = target,
        .optimize = optimize,
    });
    const sdl_lib = sdl_dep.artifact("SDL3");
    ...
    ...
    exe_mod.linkLibrary(sdl_lib);

#

I wonder if I need to do something like this, but I dont have the import folder in my project folder, its in a package I think:

exe.addIncludePath(b.path("include/"));
exe.addLibraryPath(b.path("lib/"));

I feel like I am slowly starting to understand the build.zig file, but I still dont quite understand how it all ties together with multiple packages.

Am I supposed to do someting like (just guessing):

exe.addIncludePath(sdl_dep.addthestuff??);
brisk thorn
#

Can we get autocomplete working with cimport?

brisk thorn
still inlet
#

usually, i have to build at least once using imports to get autocompletion working

brisk thorn
#

Hmmm, thanks. I've built quite a few times now.

#

Do you use sdl via a package, or inside a lib/vendor folder?

iron abyss
#

Copy/pasting my response from the issue you opened in the SDL repo:

If your program compiles when you run zig build you should get completions in your editor, if it doesn't it's a problem with ZLS, Neovim or your system setup. I use ZLS with Visual Studio Code and I get completions and type hints when I open the SDL examples in zig-examples. Make sure that your ZLS version matches your Zig version and check the ZLS logs for errors or anything that may hint at something being incorrectly configured.

#

exe_mod.linkLibrary(sdl_lib) should be enough, you shouldn't need to add any additional include paths, so the problem almost definitely is with zls/neovim and not the SDL package or your zig code

brisk thorn
#

Interesting, I just checked the zig-examples/breakout on my computer, and autocomplete works for everything except 'c.'

#

And it works for visual studio on my mac as well. So its literally just neovim not autocompleting for the sdl package. 🙄

valid summit
iron abyss
valid summit
#

The only difference from you is that I used addTranslateC instead of @cImport

brisk thorn
#

Turns out its probably a homebrew issue.

% zig env
error: Zig was built/linked incorrectly: LLVM and Clang have separate copies of libc++
       If you are dynamically linking LLVM, make sure you dynamically link libc++ too
strange bay
#

I have a weird issue with vscode and zls where importing sokol in build.zig gives me its types but if I import it in any other file it doesn't 😢

olive yacht
#

if your program compiles succesfully using sokol, then try restarting zls

strange bay
#

yes, it compiles like a charm, I restarted zls, cleared its cache, downloaded it again. nothing

#

I'm using zig 0.13 through the vscode extension