Skip to content

Fix diagnostics not triggered for files open before extension activation#356

Merged
garrytrinder merged 3 commits intomainfrom
copilot/fix-diagnostics-activation-issue
Mar 3, 2026
Merged

Fix diagnostics not triggered for files open before extension activation#356
garrytrinder merged 3 commits intomainfrom
copilot/fix-diagnostics-activation-issue

Conversation

Copy link
Contributor

Copilot AI commented Mar 3, 2026

Documents already open when the extension activates never receive diagnostics because onDidOpenTextDocument only fires for documents opened after listener registration.

After registering event listeners in registerDocumentListeners(), iterate over vscode.workspace.textDocuments and run diagnostics on any Dev Proxy files already open. Also set isDevProxyConfigFile context from the active editor so commands/menus are immediately available.

for (const document of vscode.workspace.textDocuments) {
    if (document.uri.scheme !== 'file') { continue; }
    if (isConfigFile(document)) {
        updateConfigFileDiagnostics(context, document, collection);
    } else if (isProxyFile(document)) {
        updateFileDiagnostics(context, document, collection);
    }
}

const activeEditor = vscode.window.activeTextEditor;
if (activeEditor && activeEditor.document.uri.scheme === 'file') {
    vscode.commands.executeCommand('setContext', 'isDevProxyConfigFile', isConfigFile(activeEditor.document));
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Bug: Diagnostics not triggered for files open before extension activation</issue_title>
<issue_description>## Bug

When a Dev Proxy configuration file is already open in the active editor before the extension activates, no diagnostic checks are triggered. The user must close and re-open the file to see diagnostics (schema validation, plugin checks, etc.).

Expected behaviour

On extension activation, any Dev Proxy files already open in the editor should have diagnostics run immediately, just as if the file had been opened after activation.

Steps to reproduce

  1. Open a folder containing a devproxyrc.json in VS Code
  2. Open devproxyrc.json in the editor
  3. Observe the Output panel (Dev Proxy Toolkit channel) - no diagnostic log entries appear
  4. Close and re-open the same file - diagnostics now run and log entries appear

Root cause

In src/documents.ts, document listeners are registered via onDidOpenTextDocument and onDidChangeTextDocument. These only fire for documents opened/changed after the listeners are registered during activate(). Files that are already open when the extension activates do not trigger these events.

Suggested fix

After registering the document listeners in src/documents.ts, iterate over already-open documents and run diagnostics for any that are Dev Proxy files. This should happen at the end of registerDocumentListeners() or called from activate() in src/extension.ts after registerDocumentListeners().

The relevant documents are available via vscode.workspace.textDocuments which returns all currently open text documents, and vscode.window.visibleTextEditors which returns editors currently visible.

Implementation approach

After registering listeners, process already-open documents:

for (const document of vscode.workspace.textDocuments) {
    if (document.uri.scheme !== "file") continue;
    if (isConfigFile(document)) {
        updateConfigFileDiagnostics(context, document, collection);
    } else if (isProxyFile(document)) {
        updateFileDiagnostics(context, document, collection);
    }
}

Also set isDevProxyConfigFile context if the active editor contains a config file:

const activeEditor = vscode.window.activeTextEditor;
if (activeEditor && activeEditor.document.uri.scheme === "file") {
    vscode.commands.executeCommand("setContext", "isDevProxyConfigFile", isConfigFile(activeEditor.document));
}

Key files

  • src/documents.ts - document listeners (main change)
  • src/extension.ts - activation flow (may need to coordinate)
  • src/diagnostics.ts - updateConfigFileDiagnostics() and updateFileDiagnostics()
  • src/utils/config-detection.ts - isConfigFile() and isProxyFile()

Testing

  • Add a test that verifies diagnostics are produced for an already-open document when registerDocumentListeners is called
  • Existing tests in src/test/schema.test.ts and src/test/plugins.test.ts cover the diagnostic logic itself
  • Manual test: open folder with devproxyrc.json, confirm diagnostics appear without needing to close/reopen
    </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix diagnostics not triggered for already opened files Fix diagnostics not triggered for files open before extension activation Mar 3, 2026
Copilot AI and others added 3 commits March 3, 2026 11:24
…ostics

Co-authored-by: garrytrinder <11563347+garrytrinder@users.noreply.github.com>
… processing

Co-authored-by: garrytrinder <11563347+garrytrinder@users.noreply.github.com>
@garrytrinder garrytrinder force-pushed the copilot/fix-diagnostics-activation-issue branch from 6fb4bcf to 4be3249 Compare March 3, 2026 11:26
@garrytrinder garrytrinder marked this pull request as ready for review March 3, 2026 11:30
@garrytrinder garrytrinder merged commit 4f2c62a into main Mar 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Diagnostics not triggered for files open before extension activation

2 participants