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

Zig: setting up Zig + LSP(ZLS) with Vscode/Sublime Text 4/Clion #376

Open
3 tasks done
Tracked by #320 ...
hhstore opened this issue Jul 31, 2022 · 7 comments
Open
3 tasks done
Tracked by #320 ...

Zig: setting up Zig + LSP(ZLS) with Vscode/Sublime Text 4/Clion #376

hhstore opened this issue Jul 31, 2022 · 7 comments

Comments

@hhstore
Copy link
Owner

hhstore commented Jul 31, 2022

related:

sublime text 4 配置:

@hhstore
Copy link
Owner Author

hhstore commented Jul 31, 2022

Zig + Vscode/Sublime Text 4/Clion 搭建开发环境:

步骤说明:

✅ 1. 安装 zig.
✅ 2. 安装 zls, 用于 vscode 解析/索引 zig 代码.
✅ 3. 安装 vscode/clion 相关 zig 插件
✅ 4. 更改 vscode 插件设置, 配置 zls 参数.
✅ 5. 配置结束, 愉快写代码.

安装 Zig:

setup zig development environment.

install:

  • ✅ 建议直接安装 dev 版本, zig 迭代很活跃. 社区包, 基本都是基于 nightly 版本构建.
  • ✅ 脚本1, 安装 zig dev 版本, 从官网下载官网 - 安装包, 解压到指定路径.
  • ✅ 脚本2, 安装 zig 稳定版本 + zls 脚本. 可以把 zls 安装脚本挑出来, 单独安装 zls.
  # for macos + m1:
  install:zig:dev:
    cmds:
      - mkdir -p $HOME/.local/bin/;
      - cd $HOME/.local/bin/; curl -L https://ziglang.org/builds/zig-macos-aarch64-0.10.0-dev.2617+47c4d4450.tar.xz | tar -xJ --strip-components=1 -C .;
      - chmod +x $HOME/.local/bin/zig;
      - zig version


  install:zig:
    cmds:
      - brew install zig
      - zig version
      - brew install xz # for zig zls
      - mkdir $HOME/zls && cd $HOME/zls && curl -L https://github.com/zigtools/zls/releases/download/0.9.0/x86_64-macos.tar.xz | tar -xJ --strip-components=1 -C .
      - chmod +x $HOME/zls/zls
      - sudo $HOME/zls/zls configure
    ignore_error: true
  • 当前 dev 版本:
 which zig
/Users/dev/.local/bin/zig

 zig version
0.10.0-dev.2617+47c4d4450



 zig env
{
 "zig_exe": "/Users/dev/.local/bin/zig",
 "lib_dir": "/Users/dev/.local/bin/lib/zig",
 "std_dir": "/Users/dev/.local/bin/lib/zig/std",
 "global_cache_dir": "/Users/dev/.cache/zig",
 "version": "0.10.0-dev.2617+47c4d4450"
}

安装 ZLS: (代码解析)

  install:zls:
    cmds:
      - brew install xz # for zig zls
      - mkdir $HOME/zls && cd $HOME/zls && curl -L https://github.com/zigtools/zls/releases/download/0.9.0/x86_64-macos.tar.xz | tar -xJ --strip-components=1 -C .
      - chmod +x $HOME/zls/zls
      - sudo $HOME/zls/zls configure
    ignore_error: true
  • 交互式配置日志:
