-
Notifications
You must be signed in to change notification settings - Fork 49
Description
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.