Skip to content

Commit

Permalink
[BREAKING CHANGE] Update to latest tree sitter grammar version
Browse files Browse the repository at this point in the history
  • Loading branch information
kristijanhusak committed Apr 2, 2022
1 parent 78ea0a8 commit 93ab75f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
8 changes: 4 additions & 4 deletions lua/orgmode/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
_G.orgmode = _G.orgmode or {}
local ts_revision = '1c3eb533a9cf6800067357b59e03ac3f91fc3a54'
local ts_revision = '9a595e51c1f69b9ac986f0e0b788804eda0e755d'
local setup_ts_grammar_used = false
local instance = nil

Expand Down Expand Up @@ -75,10 +75,10 @@ local function setup_ts_grammar(revision)
end

local function check_ts_grammar()
if setup_ts_grammar_used then
return
end
vim.defer_fn(function()
if setup_ts_grammar_used then
return
end
local parser_config = require('nvim-treesitter.parsers').get_parser_configs()
if parser_config and parser_config.org and parser_config.org.install_info.revision ~= ts_revision then
require('orgmode.utils').echo_error({
Expand Down
18 changes: 14 additions & 4 deletions lua/orgmode/org/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -454,16 +454,26 @@ function OrgMappings:handle_return(suffix)
item = Files.get_current_file():get_current_node()
end

if item.type == 'itemtext' or item.type == 'bullet' or item.type == 'checkbox' or item.type == 'description' then
if item.type == 'paragraph' or item.type == 'bullet' then
local list_item = item.node:parent()
if list_item:type() ~= 'listitem' then
return
end
local line = vim.fn.getline(list_item:start() + 1)
local end_row, _ = list_item:end_()
local next_line_node = current_file:get_node_at_cursor({ end_row + 1, 0 })
local second_line_node = current_file:get_node_at_cursor({ end_row + 2, 0 })
local is_end_of_file = next_line_node
and vim.tbl_contains({ 'paragraph', 'list' }, next_line_node:type())
and second_line_node
and second_line_node:type() == 'document'
-- Range for list items at the very end of the file are not calculated properly
if (end_row + 1) == vim.fn.line('$') and is_end_of_file then
end_row = end_row + 1
end
local range = {
start = { line = end_row + 1, character = 0 },
['end'] = { line = end_row + 1, character = 0 },
start = { line = end_row, character = 0 },
['end'] = { line = end_row, character = 0 },
}

local checkbox = line:match('^(%s*[%+%-])%s*%[[%sXx%-]?%]')
Expand Down Expand Up @@ -512,7 +522,7 @@ function OrgMappings:handle_return(suffix)
if #text_edits > 0 then
vim.lsp.util.apply_text_edits(text_edits, 0, constants.default_offset_encoding)

vim.fn.cursor(end_row + 2 + (add_empty_line and 1 or 0), 0) -- +1 for 0 index and +1 for next line
vim.fn.cursor(end_row + 1 + (add_empty_line and 1 or 0), 0) -- +1 for next line
vim.cmd([[startinsert!]])
end
end
Expand Down
7 changes: 3 additions & 4 deletions queries/org/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
(headline (stars) @stars (#eq? @stars "*******")) @OrgTSHeadlineLevel7
(headline (stars) @stars (#eq? @stars "********")) @OrgTSHeadlineLevel8
(bullet) @OrgTSBullet
(checkbox) @OrgTSCheckbox
((checkbox) @check (#eq? @check "\[-\]")) @OrgTSCheckboxHalfChecked
((checkbox) @check (#eq? @check "\[ \]")) @OrgTSCheckboxUnchecked
((checkbox) @check (#match? @check "\[[xX]\]")) @OrgTSCheckboxChecked
(listitem . (bullet) . (paragraph . (expr "[" "str" @OrgCheckDone "]") @OrgTSCheckboxChecked (#match? @OrgTSCheckboxChecked "\[[xX]\]")))
(listitem . (bullet) . (paragraph . (expr "[" "-" @OrgCheckInProgress "]") @OrgTSCheckboxHalfChecked (#eq? @OrgTSCheckboxHalfChecked "[-]")))
(listitem . (bullet) . (paragraph . ((expr "[") @OrgTSCheckbox.left (#eq? @OrgTSCheckbox.left "[") . (expr "]") @OrgTSCheckbox.right (#eq? @OrgTSCheckbox.right "]"))))
(property_drawer) @OrgTSPropertyDrawer
(drawer) @OrgTSDrawer
(tag) @OrgTSTag
Expand Down

0 comments on commit 93ab75f

Please sign in to comment.