Skip to content

Commit

Permalink
fix: #13
Browse files Browse the repository at this point in the history
  • Loading branch information
yioneko committed Apr 10, 2023
1 parent 8240f36 commit ff1e8d1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions lua/nvim-yati/configs/python.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ local config = {
handlers = {
on_initial = {
ch.multiline_string_literal("string"),
ch.multiline_string_literal("string_content"),
},
on_traverse = {
ch.dedent_pattern("else", "identifier", "if_statement"),
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-yati/handlers/rust.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local nt = utils.node_type
local M = {}

local function check_prev_field_closed(field_node, bufnr)
local lines = vim.treesitter.get_node_text(field_node, bufnr, { concat = false })
local lines = vim.split(vim.treesitter.get_node_text(field_node, bufnr, {}), "\n")
for i = #lines, 1, -1 do
local first_char = vim.trim(lines[i]):sub(1, 1)
-- skip previous chained field or empty line
Expand Down
8 changes: 6 additions & 2 deletions lua/nvim-yati/indent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,19 @@ function M.indentexpr(vlnum)
end

logger("START", "Line " .. vlnum)
local ok, indent = pcall(M.get_indent, vlnum - 1)
local ok, indent = xpcall(M.get_indent, debug.traceback, vlnum - 1)
if ok then
logger("END", "Total computed: " .. indent)
return indent
else
logger("END", "Error: " .. indent)
vim.schedule(function()
vim.notify_once(
string.format("[nvim-yati]: indent computation for line %s failed, consider submitting an issue for it", vlnum),
string.format(
"[nvim-yati]: indent computation for line %s failed, consider submitting an issue for it\n%s",
vlnum,
indent
),
vim.log.levels.WARN
)
end)
Expand Down
5 changes: 3 additions & 2 deletions lua/nvim-yati/utils.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
local M = {}
local ts_parser = require("nvim-treesitter.parsers")

---@return LanguageTree
function M.get_parser(bufnr)
return ts_parser.get_parser(bufnr)
local ft = vim.bo[bufnr].filetype
local lang = vim.treesitter.language.get_lang(ft)
return vim.treesitter.get_parser(bufnr, lang)
end

---@return string
Expand Down

0 comments on commit ff1e8d1

Please sign in to comment.