Skip to content

fix: guard against nil in root_dir when all targets are filtered out#318

Open
Rival wants to merge 1 commit into
seblyng:mainfrom
Rival:fix/root-dir-nil-crash
Open

fix: guard against nil in root_dir when all targets are filtered out#318
Rival wants to merge 1 commit into
seblyng:mainfrom
Rival:fix/root-dir-nil-crash

Conversation

@Rival

@Rival Rival commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Summary

In sln/utils.lua, root_dir calls filter_targets and then falls through to:

return vim.fs.dirname(filtered_targets[1])
    or selected_solution and vim.fs.dirname(selected_solution)
    or csproj and vim.fs.dirname(csproj)

If ignore_target rejects every found solution, filtered_targets is empty and filtered_targets[1] is nil. Passing nil to vim.fs.dirname raises a bad-argument error, crashing LSP startup.

Fix: add a nil guard so the fallback chain works correctly:

return filtered_targets[1] and vim.fs.dirname(filtered_targets[1])
    or selected_solution and vim.fs.dirname(selected_solution)
    or csproj and vim.fs.dirname(csproj)

Reproducer

-- roslyn.nvim config
ignore_target = function(_) return true end  -- reject all solutions

Open a .cs file — without this fix, LSP startup crashes silently.

🤖 Generated with Claude Code

When every solution found by `find_solutions` is rejected by
`ignore_target`, `filtered_targets` is empty and `filtered_targets[1]`
is nil. Passing nil directly to `vim.fs.dirname` raises a bad-argument
error and crashes LSP startup silently.

Add a nil guard so the fallback chain continues to
`roslyn_nvim_selected_solution` and then `csproj`:

  return filtered_targets[1] and vim.fs.dirname(filtered_targets[1])
      or selected_solution and vim.fs.dirname(selected_solution)
      or csproj and vim.fs.dirname(csproj)

Reproducer: set `ignore_target` to reject all solutions in a project
that has no selected solution and no csproj fallback.
@seblyng

seblyng commented Feb 22, 2026

Copy link
Copy Markdown
Owner

Need a test for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants