Skip to content

Fix diagnostics fallback#79

Open
wtfbbqhax wants to merge 3 commits intobug-ops:mainfrom
wtfbbqhax:fix_diagnostics_fallback
Open

Fix diagnostics fallback#79
wtfbbqhax wants to merge 3 commits intobug-ops:mainfrom
wtfbbqhax:fix_diagnostics_fallback

Conversation

@wtfbbqhax
Copy link
Copy Markdown

Description

Fix get_diagnostics for language servers that do not support pull diagnostics, such
as clangd in this C++ setup.

The change makes diagnostics retrieval capability-aware: when a server supports
textDocument/diagnostic, mcpls uses it; otherwise it falls back to cached
textDocument/publishDiagnostics results instead of returning -32601 method not found.
It also wires LSP notification forwarding into normal server startup so published
diagnostics, logs, and messages are actually captured during serve().

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to
    change)
  • Documentation update
  • Refactoring (no functional changes)

Related Issues

Fixes #(issue number)

Checklist

  • I have read the CONTRIBUTING (CONTRIBUTING.md) guide
  • My code follows the project's coding style
  • I have added tests that prove my fix/feature works
  • All new and existing tests pass
  • I have updated the documentation accordingly
  • I have updated the CHANGELOG.md (for user-facing changes)

Additional Notes

  • get_diagnostics now:
    • uses pull diagnostics when the selected server advertises support
    • falls back to cached published diagnostics when pull diagnostics are
      unsupported
    • also falls back on LSP server error: -32601 - method not found
  • Normal startup now forwards LSP notifications into the translator cache, so
    publishDiagnostics, window/logMessage, and window/showMessage are available during
    a real session.
  • Added focused tests for:
    • notification ingestion into the translator cache
    • fallback to cached diagnostics when pull diagnostics are unsupported
  • Verified with cargo test -p mcpls-core --lib (317 passed, 0 failed).

Problem

While using `mcpls` in a C++ project I noticed that it always return
the following error when calling get references from a '.h' header file:

    Error: tool call error: tool call failed for `mcpls/get_references`
    Caused by:
        tools/call failed: Mcp error: -32603: no LSP server configured for language: c

After reviewing the documentation and creating an mcpls.toml with the
following, it continued to not work

    [[lsp_servers]]
    language_id = "cpp"
    command = "clangd"
    args = ["--background-index", "--clang-tidy"]
    file_patterns = ["**/*.cpp", "**/*.cc", "**/*.cxx", "**/*.hpp", "**/*.c", "**/*.h"]

    # and/or with
    [[lsp_servers]]
    language_id = "c"
    command = "clangd"
    args = ["--background-index", "--clang-tidy"]
    file_patterns = ["**/*.c", "**/*.h"]

With the above changing resulting in the language detection for matching
file patterns to "plaintext"

    Error: tool call error: tool call failed for `mcpls/get_references`
    Caused by:
        tools/call failed: Mcp error: -32603: no LSP server configured for language: plaintext

What changed

- serve() now initializes the translator with an effective extension map
  built from both workspace mappings and LSP server file patterns:
    - crates/mcpls-core/src/lib.rs:114:114
- Added ServerConfig::build_effective_extension_map() to overlay
  extensions inferred from file_patterns:
    - crates/mcpls-core/src/config/mod.rs:287:287
- Added a small parser for simple glob extensions (e.g. **/*.h, *.c):
    - crates/mcpls-core/src/config/mod.rs:123:123

Tests added

- Pattern-derived mapping overrides default extension mapping (.c/.h -> cpp):
    - crates/mcpls-core/src/config/mod.rs:700:700
- Complex non-simple patterns are ignored safely:
    - crates/mcpls-core/src/config/mod.rs:721:721

Verification

- New tests passed.
- Full mcpls-core unit/integration tests passed.
- Existing unrelated doctest failure remains in lsp/types.rs (pre-existing visibility issue).

Fix was implemented by Codex
Add direct unit coverage for extract_extension_from_pattern edge cases, including empty input, no-dot patterns, dotfiles, and multi-dot filenames.

Tighten the parser to reject dotfile basenames so hidden files like .gitignore do not get treated as language extensions.

Update the translator initialization test to assert against build_effective_extension_map(), which matches the runtime code path introduced by the earlier file_patterns fix.

Document the resulting C/C++ language detection behavior change in CHANGELOG.md.
Make get_diagnostics capability-aware so servers without pull diagnostics support fall back to cached published diagnostics instead of surfacing -32601.

Wire LSP notification forwarding into normal server startup so publishDiagnostics, log messages, and showMessage notifications populate the translator cache during serve().

Add focused tests for notification ingestion and cached diagnostics fallback, and clarify the MCP tool description to reflect the new behavior.
@github-actions github-actions bot added documentation Improvements or additions to documentation rust Rust code changes mcpls-core mcpls-core crate changes labels Apr 1, 2026
@wtfbbqhax
Copy link
Copy Markdown
Author

Codex called this a "fix" though i think it might be more of new functionality.

The basic utility is that using Clangd, get_diagnostics calls an unsupported method; this change redirects it to the get_cached_diagnostics silently.

In my workflow and perhaps a better solution is to direct codex/claude to only use the get_cached_diagnostics in the first place; at the moment I implement a Usage reference for your mcpls in my AGENTS.md files over multiple projects (Rust, C, C++ and Go) and the agents tend to encounter language specific failures from time to time.

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

Labels

documentation Improvements or additions to documentation mcpls-core mcpls-core crate changes rust Rust code changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant