Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f7d4d1e
ci: add lua-language-server --check to static analysis
rcasia May 20, 2026
c877744
feat: add type definitions for neotest and vim.lsp types
rcasia May 20, 2026
ba1c454
fix: resolve param-type-mismatch and missing-return-value in junit_re…
rcasia May 20, 2026
1346b10
fix: remove redundant param docs and fix stdpath_data type
rcasia May 20, 2026
ba91bb1
fix: move param docs outside memoized function
rcasia May 20, 2026
0280016
fix: add missing _level and _filename fields to Logger class
rcasia May 20, 2026
48c230c
fix: remove redundant type annotation in Installer
rcasia May 20, 2026
617d1d8
fix: add get_supported_versions to ConfigOpts class
rcasia May 20, 2026
44f41d1
fix: define neotest-java.Compilers type for compiler module
rcasia May 20, 2026
9907e92
ci: add jit and _G globals to .luarc.json
rcasia May 20, 2026
060f157
fix: update vim.lsp.Client.request signature to match actual API
rcasia May 20, 2026
c410548
fix: add neotest-java.ClientProviderDeps class for deps typing
rcasia May 20, 2026
110558e
fix: add missing return in ui.select callback
rcasia May 20, 2026
76d1a15
fix: remove void return types and inline get_supported_versions
rcasia May 20, 2026
aef4d18
fix: revert table.unpack to unpack and suppress deprecated warning
rcasia May 20, 2026
ab28649
fix: suppress remaining lsp type warnings with diagnostics.disable
rcasia May 20, 2026
565bc19
fix: resolve undefined-doc-param and undefined-doc-name in classpath_…
rcasia May 20, 2026
f0ae1fd
fix: suppress deprecated warning in minimal_init.lua
rcasia May 20, 2026
1a87ae4
fix: revert position.ref() to position.id in junit_command_builder.lua
rcasia May 20, 2026
b71c1e4
fix: add ref field to neotest.Position type definition
rcasia May 20, 2026
2814afd
Merge branch 'main' into fix/lua-language-server-warnings
rcasia May 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .luarc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
"it",
"assert",
"before_each",
"after_each"
]
"after_each",
"jit",
"_G",
"_NEOTEST_IS_CHILD",
"unpack"
],
"diagnostics.neededFileStatus": {
"undefined-field": "none",
"deprecated": "none"
}
}
2 changes: 2 additions & 0 deletions lua/neotest-java/command/binaries.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local nio = require("nio")
--- @field java fun(cwd: neotest-java.Path): neotest-java.Path
--- @field javap fun(cwd: neotest-java.Path): neotest-java.Path

