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 15, 2024
1 parent ace7904 commit b10e02f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 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
5 changes: 4 additions & 1 deletion lua/rocks_treesitter/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ local function install_latest_version(rocks)
end
)
end
api.install(rocks[1].name, tostring(latest_version or "dev"), try_start_highlight)
api.install(rocks[1].name, tostring(latest_version or "dev"), {
callback = try_start_highlight,
config_path = config.config_path,
})
end

---@param rocks Rock[]
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 b10e02f

Please sign in to comment.