Skip to content

Commit

Permalink
fix: on Windows, use zig compiler for treesitter instead of clang
Browse files Browse the repository at this point in the history
On Windows:

Rust: `cargo build` -> builds successfully.
Zig: `zig build-exe` -> builds successfully.
C++: `clang++ main.cpp` -> unable to find a visual studio installation; try running clang from a developer command prompt [-wmsvc-not-found]

Windows C++ toolchain is still a joke today, and the joke's not funny
anymore.

As the zig way of building treesitter is unstable on other platforms,
limit zig usage to just Windows.
  • Loading branch information
yamgent committed Jul 24, 2024
1 parent db5684a commit a019b26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 4 additions & 3 deletions docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
### Common
* Rust
* Rationale: Mainly for compiling
* Clang
* Plugin users: Treesitter
* Note: For Windows, setting up `PATH` is essential so that Treesitter can access clang. For more details, see [Treesitter Wiki](https://github.com/nvim-treesitter/nvim-treesitter/wiki/Windows-support) ("Through Visual Studio")
* Clang (non-Windows only)
* Plugin users: Treesiiter
* Zig (Windows only)
* Plugin users: Treesitter (clang is a pain to setup on Windows)
* Nodejs
* Plugin users: Lsp
* Nerd Fonts
Expand Down
12 changes: 10 additions & 2 deletions lua/wangleng/plugins/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ return {
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function()
local is_win32 = vim.fn.has('win32') == 1

if is_win32 then
-- on Windows, it is a pain to set up clang properly
require("nvim-treesitter.install").compilers = { "zig" }
end

local configs = require("nvim-treesitter.configs")

configs.setup({
Expand All @@ -19,7 +26,9 @@ return {
"zig",
},
-- install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
-- zig can only install synchronously, async install somehow have problems
-- (and since Windows is using zig, have to disable async install, which is the default)
sync_install = is_win32,
-- enable highlighting
highlight = { enable = true },
-- enable indent behaviour when using '=' operator
Expand All @@ -28,4 +37,3 @@ return {
end
},
}

0 comments on commit a019b26

Please sign in to comment.