-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle
filter_dir
,is_test_file
functions with jdtls
delete all nvim-java dependency add project cache support
- Loading branch information
Showing
26 changed files
with
1,002 additions
and
347 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,63 +1,18 @@ | ||
local adapter = {} | ||
---@class neotest.Adapter | ||
---@field name string | ||
adapter.Adapter = { name = 'neotest-jdtls' } | ||
local adapter = require('neotest-jdtls.neotest.adapter') | ||
local project = require('neotest-jdtls.utils.project') | ||
|
||
---Find the project root directory given a current directory to work from. | ||
---Should no root be found, the adapter can still be used in a non-project context if a test file matches. | ||
---@async | ||
---@param dir string @Directory to treat as cwd | ||
---@return string | nil @Absolute root dir of test suite | ||
function adapter.Adapter.root(dir) | ||
return require('neotest-jdtls.impl.root').root(dir) | ||
end | ||
local group = vim.api.nvim_create_augroup('neotest-jdtls', { clear = true }) | ||
|
||
---Filter directories when searching for test files | ||
---@async | ||
---@param name string Name of directory | ||
---@param rel_path string Path to directory, relative to root | ||
---@param root string Root directory of project | ||
---@return boolean | ||
function adapter.Adapter.filter_dir(name, rel_path, root) | ||
return require('neotest-jdtls.impl.filter_dir').filter_dir( | ||
name, | ||
rel_path, | ||
root | ||
) | ||
end | ||
vim.api.nvim_create_autocmd({ 'BufWritePost' }, { | ||
pattern = '*.java', | ||
callback = project.autocmd_clear_cache, | ||
group = group, | ||
}) | ||
|
||
---@async | ||
---@param file_path string | ||
---@return boolean | ||
function adapter.Adapter.is_test_file(file_path) | ||
local is_test_file = | ||
require('neotest-jdtls.impl.is_test_file').is_test_file(file_path) | ||
return is_test_file | ||
end | ||
vim.api.nvim_create_user_command( | ||
'NeotestJdtlsClearProjectCache', | ||
project.clear_project_cache, | ||
{} | ||
) | ||
|
||
---Given a file path, parse all the tests within it. | ||
---@async | ||
---@param file_path string Absolute file path | ||
---@return neotest.Tree | nil | ||
function adapter.Adapter.discover_positions(file_path) | ||
return require('neotest-jdtls.impl.discover_positions').discover_positions( | ||
file_path | ||
) | ||
end | ||
|
||
---@param args neotest.RunArgs | ||
---@return neotest.RunSpec | ||
function adapter.Adapter.build_spec(args) | ||
return require('neotest-jdtls.impl.excute').build_spec(args) | ||
end | ||
|
||
---@async | ||
---@param spec neotest.RunSpec | ||
---@param result neotest.StrategyResult | ||
---@param tree neotest.Tree | ||
---@return table<string, neotest.Result> | ||
function adapter.Adapter.results(spec, result, tree) | ||
return require('neotest-jdtls.impl.results').results(spec, result, tree) | ||
end | ||
|
||
return adapter.Adapter | ||
return adapter |
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,51 @@ | ||
local class = require('neotest-jdtls.utils.class') | ||
local log = require('neotest-jdtls.utils.log') | ||
local ResultParserFactory = | ||
require('neotest-jdtls.junit.results.result-parser-factory') | ||
|
||
---@class java_test.JUnitTestReport | ||
---@field private conn uv_tcp_t | ||
---@field private result_parser java_test.TestParser | ||
---@field private result_parser_fac java_test.TestParserFactory | ||
local JUnitReport = class() | ||
|
||
function JUnitReport:_init() | ||
self.conn = nil | ||
self.result_parser_fac = ResultParserFactory() | ||
end | ||
|
||
---Returns the test results | ||
---@return java_test.TestResults[] | ||
function JUnitReport:get_results() | ||
return self.result_parser:get_test_details() | ||
end | ||
|
||
---Returns a stream reader function | ||
---@param conn uv_tcp_t | ||
---@return fun(err: string, buffer: string) # callback function | ||
function JUnitReport:get_stream_reader(conn) | ||
self.conn = conn | ||
self.result_parser = self.result_parser_fac:get_parser() | ||
return vim.schedule_wrap(function(err, buffer) | ||
if err then | ||
self.conn:close() | ||
return | ||
end | ||
|
||
if buffer then | ||
self:on_update(buffer) | ||
else | ||
self.conn:close() | ||
end | ||
end) | ||
end | ||
|
||
---Runs on connection update | ||
---@private | ||
---@param text string | ||
function JUnitReport:on_update(text) | ||
log.trace('on_update', text) | ||
self.result_parser:parse(text) | ||
end | ||
|
||
return JUnitReport |
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,7 @@ | ||
---@enum java_test.TestExecutionStatus | ||
local TestStatus = { | ||
Started = 'started', | ||
Ended = 'ended', | ||
} | ||
|
||
return TestStatus |
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,30 @@ | ||
---@enum MessageId | ||
local MessageId = { | ||
-- Notification about a test inside the test suite. | ||
-- TEST_TREE + testId + "," + testName + "," + isSuite + "," + testCount + "," + isDynamicTest + | ||
-- "," + parentId + "," + displayName + "," + parameterTypes + "," + uniqueId | ||
|
||
-- isSuite = "true" or "false" | ||
-- isDynamicTest = "true" or "false" | ||
-- parentId = the unique id of its parent if it is a dynamic test, otherwise can be "-1" | ||
-- displayName = the display name of the test | ||
-- parameterTypes = comma-separated list of method parameter types if applicable, otherwise an | ||
-- empty string | ||
-- uniqueId = the unique ID of the test provided by JUnit launcher, otherwise an empty string | ||
|
||
TestTree = '%TSTTREE', | ||
TestStart = '%TESTS', | ||
TestEnd = '%TESTE', | ||
TestFailed = '%FAILED', | ||
TestError = '%ERROR', | ||
ExpectStart = '%EXPECTS', | ||
ExpectEnd = '%EXPECTE', | ||
ActualStart = '%ACTUALS', | ||
ActualEnd = '%ACTUALE', | ||
TraceStart = '%TRACES', | ||
TraceEnd = '%TRACEE', | ||
IGNORE_TEST_PREFIX = '@Ignore: ', | ||
ASSUMPTION_FAILED_TEST_PREFIX = '@AssumptionFailure: ', | ||
} | ||
|
||
return MessageId |
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,14 @@ | ||
local class = require('neotest-jdtls.utils.class') | ||
local TestParser = require('neotest-jdtls.junit.results.result-parser') | ||
|
||
---@class java_test.TestParserFactory | ||
local TestParserFactory = class() | ||
|
||
---Returns a test parser of given type | ||
---@param args any | ||
---@return java_test.TestParser | ||
function TestParserFactory.get_parser(_args) | ||
return TestParser() | ||
end | ||
|
||
return TestParserFactory |
Oops, something went wrong.