Skip to content

Commit

Permalink
fix: TSInstall issues on macOS, hopefully once and for good (#891)
Browse files Browse the repository at this point in the history
  • Loading branch information
aldanor authored May 24, 2023
1 parent c233100 commit 4988a6f
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion lua/neorg/modules/core/integrations/treesitter/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,45 @@ module.public = {
end,
}

-- this fixes the problem of installing neorg ts parsers on macOS without resorting to using gcc
local function install_norg_ts()
if vim.fn.has 'macunix' == 1 then
-- https://github.com/nvim-neorg/tree-sitter-norg/issues/7
-- (we have to force clang to c++11 mode on macOS manually)

local shell = require 'nvim-treesitter.shell_command_selectors'
local install = require 'nvim-treesitter.install'

-- save the original functions
local select_executable = shell.select_executable
local compilers = install.compilers

-- temporarily patch treesitter install logic
local cc = 'clang++ -std=c++11'
---@diagnostic disable-next-line: duplicate-set-field
shell.select_executable = function(executables)
return vim.tbl_filter(function(c) ---@param c string
return c ~= vim.NIL and (vim.fn.executable(c) == 1 or c == cc)
end, executables)[1]
end
install.compilers = { cc }

-- install norg parsers
local ok, err = pcall(function()
install.commands.TSInstallSync['run!'] 'norg'
end)

-- no matter what, restore the defaults back
shell.select_executable = select_executable
install.compilers = compilers

-- if an error occurred during install, propagate it up
if not ok then error(err) end
else
vim.cmd [[ TSInstall! norg ]]
end
end

module.on_event = function(event)
if event.split_type[1] == "core.keybinds" then
if event.split_type[2] == "core.integrations.treesitter.next.heading" then
Expand All @@ -695,7 +734,7 @@ module.on_event = function(event)
module.public.goto_previous_query_match(module.private.link_query)
end
elseif event.split_type[2] == "sync-parsers" then
local ok = pcall(vim.cmd, "TSInstall! norg")
local ok = pcall(install_norg_ts)

if not ok then
neorg.utils.notify(
Expand Down

0 comments on commit 4988a6f

Please sign in to comment.