Skip to content

Commit

Permalink
Create unit tests for tree-sitter (#34)
Browse files Browse the repository at this point in the history
* added some unit tests for the tree-sitter

* updated github actions and rockspec
  • Loading branch information
FourierTransformer authored Nov 30, 2024
1 parent 2dad2a7 commit 85d6a63
Show file tree
Hide file tree
Showing 7 changed files with 386 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
- uses: actions/checkout@main

- name: Install Lua
uses: leafo/gh-actions-lua@v8.0.0
uses: leafo/gh-actions-lua@v10
with:
luaVersion: ${{ matrix.luaVersion }}

- name: Install LuaRocks
uses: leafo/gh-actions-luarocks@v4.0.0
uses: leafo/gh-actions-luarocks@v4

- name: Build
run: scripts/setup_local_luarocks.sh
Expand Down
12 changes: 6 additions & 6 deletions gen/teal_language_server/document.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local asserts = require("teal_language_server.asserts")
local tracing = require("teal_language_server.tracing")

local ltreesitter = require("ltreesitter")
local teal_parser = ltreesitter.load("./teal.so", "teal")
local teal_parser = ltreesitter.require("parser/teal", "teal")

local tl = require("tl")

Expand Down Expand Up @@ -397,7 +397,7 @@ function Document:type_information_for_tokens(tokens, y, x)
return nil
end

function Document:_parser_token(y, x)
function Document:_tree_sitter_token(y, x)
local moved = self._tree_cursor:goto_first_child()
local node = self._tree_cursor:current_node()

Expand Down Expand Up @@ -487,21 +487,21 @@ function Document:_parser_token(y, x)

if y == start_point.row and y == end_point.row then
if x >= start_point.column and x <= end_point.column then
return self:_parser_token(y, x)
return self:_tree_sitter_token(y, x)
end

elseif y >= start_point.row and y <= end_point.row then
return self:_parser_token(y, x)
return self:_tree_sitter_token(y, x)
end

moved = self._tree_cursor:goto_next_sibling()
node = self._tree_cursor:current_node()
end
end

function Document:parser_token(y, x)
function Document:tree_sitter_token(y, x)
self._tree_cursor:reset(self._tree:root())
return self:_parser_token(y, x)
return self:_tree_sitter_token(y, x)
end

class.setup(Document, "Document", {
Expand Down
2 changes: 1 addition & 1 deletion gen/teal_language_server/misc_handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function MiscHandlers:_get_node_info(params, pos)
end

tracing.warning(_module_name, "Received request for completion at position: {}", { pos })
local node_info = doc:parser_token(pos.line, pos.character)
local node_info = doc:tree_sitter_token(pos.line, pos.character)
if node_info == nil then
tracing.warning(_module_name, "Unable to retrieve node info from tree-sitter parser", {})
return nil
Expand Down
Loading

0 comments on commit 85d6a63

Please sign in to comment.