Skip to content

Commit cf97218

Browse files
feat(ts)!: Update required tree-sitter-org version
1 parent 06131e1 commit cf97218

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

.github/workflows/luarocks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ jobs:
3131
with:
3232
version: ${{ env.LUAROCKS_VERSION }}
3333
dependencies: |
34-
tree-sitter-orgmode ~> 1
34+
tree-sitter-orgmode ~> 2

lua/orgmode/health.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ function M.check()
1010
end
1111

1212
function M.check_has_treesitter()
13-
local ok, result, err = pcall(vim.treesitter.language.add, 'org')
14-
if not ok or (not result and err ~= nil) then
13+
local ts = require('orgmode.utils.treesitter.install')
14+
if ts.not_installed() then
1515
return h.error('Treesitter grammar is not installed. Run `:Org install_treesitter_grammar` to install it.')
1616
end
17+
if ts.outdated() then
18+
return h.error('Treesitter grammar is out of date. Run `:Org install_treesitter_grammar` to update it.')
19+
end
1720
return h.ok('Treesitter grammar installed')
1821
end
1922

lua/orgmode/utils/init.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,4 +622,18 @@ function utils.get_visual_selection()
622622
return table.concat(vim.fn.getregion(vim.fn.getpos('v'), vim.fn.getpos('.')), '\n')
623623
end
624624

625+
---@param msg string|string[]
626+
---@param opts? { level?: 'info' | 'warn' | 'error', id: string }
627+
---@return string
628+
function utils.notify(msg, opts)
629+
opts = vim.tbl_extend('force', {
630+
title = 'Orgmode',
631+
id = 'orgmode',
632+
level = 'info',
633+
}, opts or {})
634+
635+
local message = type(msg) == 'table' and table.concat(msg, '\n') or msg --[[@as string]]
636+
vim.notify(message, vim.log.levels[opts.level:upper()], opts)
637+
end
638+
625639
return utils

lua/orgmode/utils/treesitter/install.lua

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local M = {
55
compilers = { vim.fn.getenv('CC'), 'cc', 'gcc', 'clang', 'cl', 'zig' },
66
}
77

8-
local required_version = '1.3.4'
8+
local required_version = '2.0.0'
99

1010
function M.install()
1111
if M.not_installed() then
@@ -55,7 +55,7 @@ function M.get_package_path()
5555
end
5656

5757
function M.get_lock_file()
58-
return M.get_package_path() .. '/.org-ts-lock.json'
58+
return vim.fs.joinpath(M.get_package_path(), '.org-ts-lock.json')
5959
end
6060

6161
function M.select_compiler_args(compiler)
@@ -119,7 +119,7 @@ function M.get_path(url, type)
119119
local is_local_path = vim.fn.isdirectory(local_path) == 1
120120

121121
if is_local_path then
122-
utils.echo_info('Using local version of tree-sitter grammar...')
122+
utils.notify('Using local version of tree-sitter grammar...')
123123
return Promise.resolve(local_path)
124124
end
125125

@@ -132,7 +132,7 @@ function M.get_path(url, type)
132132
reinstall = 'Reinstalling',
133133
}
134134

135-
utils.echo_info(('%s tree-sitter grammar...'):format(msg[type]))
135+
utils.notify(('%s tree-sitter grammar...'):format(msg[type]))
136136
return M.exe('git', {
137137
args = { 'clone', '--filter=blob:none', '--depth=1', '--branch=' .. required_version, url, path },
138138
}):next(function(code)
@@ -145,8 +145,7 @@ end
145145

146146
---@param type? 'install' | 'update' | 'reinstall''
147147
function M.run(type)
148-
-- local url = 'https://github.com/nvim-orgmode/tree-sitter-org'
149-
local url = '/home/kristijan/github/tree-sitter-org'
148+
local url = 'https://github.com/nvim-orgmode/tree-sitter-org'
150149
local compiler = vim.tbl_filter(function(exe)
151150
return exe ~= vim.NIL and vim.fn.executable(exe) == 1
152151
end, M.compilers)[1]
@@ -171,12 +170,19 @@ function M.run(type)
171170
if code ~= 0 then
172171
error('[orgmode] Failed to compile parser', 0)
173172
end
174-
local renamed = vim.fn.rename(path .. '/parser.so', package_path .. '/parser/org.so')
173+
local source = vim.fs.joinpath(path, 'parser.so')
174+
local destination = vim.fs.joinpath(package_path, 'parser', 'org.so')
175+
local renamed = vim.fn.rename(source, destination)
175176
if renamed ~= 0 then
176177
error('[orgmode] Failed to move generated tree-sitter parser to runtime folder', 0)
177178
end
178179
utils.writefile(M.get_lock_file(), vim.json.encode({ version = required_version })):wait()
179-
utils.echo_info('Done!')
180+
local msg = { 'Done!' }
181+
if type == 'update' then
182+
table.insert(msg, 'Please restart Neovim to apply the changes.')
183+
end
184+
utils.notify(msg)
185+
vim.treesitter.language.add('org')
180186
return true
181187
end))
182188
:wait(60000)

0 commit comments

Comments
 (0)