Skip to content

Commit 71cd029

Browse files
authored
fix: tree-sitter-norg parser builds on MacOS (#1587)
- Added use_makefile, which is how nvim-treesitter builds the norg parser by default and correctly adds the required flags - Removed a MacOS build kludge that is no longer needed (and seems not to work anymore) - Removed branch specification which is ignored when setting revision.
1 parent a48166d commit 71cd029

File tree

1 file changed

+3
-50
lines changed
  • lua/neorg/modules/core/integrations/treesitter

1 file changed

+3
-50
lines changed

lua/neorg/modules/core/integrations/treesitter/module.lua

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,16 @@ module.config.public = {
147147
norg = {
148148
url = "https://github.com/nvim-neorg/tree-sitter-norg",
149149
files = { "src/parser.c", "src/scanner.cc" },
150-
branch = "main",
151150
revision = "6348056b999f06c2c7f43bb0a5aa7cfde5302712",
151+
use_makefile = true,
152152
},
153153
-- Configuration for the metadata parser (used to parse the contents
154154
-- of `@document.meta` blocks).
155155
norg_meta = {
156156
url = "https://github.com/nvim-neorg/tree-sitter-norg-meta",
157157
files = { "src/parser.c" },
158-
branch = "main",
159158
revision = "a479d1ca05848d0b51dd25bc9f71a17e0108b240",
159+
use_makefile = true,
160160
},
161161
},
162162
}
@@ -927,57 +927,10 @@ module.public = {
927927
end,
928928
}
929929

930-
-- this fixes the problem of installing neorg ts parsers on macOS without resorting to using gcc
931-
local function install_norg_ts()
932-
local install = require("nvim-treesitter.install")
933-
934-
if vim.fn.has("macunix") == 1 then
935-
-- https://github.com/nvim-neorg/tree-sitter-norg/issues/7
936-
-- (we have to force clang to c++11 mode on macOS manually)
937-
938-
local shell = require("nvim-treesitter.shell_command_selectors")
939-
940-
-- save the original functions
941-
local select_executable = shell.select_executable
942-
local compilers = install.compilers
943-
944-
-- temporarily patch treesitter install logic
945-
local cc = "clang++ -std=c++11"
946-
---@diagnostic disable-next-line: duplicate-set-field
947-
shell.select_executable = function(executables)
948-
return vim.tbl_filter(function(c) ---@param c string
949-
return c ~= vim.NIL and (vim.fn.executable(c) == 1 or c == cc)
950-
end, executables)[1]
951-
end
952-
install.compilers = { cc }
953-
954-
-- install norg parsers
955-
local ok, err = pcall(function()
956-
install.commands.TSInstallSync["run!"]("norg")
957-
end)
958-
959-
-- no matter what, restore the defaults back
960-
shell.select_executable = select_executable
961-
install.compilers = compilers
962-
963-
-- if an error occurred during install, propagate it up
964-
if not ok then
965-
error(err)
966-
end
967-
else
968-
install.commands.TSInstallSync["run!"]("norg")
969-
end
970-
end
971-
972930
module.on_event = function(event)
973931
if event.split_type[2] == "sync-parsers" then
974-
local ok, err = pcall(install_norg_ts)
975-
976-
if not ok then
977-
utils.notify(string.format([[Unable to auto-install Norg parser: %s]], err), vim.log.levels.WARN)
978-
end
979-
980932
local install = require("nvim-treesitter.install")
933+
install.commands.TSInstallSync["run!"]("norg")
981934
install.commands.TSInstallSync["run!"]("norg_meta")
982935
end
983936
end

0 commit comments

Comments
 (0)