-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from mistweaverco/feat-complete-rewrite-parser
Feat complete rewrite parser
- Loading branch information
Showing
11 changed files
with
272 additions
and
401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
local FS = require("kulala.utils.fs") | ||
local M = {} | ||
|
||
M.pipe = function(cmdstring, contents) | ||
-- build the command | ||
local cmd = {} | ||
for token in string.gmatch(cmdstring, "[^%s]+") do | ||
table.insert(cmd, token) | ||
end | ||
local cmd_exists = FS.command_exists(cmd[1]) | ||
if not cmd_exists then | ||
vim.notify("Pipe --> Command not found: " .. cmd[1] .. ". Returning plain contents..", vim.log.levels.ERROR) | ||
return contents | ||
end | ||
return vim.system(cmd, { stdin = contents, text = true }):wait().stdout | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,23 @@ | ||
local Ts = vim.treesitter | ||
local PARSER = require("kulala.parser") | ||
|
||
local M = {} | ||
|
||
-- Function to find all "request" nodes in the tree | ||
local function find_all_request_nodes(node) | ||
local request_nodes = {} | ||
|
||
local function recursive_search(node) | ||
if not node then return end | ||
|
||
for child in node:iter_children() do | ||
if child:type() == "request" then | ||
table.insert(request_nodes, child) | ||
end | ||
recursive_search(child) | ||
end | ||
end | ||
|
||
recursive_search(node) | ||
return request_nodes | ||
end | ||
|
||
-- Function to move to the next "request" node | ||
M.jump_next = function() | ||
local bufnr = vim.api.nvim_get_current_buf() | ||
local parser = Ts.get_parser(bufnr) | ||
local tree = parser:parse()[1] | ||
local root = tree:root() | ||
|
||
local request_nodes = find_all_request_nodes(root) | ||
|
||
-- Get the current cursor position | ||
local cursor = vim.api.nvim_win_get_cursor(0) | ||
local current_row = cursor[1] - 1 | ||
local current_col = cursor[2] | ||
|
||
for _, node in ipairs(request_nodes) do | ||
local start_row, start_col, _, _ = node:range() | ||
if start_row > current_row or (start_row == current_row and start_col > current_col) then | ||
vim.api.nvim_win_set_cursor(0, {start_row + 1, start_col}) | ||
return | ||
end | ||
local _, reqs = PARSER.get_document() | ||
local next = PARSER.get_next_request(reqs) | ||
if next then | ||
vim.api.nvim_win_set_cursor(0, {next.start_line + 1, 0}) | ||
end | ||
|
||
print("No next 'request' node found") | ||
end | ||
|
||
-- Function to move to the previous "request" node | ||
M.jump_prev = function() | ||
local bufnr = vim.api.nvim_get_current_buf() | ||
local parser = Ts.get_parser(bufnr) | ||
local tree = parser:parse()[1] | ||
local root = tree:root() | ||
|
||
local request_nodes = find_all_request_nodes(root) | ||
|
||
-- Get the current cursor position | ||
local cursor = vim.api.nvim_win_get_cursor(0) | ||
local current_row = cursor[1] - 1 | ||
local current_col = cursor[2] | ||
|
||
for i = #request_nodes, 1, -1 do | ||
local node = request_nodes[i] | ||
local start_row, start_col, _, _ = node:range() | ||
if start_row < current_row or (start_row == current_row and start_col < current_col) then | ||
vim.api.nvim_win_set_cursor(0, {start_row + 1, start_col}) | ||
return | ||
end | ||
local _, reqs = PARSER.get_document() | ||
local prev = PARSER.get_previous_request(reqs) | ||
if prev then | ||
vim.api.nvim_win_set_cursor(0, {prev.start_line + 1, 0}) | ||
end | ||
|
||
print("No previous 'request' node found") | ||
end | ||
|
||
|
||
|
||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.