---@diagnostic disable: undefined-doc-name
--- @class neotest-java.BinariesDeps
--- @field client_provider fun(cwd: neotest-java.Path): vim.lsp.Client
--- @field is_windows? boolean
Expand Down Expand Up @@ -43,6 +44,7 @@ local Binaries = function(deps)
}
local result_future = nio.control.future()
schedule(function()
---@diagnostic disable-next-line: undefined-field
client:request("workspace/executeCommand", cmd, function(err, res)
assert(not err, "Error while getting Java home from lsp server: " .. vim.inspect(err))
assert(not res.err, "Error while getting Java home from lsp server: " .. vim.inspect(res.err))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ local nio = require("nio")
--- @field projectRoot string

--- @class neotest-java.ClasspathProviderDeps
---@diagnostic disable-next-line: undefined-doc-name
--- @field client_provider fun(cwd: neotest-java.Path): vim.lsp.Client
--- @field schedule? fun(fn: fun()) Defaults to vim.schedule. Inject a synchronous pass-through in tests.

--- @param deps neotest-java.ClasspathProviderDeps
--- @return neotest-java.ClasspathProvider

local function ClasspathProvider(deps)
local schedule = deps.schedule or vim.schedule
return {
Expand All @@ -23,6 +24,7 @@ local function ClasspathProvider(deps)
local base_dir_uri = vim.uri_from_fname(base_dir:to_string())
local client = deps.client_provider(base_dir)

---@diagnostic disable-next-line: undefined-field
local bufnr = vim.tbl_keys(client.attached_buffers)[1]
local runtime = nio.control.future()
local test = nio.control.future()
Expand All @@ -32,6 +34,7 @@ local function ClasspathProvider(deps)
-- called internally by client:request, is safe to invoke. Mirrors
-- the fix applied to command/binaries.lua in 7cdd189.
schedule(function()
---@diagnostic disable-next-line: undefined-field
client:request("workspace/executeCommand", {
command = "java.project.getClasspaths",
arguments = { base_dir_uri, vim.json.encode({ scope = "runtime" }) },
Expand All @@ -43,6 +46,7 @@ local function ClasspathProvider(deps)
end
end, bufnr)

---@diagnostic disable-next-line: undefined-field
client:request("workspace/executeCommand", {
command = "java.project.getClasspaths",
arguments = { base_dir_uri, vim.json.encode({ scope = "test" }) },
Expand Down
14 changes: 13 additions & 1 deletion lua/neotest-java/core/spec_builder/compiler/client_provider.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
local Path = require("neotest-java.model.path")

--- @param deps { get_clients: fun(opts: table): vim.lsp.Client[], globpath: fun(dir: string, pattern: string, nosuf: boolean, list: boolean): string[], bufadd: fun(path: string): number, bufload: fun(path: string), sleep: fun(ms: number), hrtime: fun(): number }
--- @class neotest-java.ClientProviderDeps
---@diagnostic disable-next-line: undefined-doc-name
--- @field get_clients fun(opts: table): vim.lsp.Client[]
--- @field globpath fun(dir: string, pattern: string, nosuf: boolean, list: boolean): string[]
--- @field bufadd fun(path: string): number
--- @field bufload fun(path: string)
--- @field sleep fun(ms: number)
--- @field hrtime fun(): number

--- @param deps neotest-java.ClientProviderDeps
---@diagnostic disable-next-line: undefined-doc-name
--- @return fun(cwd: neotest-java.Path): vim.lsp.Client
local function ClientProvider(deps)
local client
Expand Down Expand Up @@ -41,6 +51,7 @@ local function ClientProvider(deps)
end

--- @param cwd neotest-java.Path
---@diagnostic disable-next-line: undefined-doc-name
--- @return vim.lsp.Client
return function(cwd)
if client and client.initialized then
Expand All @@ -56,6 +67,7 @@ local function ClientProvider(deps)
assert(
wait(10000, function()
client = deps.get_clients({ name = "jdtls", bufnr = bufnr })[1]
---@diagnostic disable-next-line: undefined-field
return not not client and not not client.initialized
end, 1000),
"jdtls client not started in time"
Expand Down
7 changes: 6 additions & 1 deletion lua/neotest-java/core/spec_builder/compiler/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ local client_provider = ClientProvider({
end,
})

---@type table<string, NeotestJavaCompiler>
---@class neotest-java.Compilers
---@field lsp NeotestJavaCompiler
---@diagnostic disable-next-line: undefined-doc-name
---@field client_provider fun(cwd: neotest-java.Path): vim.lsp.Client

---@type neotest-java.Compilers
local compilers = {
lsp = LspCompiler({ client_provider = client_provider }),
client_provider = client_provider,
Expand Down
2 changes: 2 additions & 0 deletions lua/neotest-java/core/spec_builder/compiler/lsp_compiler.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local logger = require("neotest-java.logger")

--- @diagnostic disable-next-line: undefined-doc-name
--- @param deps { client_provider: fun(cwd: neotest-java.Path): vim.lsp.Client }
--- @return NeotestJavaCompiler
local function LspCompiler(deps)
Expand All @@ -10,6 +11,7 @@ local function LspCompiler(deps)
logger.debug(("compilation in %s mode"):format(args.compile_mode))

vim.schedule(function()
--- @diagnostic disable-next-line: undefined-field
client:request(
"java/buildWorkspace",
{ forceRebuild = args.compile_mode == "full" },
Expand Down
5 changes: 2 additions & 3 deletions lua/neotest-java/default_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ end
---@field default_junit_jar_version neotest-java.JunitVersion
---@field test_classname_patterns string[] | nil
---@field disable_update_notifications boolean | nil
---@field get_supported_versions fun(): table[]

---@type neotest-java.ConfigOpts
local default_config = {
Expand All @@ -51,9 +52,7 @@ local default_config = {
"^.*IT$",
"^.*Spec$",
},
get_supported_versions = get_supported_versions,
}

-- Export getter function for supported versions
default_config.get_supported_versions = get_supported_versions

return default_config
1 change: 1 addition & 0 deletions lua/neotest-java/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ local function NeotestJavaAdapter(config, deps)
prompt = msg,
}, function(choice)
cb(choice)
return nil
end)
end,
notify = lib.notify,
Expand Down
9 changes: 4 additions & 5 deletions lua/neotest-java/install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ local version_detector = JunitVersionDetector({
---@field exists fun(filepath: string): boolean
---@field checksum fun(file_path: neotest-java.Path): string
---@field download fun(url: string, output: string): { code: number, stderr: string }
---@field delete_file fun(filepath: string): void
---@field ask_user_consent fun(message: string, choices: string[], callback: fun(choice: string | nil)): void
---@field notify fun(message: string, level?: string): void
---@field delete_file fun(filepath: string)
---@field ask_user_consent fun(message: string, choices: string[], callback: fun(choice: string | nil))
---@field notify fun(message: string, level?: string)
---@field detect_existing_version fun(): neotest-java.JunitVersion | nil, neotest-java.Path | nil

---@class neotest-java.Installer
---@field install fun(config: neotest-java.ConfigOpts): void
---@field install fun(config: neotest-java.ConfigOpts)

--- @param deps neotest-java.InstallDeps
--- @return neotest-java.Installer
local Installer = function(deps)
--- @type neotest-java.InstallDeps
local exists_fn = deps.exists
local checksum_fn = deps.checksum
local delete_file_fn = deps.delete_file
Expand Down
3 changes: 3 additions & 0 deletions lua/neotest-java/logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ local loggers = {}
local log_date_format = "%FT%H:%M:%SZ%z"

---@class neotest.Logger
---@field _level number
---@field _filename string
---@field trace function
---@field debug function
---@field info function
Expand Down Expand Up @@ -73,6 +75,7 @@ function Logger.new(filename, opts)
local parts = {
table.concat({ level, "|", os.date(log_date_format), "|", fileinfo, "|" }, " "),
}
---@diagnostic disable-next-line: undefined-field
if _G._NEOTEST_IS_CHILD then
table.insert(parts, "CHILD |")
end
Expand Down
5 changes: 2 additions & 3 deletions lua/neotest-java/model/junit_result.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ local function create_file_with_content(data, tempname)
if #data == 0 then
return nil
end
data = vim.iter(vim.tbl_values(data)):flatten(math.huge):totable()
data = table.concat(data, LINE_SEPARATOR)
data = table.concat(vim.iter(vim.tbl_values(data)):flatten(math.huge):totable(), LINE_SEPARATOR)
end

-- Generate a unique temporary file name
Expand Down Expand Up @@ -115,7 +114,7 @@ function JunitResult:status()
}
return FAILED, { fail }
end
return PASSED
return PASSED, {}
end

---@param with_name_prefix? boolean
Expand Down
57 changes: 57 additions & 0 deletions lua/neotest-java/types.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
-- Type definitions for external libraries used by neotest-java
-- This file is not loaded at runtime, only used by lua-language-server for type checking

---@class neotest.Position
---@field id string
---@field name string
---@field type "test" | "namespace" | "dir" | "file"
---@field path string
---@field range integer[]
---@field ref fun(): string

---@class neotest.Tree
---@field data fun(): neotest.Position
---@field iter fun(): fun():integer[], neotest.Position
---@field to_list fun(): neotest.Position[]
---@field children fun(): neotest.Tree[]
---@field root fun(): neotest.Tree

---@class neotest.Error
---@field message string
---@field line integer?

---@class neotest.Result
---@field status neotest.ResultStatus
---@field output string?
---@field short string?
---@field errors neotest.Error[]?

---@alias neotest.ResultStatus "passed" | "failed" | "skipped"

---@class neotest.RunArgs
---@field tree neotest.Tree
---@field strategy string?

---@class neotest.RunSpec
---@field command string|string[]
---@field env table<string, string>?
---@field cwd string?
---@field context table?
---@field strategy table?

---@class neotest.StrategyResult
---@field code integer
---@field output string

---@class neotest.Adapter
---@field name string
---@field root fun(dir: string): string?
---@field is_test_file fun(filepath: string): boolean
---@field discover_positions fun(filepath: string): neotest.Tree
---@field build_spec fun(args: neotest.RunArgs): neotest.RunSpec|neotest.RunSpec[]|nil
---@field results fun(spec: neotest.RunSpec, strategy_result: neotest.StrategyResult): table<string, neotest.Result>
---@field filter_dir fun(name: string): boolean

---@class nio.control.Event
---@field wait fun()
---@field set fun()
5 changes: 1 addition & 4 deletions lua/neotest-java/util/junit_version_detector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ end
---@field exists fun(filepath: neotest-java.Path): boolean
---@field checksum fun(file_path: neotest-java.Path): string
---@field scan fun(dir: neotest-java.Path, opts: { search_patterns: string[] }): neotest-java.Path[]
---@field stdpath_data fun(): string
---@field stdpath_data fun(name: string): string

---@class neotest-java.JunitVersionDetector
---@field detect_existing_version fun(): neotest-java.JunitVersion | nil, neotest-java.Path | nil
Expand Down Expand Up @@ -104,9 +104,6 @@ local JunitVersionDetector = function(deps)
--- @return table[]
get_supported_versions = get_supported_versions,

--- @param file_path neotest-java.Path
--- @param file_reader? fun(path: string): string
--- @return string hash
_checksum = checksum, -- Exposed for testing
}
end
Expand Down
13 changes: 7 additions & 6 deletions lua/neotest-java/util/read_xml_tag.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ local memo = require("neotest.lib.func_util.memoize")
local file = require("neotest.lib.file")
local xml = require("neotest.lib.xml")

---@param filepath string
---@param selector string ex: project.build.sourceDirectory
---@return string | nil
local cache = {}
local read_xml_tag = memo(function(filepath, selector)
--- @param filepath string
--- @param selector string ex: project.build.sourceDirectory
--- @return string | nil
local function _read_xml_tag(filepath, selector)
local content = file.read(filepath)
local parsed = xml.parse(content)

Expand All @@ -22,6 +21,8 @@ local read_xml_tag = memo(function(filepath, selector)
end

return parsed
end, cache)
end

local read_xml_tag = memo(_read_xml_tag)

return read_xml_tag
1 change: 1 addition & 0 deletions scripts/minimal_init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- scripts/minimal_init.lua
-- Headless testing with mini.test, no user config loaded.
---@diagnostic disable: deprecated

local DEPENDENCIES_DIR = "./.dependencies"

Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/full_workflow_spec.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@diagnostic disable: undefined-field
-- E2E test: Full Neotest workflow with Java tests
-- This test verifies that neotest-java correctly executes tests and reports results

Expand Down Expand Up @@ -49,13 +50,15 @@ describe("E2E: neotest-java full workflow", function()

-- Verify we got results
assert.is_not_nil(results, "Should have test results")
---@diagnostic disable-next-line: param-type-mismatch
assert.is_true(next(results) ~= nil, "Results should not be empty")

-- Count pass/fail
local passed = 0
local failed = 0
local total = 0

---@diagnostic disable-next-line: param-type-mismatch
for test_id, result in pairs(results) do
if test_id:match("Test") then -- Only count actual tests, not file/namespace nodes
total = total + 1
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_async_helpers_spec.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local run_sync = require("tests.async_helpers").run_sync
---@diagnostic disable: undefined-field
local async = require("tests.async_helpers").async

describe("async_helpers.run_sync", function()
Expand Down
Loading
Loading