-
Notifications
You must be signed in to change notification settings - Fork 7
refactor: Cleanup / Tidying + missing tests #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5d509fe
d294fc2
0f9e47f
f118cb2
6cb83be
cbf097f
11d8696
1fed89f
4b80566
611389d
f1fc558
069c360
4e5f8e9
15215d0
d7ec280
47faaa7
3144452
fe2c1fc
15ac5da
fc36012
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
local lib = require("neotest.lib") | ||
local neotest = require("neotest.lib") | ||
|
||
local M = {} | ||
local class_query = require("neotest-kotlin.treesitter.class-query") | ||
local package_query = require("neotest-kotlin.treesitter.package-query") | ||
local kotest_query = require("neotest-kotlin.treesitter.kotest-query") | ||
|
||
M.parse = function(path, query) | ||
local positions = lib.treesitter.parse_positions(path, query, { | ||
nested_namespaces = true, | ||
nested_tests = false, | ||
fast = false, | ||
}) | ||
|
||
return positions | ||
end | ||
local M = {} | ||
|
||
---Get all matches for the query perform on the path | ||
---@param path string | ||
---@param query string | ||
---@return string[] | ||
M.get_all_matches_as_string = function(path, query) | ||
local function get_all_matches_as_string(path, query) | ||
local language = "kotlin" | ||
|
||
local bufnr = vim.api.nvim_create_buf(false, true) | ||
|
@@ -54,17 +48,28 @@ M.get_all_matches_as_string = function(path, query) | |
return results | ||
end | ||
|
||
--- This will take in a path to a file, run a treesitter query on it, and return the first match as a string. | ||
---@param path string path to file | ||
---@param query string treesitter query | ||
---@return string? first_match | ||
M.get_first_match_string = function(path, query) | ||
local results = M.get_all_matches_as_string(path, query) | ||
if #results > 0 then | ||
return results[1] | ||
end | ||
---List all classes in a provided file using treesitter | ||
---@param file string | ||
---@return string[] classes | ||
function M.list_all_classes(file) | ||
return get_all_matches_as_string(file, class_query) | ||
end | ||
|
||
---Get the first java package in a provided file using treesitter | ||
---@param file string | ||
---@return string? package | ||
function M.java_package(file) | ||
return get_all_matches_as_string(file, package_query)[1] | ||
end | ||
|
||
return nil | ||
---Uses neotest.treeistter.parse_positions to discover all namespaces/tests in a file. | ||
---@param file string | ||
---@return neotest.Tree? | ||
function M.parse_positions(file) | ||
return neotest.treesitter.parse_positions(file, kotest_query, { | ||
nested_namespaces = true, | ||
nested_tests = false, | ||
}) | ||
Comment on lines
+51
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of exposing the raw Treesitter queries using the |
||
end | ||
|
||
return M |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"target" was typo'd as "taret" super minor change, doesn't really make sense in a refactor, but couldn't help myself