Welcome to the ZLS configuration wizard!
      *
       |\
      /* \
      |  *\
    _/_*___|_    x
      | @ @     /
     @     \   /
      \__-/   /

? Should this configuration be system-wide? (y/n) > y
Found zig executable '/Users/dev/.local/bin/zig' in PATH.
? Which code editor do you use? (select one)

  - VSCode
  - Sublime
  - Kate
  - Neovim
  - Vim8
  - Emacs
  - Doom
  - Other

> vscode
? Do you want to enable snippets? (y/n) > y
? Do you want to enable style warnings? (y/n) > y
? Do you want to enable semantic highlighting? (y/n) > y
? Do you want to enable .* and .? completions? (y/n) > y
Writing config to /Library/Preferences/zls.json ... successful.



To use ZLS in Visual Studio Code, install the 'ZLS for VSCode' extension from 
'https://github.com/zigtools/zls-vscode/releases' or via the extensions menu.
Then, open VSCode's 'settings.json' file, and add:

"zigLanguageClient.path": "[command_or_path_to_zls]"

Thank you for choosing ZLS!

vscode 配置:

vscode 下载:

vscode 插件安装:

参考:

clion / IntelliJ IDEA 配置:

IDE: clion

插件: intellij-zig

@hhstore
Copy link
Owner Author

hhstore commented Jul 31, 2022

vscode 配置:

# vscode 设置, 搜索 zls, 添加对应的 zls 安装路径

/Users/dev/zls/zls

vscode 设置:

image

  • ✅ 代码预览:

image

  • ✅ 成功跳转:

image

  • ✅ 跳转到标准库:

image

之后, 就可以愉快的写 zig 了.

@hhstore
Copy link
Owner Author

hhstore commented Jul 31, 2022

clion / IntelliJ IDEA 配置:

  • 目前 zig 的几个插件, 对最新版本的 IntelliJ IDEA 并不 work.
  • so, 只能使用 vscode + zig + zls 开发.
  • 理论上, vim + zls 也应该是 work 的.

@hhstore
Copy link
Owner Author

hhstore commented Jul 31, 2022

1

@hhstore hhstore changed the title Zig: with vscode Zig: with vscode/clion Jul 31, 2022
@hhstore hhstore mentioned this issue Jul 31, 2022
5 tasks
This was referenced Aug 21, 2022
@hhstore
Copy link
Owner Author

hhstore commented Sep 8, 2022

Sublime Text 4 + ZLS 配置 Zig 开发环境:

zls 配置:

步骤:

  1. 下载安装 Sublime Text 4.
  2. 安装 LSP 插件: https://github.com/sublimelsp/LSP
  3. 设置中, 添加 LSP 配置段:
    • 注意 zls 的路径, 填写自己机器对应的路径.
  4. 结束. (如果不生效, 重启一下编辑器)
// Settings in here override those in "LSP/LSP.sublime-settings"
{
    "clients": {
        "zig": {
            "command": ["/Users/dev/zls/zls"],
            "enabled": true,
            "selector": "source.zig"
        }
    }
}

image

配置成功效果:

  • sublime text 4 配置方式很简单. 目前 vscode + zls 插件好像炸了. 暂时只能使用 sublime text 4来开发.

image

  • 预览模块效果:

image

插件安装:

theme 插件:

必装插件:

  • 终端插件
  • git 插件
  • LSP 插件

image

@hhstore hhstore changed the title Zig: with vscode/clion Zig: with Vscode/Sublime Text 4/Clion Sep 8, 2022
This was referenced Sep 8, 2022
@hhstore
Copy link
Owner Author

hhstore commented Sep 9, 2022

zls-vscode 插件炸机:

@hhstore hhstore added the LSP label Sep 9, 2022
@hhstore hhstore changed the title Zig: with Vscode/Sublime Text 4/Clion Zig: configure LSP(ZLS) with Vscode/Sublime Text 4/Clion Nov 4, 2022
@hhstore hhstore changed the title Zig: configure LSP(ZLS) with Vscode/Sublime Text 4/Clion Zig: setting up Zig + LSP(ZLS) with Vscode/Sublime Text 4/Clion Nov 4, 2022
@CreatorMetaSky
Copy link

CreatorMetaSky commented Nov 17, 2022

如果用最新版本的 zls-vscode, 安装方式:zig + zls-vscode + zls,最好看下 zls-vscode 提示的编译 zls 的 zig 版本,下载一个一样的版本 zig 就可以了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants