Replies: 4 comments 2 replies
-
You can use the local nio = require("nio")
local executeCommand = nio.wrap(jdtls.executeCommand, 2)
adapter.is_test_file = function(file_path)
local uri = vim.uri_from_fname(file_path)
local err, is_test_file = executeCommand({
command = "java.project.isTestFile",
arguments = { uri },
})
assert(err, "could not check the file")
return is_test_file
end |
Beta Was this translation helpful? Give feedback.
-
Here are the interface and types. For the dap strategy, you need to pass a |
Beta Was this translation helpful? Give feedback.
-
@rcarriga nvim-java got a co-routine library https://github.com/nvim-java/lua-async-await. Seems like the one you are using and the one I'm using is not compatible. I tried When I do this, function neotest.Adapter.is_test_file(file_path)
if
file_path
== "/home/s1n7ax/Workspace/demo/src/test/java/com/example/demo/DemoApplicationTests.java"
then
return true
end
return false
end
However, when following logic is used, local function execute_command(cmd_info, timeout, buffer)
timeout = timeout and timeout or 5000
buffer = buffer and buffer or 0
return jdtls().request_sync("workspace/executeCommand", cmd_info, timeout, buffer)
end function neotest.Adapter.is_test_file(file_path)
vim.print("is test file check: " .. file_path)
local response = execute_command({
command = "java.project.isTestFile",
arguments = { vim.uri_from_fname(file_path) },
})
if response.err then
error(response.err.message)
end
vim.print(response.result)
return response.result
end Output looks as follows. It's defiantly blocking and value is being returned but filter_dir bin/test/com/example/demo/demo
filter_dir bin/main/com/example/demo/demo
filter_dir src/test/java/com/example/demo/demo
filter_dir src/main/java/com/example/demo/demo
is test file check: /home/s1n7ax/Workspace/demo/gradlew
is test file check: /home/s1n7ax/Workspace/demo/src/test/java/com/example/demo/DemoApplicationTests.java
true
is test file check: /home/s1n7ax/Workspace/demo/src/test/java/com/example/demo/DemoApplicationTests.java
true
is test file check: /home/s1n7ax/Workspace/demo/src/test/java/com/example/demo/DemoApplicationTests.java
true |
Beta Was this translation helpful? Give feedback.
-
THIS IS THE implementation with my co-routine library. NOT the above example. I pushed implementation here. This wont work without https://github.com/nvim-java-core dependency. I have this to call jdtls and get the is test status from server. I have made it a callback style so I can wrap it using your library Here is how I've wrapped and used it Here is the output. As you can see from the logs, request is sent to get is test file check and response was received successfully.
|
Beta Was this translation helpful? Give feedback.
-
I'm working on https://github.com/nvim-java/nvim-java. So far, I have created only two APIs to run tests.
run_current_test_class
debug_current_test_class
Both these are ran using
nvim-dap
& test discovery is done by communicating tojdtls
language server.However, I would like to have an adapter so I can get all the neotest features come with it. However, I don't really understand how to do asynchronous stuff from the given adapter interface. I can see that you have the
@async
annotation in each method, however, there is no callback function passed to any APIs.So I would like to get help on
For instance, there is a language sever command for checking if the given file is a test or not in jdtls. It's
java.project.isTestFile
. However calling this has to be done asynchronously. So my adapter function should look like this with a callback function. But looking at the interface there is not? So how should this be handled?build_spec
return? Is it a dap laucher config?Beta Was this translation helpful? Give feedback.
All reactions