Problem
textDocument/definition returns empty results when called shortly after textDocument/didOpen.
Reproduction: Any LSP client that sends definition requests within ~200ms of opening a document will intermittently get empty results, even when symbols exist.
Root Cause
In server.ts, documents.onDidOpen calls validatePerlDocument() without awaiting it. Since validatePerlDocument spawns a Perl process (300-500ms+), the onDefinition handler often runs before navSymbols is populated, causing it to return empty.
Proposed Fix
In server.ts, add a fallback in onDefinition to parse the document on-demand if navSymbols is not yet populated.
1. Add import at the top of the file:
import { parseDocument } from "./parser";
2. Modify the onDefinition handler - add fallback before calling getDefinition:
// Parse on-demand if navSymbols hasn't been populated yet
if (!perlDoc) {
perlDoc = await parseDocument(document, ParseType.selfNavigation);
}
This uses the existing parseDocument function (which parses Perl syntax directly in Node.js) instead of waiting for the slow external Perl process to complete.
Happy to submit a PR if this approach looks good.
Thank you,
Yakir Gibraltar.
Problem
textDocument/definitionreturns empty results when called shortly aftertextDocument/didOpen.Reproduction: Any LSP client that sends definition requests within ~200ms of opening a document will intermittently get empty results, even when symbols exist.
Root Cause
In
server.ts,documents.onDidOpencallsvalidatePerlDocument()without awaiting it. SincevalidatePerlDocumentspawns a Perl process (300-500ms+), theonDefinitionhandler often runs beforenavSymbolsis populated, causing it to return empty.Proposed Fix
In
server.ts, add a fallback inonDefinitionto parse the document on-demand ifnavSymbolsis not yet populated.1. Add import at the top of the file:
2. Modify the
onDefinitionhandler - add fallback before callinggetDefinition:This uses the existing
parseDocumentfunction (which parses Perl syntax directly in Node.js) instead of waiting for the slow external Perl process to complete.Happy to submit a PR if this approach looks good.
Thank you,
Yakir Gibraltar.