Skip to content

[feature] Support language injections in LSP diagnostics #2522

@simeonoff

Description

@simeonoff

⭐ Suggestion

The LSP currently doesn't report diagnostics for rules targeting injected languages. For example, given a config with language injections:

customLanguages:
  scss:
    libraryPath: ./lib/scss.so
    extensions: [scss]
    languageSymbol: tree_sitter_scss
  sassdoc:
    libraryPath: ./lib/sassdoc.so
    extensions: [sassdoc]
languageInjections:
  - hostLanguage: scss
    rule:
      pattern:
        context: '/// $CONTENT'
        selector: sassdoc_line
    injected: sassdoc

Rules targeting sassdoc are correctly matched by ast-grep scan, but the LSP returns empty diagnostics for the same files. The CLI handles this in filter_file_rule by calling get_injections() on the parsed tree and scanning each injected sub-tree separately, but the LSP's get_versioned_ast only parses the host language tree.

💻 Use Cases

I'm currently working around this in Neovim by running ast-grep scan --json=stream as an external linter via nvim-lint, but it would be great to have this work natively through the LSP so editors that don't support custom external linters (like Zed or VScode) can also benefit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions