Skip to content

[index] ServerImpl.textDocumentReferencesOp: empty pcSymbol produces garbage targetId #70

Description

@rochala

Severity: low — noisy logs and a degenerate map key, but no functional regression today.

Symptom

ServerImpl.textDocumentReferencesOp does:

defResult <- IO.interruptible(pc.definition(offsetParams))
pcSymbol   = defResult.symbol()
targetId   = index.SymbolId.fromSemanticDb(pcSymbol)

When the cursor is on whitespace, a keyword, or an unresolved identifier, defResult.symbol() returns "". fromSemanticDb("") returns SymbolId(Nil, Nil, "", None) — a term id with an empty name. The lookup runs unguarded and the log line says

References for : 0 refs

…which is misleading. Worse, if anything else in the index also produces an empty-name id (the TastyIndexer NonFatal fallback at line 348 returns <unknown> — close but not empty; issue ##8 — but other code paths could leak empty-name ids in the future), this lookup would silently match them.

Fix

Guard at the call site:

defResult <- IO.interruptible(pc.definition(offsetParams))
pcSymbol   = defResult.symbol()
result    <- if pcSymbol.isEmpty then IO.pure(lsp.TextDocumentReferencesOpOutput(None))
             else {
               val targetId = index.SymbolId.fromSemanticDb(pcSymbol)
               symbolIndex.getReferences(targetId).map(...)
             }

Acceptance criteria

  • Unit test: pcSymbol = "" returns TextDocumentReferencesOpOutput(None) without an index lookup

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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