Skip to content

fix: Implement analysis error investigation fixes#2

Open
moonolgerd wants to merge 2 commits intomainfrom
fix/analysis-investigation
Open

fix: Implement analysis error investigation fixes#2
moonolgerd wants to merge 2 commits intomainfrom
fix/analysis-investigation

Conversation

@moonolgerd
Copy link
Owner

Implements the fixes documented in analysis-error-investigation.md, addressing LanguageModelError propagation, empty cache issues, double semicolons, disposable leaks on config changes, and empty file guard checks.

Copilot AI review requested due to automatic review settings March 7, 2026 05:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR applies a set of robustness fixes to the Source Doc VS Code extension (CodeLens + Copilot explanations), focusing on error handling, edge cases, and lifecycle management.

Changes:

  • Improve Copilot LanguageModelError messaging and avoid caching/returning empty explanations.
  • Add guards for “nothing to explain” and empty documents (range creation).
  • Address minor cleanup issues (e.g., double semicolon) and attempt to fix CodeLens registration disposal on language config changes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/extension.ts Adjusts language re-registration disposal behavior and adds a no-op guard for explainFile when there are no explainable lines.
src/explanationProvider.ts Adds LanguageModelError code-specific messaging and rejects empty Copilot responses.
src/codeLensProvider.ts Guards file-level lens range creation for empty documents and fixes a stray double semicolon.

Comment on lines 49 to 54
if (e.affectsConfiguration('sourceDoc.languages')) {
languageRegistrations.forEach(d => d.dispose());
languageRegistrations = [];
registerCodeLensProviders(context, codeLensProvider, languageRegistrations);
languageRegistrations.forEach(d => context.subscriptions.push(d));
}
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The language re-registration logic is still leaking/duplicating CodeLens providers: the initial registerCodeLensProviders(context, codeLensProvider) call registers directly into context.subscriptions, but those initial registrations are never captured in languageRegistrations, so they are never disposed when sourceDoc.languages changes. This means removed languages can continue to have a provider registered, and new languages can end up with multiple registrations.

Consider tracking all language registrations in languageRegistrations (including the initial registration) and disposing that set on every languages change, rather than pushing new registrations into context.subscriptions each time.

Copilot uses AI. Check for mistakes.
Comment on lines 95 to +98
result = result.trim();
if (!result) {
throw new Error('Copilot returned an empty explanation. Please try again.');
}
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new if (!result) throw ... check will treat user cancellation as an error in some cases: if the cancellation token is triggered during streaming before any text is received, the loop breaks, result stays empty, and an error message is thrown/shown. Cancellation should typically short-circuit without surfacing a failure.

Consider explicitly checking token.isCancellationRequested after the streaming loop and throwing a cancellation-specific error (or returning early) so callers can ignore it, while still preventing empty explanations from being cached.

Copilot uses AI. Check for mistakes.
Comment on lines +81 to +87
throw new Error('Copilot access denied. Please check your GitHub Copilot subscription.');
case 'Blocked':
throw new Error('Copilot request was blocked. Please check your GitHub Copilot settings.');
case 'NotFound':
throw new Error('Copilot model not found. Please check your GitHub Copilot extension.');
case 'RequestFailed':
throw new Error('Copilot request failed. Please try again.');
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the specific LanguageModelError codes handled here, the thrown messages no longer include the underlying err.code. Elsewhere (and per the extension’s error-handling goals) the code is useful for debugging/support; consider including the code in these user-facing messages as well (e.g., "Copilot error (NoPermissions): …").

Suggested change
throw new Error('Copilot access denied. Please check your GitHub Copilot subscription.');
case 'Blocked':
throw new Error('Copilot request was blocked. Please check your GitHub Copilot settings.');
case 'NotFound':
throw new Error('Copilot model not found. Please check your GitHub Copilot extension.');
case 'RequestFailed':
throw new Error('Copilot request failed. Please try again.');
throw new Error(`Copilot error (${err.code}): access denied. Please check your GitHub Copilot subscription.`);
case 'Blocked':
throw new Error(`Copilot error (${err.code}): request was blocked. Please check your GitHub Copilot settings.`);
case 'NotFound':
throw new Error(`Copilot error (${err.code}): model not found. Please check your GitHub Copilot extension.`);
case 'RequestFailed':
throw new Error(`Copilot error (${err.code}): request failed. Please try again.`);

Copilot uses AI. Check for mistakes.
@moonolgerd
Copy link
Owner Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link

Copilot AI commented Mar 7, 2026

@moonolgerd I've opened a new pull request, #3, to work on those changes. Once the pull request is ready, I'll request review from you.

…uageModelError codes missing from messages (#3)

* Initial plan

* fix: address review comments - registration leak, cancellation, and error codes

Co-authored-by: moonolgerd <3743184+moonolgerd@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: moonolgerd <3743184+moonolgerd@users.noreply.github.com>
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.

3 participants