Skip to content

Commit

Permalink
feat: Add support for an optional import config path
Browse files Browse the repository at this point in the history
  • Loading branch information
simifalaye committed Nov 12, 2024
1 parent 48a6c86 commit 2912c76
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/luarocks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
with:
version: ${{ env.LUAROCKS_VERSION }}
dependencies: |
rocks.nvim >= 1.19.0
rocks.nvim >= 2.42.0
4 changes: 3 additions & 1 deletion doc/rocks-treesitter.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ configure this plugin.
disable = [
"lhaskell"
]

config_path = "rocks-treesitter.toml"

[treesitter.parser_map]
# You can add custom filetype to parser mappings.
# Determine the filetype with ':lua =vim.bo[0].filetype'.
Expand All @@ -104,6 +105,7 @@ Or, you add a lua table to your `vim.g.rocks_nvim` setting:
parser_map = { },
---@type string[] | fun(lang: string, bufnr: integer):boolean
disable = { }, -- filetypes or a function
config_path = "rocks-treesitter.toml",
},
}
<
Expand Down
8 changes: 8 additions & 0 deletions lua/rocks_treesitter/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ local config = {
disable = {},
---@type table<string, string>
parser_map = require("rocks_treesitter.ft_parser_map"),
---@type string?
config_path = nil,
}

local api = require("rocks.api")
Expand All @@ -32,6 +34,11 @@ local api = require("rocks.api")
--- File types to disable highlighting for (lua + toml config)
--- or a function to conditionally disable highlighting (lua only)
---@field disable? string[] | fun(lang: string, bufnr: integer):boolean
---
--- Specify a config path, relative to the base rocks config file, to
--- install treesitter rocks (ex. "rocks-treesitter.toml"). If not set, they will be added
--- to the base config file
--- @field config_path? string

local toml_config = api.get_rocks_toml()["treesitter"]
---@type RocksTreesitterOpts
Expand Down Expand Up @@ -75,5 +82,6 @@ config.disable = type(opts.disable) == "function" and opts.disable
---@diagnostic disable-next-line: assign-type-mismatch
config.auto_install = vim.F.if_nil(opts.auto_install, config.auto_install)
config.parser_map = vim.tbl_extend("force", config.parser_map, opts.parser_map or {})
config.config_path = vim.F.if_nil(opts.config_path)

return config
16 changes: 11 additions & 5 deletions lua/rocks_treesitter/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ local function prompt_auto_install(rocks)
---@param version string?
local function install_rock_or_mark_declined(version)
if version then
api.install(rock_name, version, function(installed_rock)
---@cast installed_rock Rock
try_start_highlight(installed_rock)
end)
api.install(rock_name, version, {
callback = function(installed_rock)
---@cast installed_rock Rock
try_start_highlight(installed_rock)
end,
config_path = config.config_path,
})
else
_declined_installs[rock_name] = true
end
Expand Down Expand Up @@ -118,7 +121,10 @@ local function do_highlight(lang)
prompt_auto_install(rocks)
end)
elseif config.auto_install then
api.install(rocks[1].name, nil, try_start_highlight)
api.install(rocks[1].name, nil, {
callback = try_start_highlight,
config_path = config.config_path
})
end
end)
end
Expand Down
2 changes: 1 addition & 1 deletion rocks-treesitter.nvim-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = _MODREV .. _SPECREV

dependencies = {
"lua >= 5.1",
"rocks.nvim >= 1.19.0",
"rocks.nvim >= 2.42.0",
}

source = {
Expand Down

0 comments on commit 2912c76

Please sign in to comment.