Skip to content

Commit

Permalink
feat: non-strict indentation check for code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
benlubas committed May 3, 2024
1 parent aa2412b commit 226cb46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
24 changes: 16 additions & 8 deletions lua/neorg/modules/core/integrations/treesitter/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,12 @@ module.public = {
return result
end,
--- Given a node this function will break down the AST elements and return the corresponding text for certain nodes
-- @Param tag_node (userdata/treesitter node) - a node of type tag/carryover_tag
get_tag_info = function(tag_node)
--- @param tag_node TSNode - a node of type tag/carryover_tag
--- @param strict boolean? default true, true false, don't error when indentation isn't correct
get_tag_info = function(tag_node, strict)
if strict == nil then
strict = true
end
if
not tag_node
or not vim.tbl_contains(
Expand Down Expand Up @@ -429,13 +433,17 @@ module.public = {
for i, line in ipairs(content) do
if i == 1 then
if content_start_column < start_column then
log.error(
string.format(
"Unable to query information about tag on line %d: content is indented less than tag start!",
start_row + 1
if strict then
log.error(
string.format(
"Unable to query information about tag on line %d: content is indented less than tag start!",
start_row + 1
)
)
)
return nil
return nil
else
start_column = content_start_column
end
end
content[i] = string.rep(" ", content_start_column - start_column) .. line
else
Expand Down
2 changes: 1 addition & 1 deletion lua/neorg/modules/core/tangle/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ module.public = {
local capture = query.captures[id]

if capture == "tag" then
local parsed_tag = treesitter.get_tag_info(node)
local parsed_tag = treesitter.get_tag_info(node, false)

if parsed_tag then
local declared_filetype = parsed_tag.parameters[1]
Expand Down

0 comments on commit 226cb46

Please sign in to comment.