Skip to content

Bschnurr/fix pylance project env update#8563

Merged
bschnurr merged 6 commits into
microsoft:mainfrom
bschnurr:bschnurr/fix-pylance-project-env-update
Jun 29, 2026
Merged

Bschnurr/fix pylance project env update#8563
bschnurr merged 6 commits into
microsoft:mainfrom
bschnurr:bschnurr/fix-pylance-project-env-update

Conversation

@bschnurr

Copy link
Copy Markdown
Member

PR Classification

Code cleanup and test robustness improvement.

PR Summary

This pull request removes deferred settings update logic in favor of immediate updates and improves test reliability for completion item detection.

  • PythonLanguageClient.cs: Removed the deferred settings change timer and related logic, now triggering immediate settings updates; simplified cleanup and removed unnecessary awaits.
  • PythonProjectNode.cs: Unsubscribes from CondaInterpreterDiscoveryCompleted during disposal.
  • IntellisenseTests.cs: Enhanced the test to robustly wait for the "executable" completion item and improved event handler cleanup.

bschnurr and others added 5 commits June 23, 2026 12:16
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Simplify settings update in PythonLanguageClient by removing the deferred timer and triggering updates immediately. Refactor interpreter change handling in PythonProjectNode for clarity and unsubscribe from Conda discovery events during cleanup. Enhance AutoComplete test in IntellisenseTests to reliably detect completion items and ensure proper event handler cleanup.
@bschnurr bschnurr requested a review from a team as a code owner June 25, 2026 18:16
} catch (ObjectDisposedException) {
}
TriggerWorkspaceUpdateConfig().DoNotWait();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📍 Python/Product/PythonTools/PythonTools/LanguageServerClient/PythonLanguageClient.cs:492
OnSettingsChanged now runs TriggerWorkspaceUpdateConfig() without the defensive try/catch that the deleted timer callback had. That callback explicitly caught NullReferenceException/ObjectDisposedException with the comment "Field was nulled or service disappeared during teardown" — meaning this failure was observed in practice. While TriggerWorkspaceUpdateConfig self-guards on _disposed || _rpc == null, that guard does not stop GetSettings() from dereferencing a disposed VS option/service mid-teardown, and the exception could now propagate into VS's options-change dispatch. Consider re-adding the defensive try/catch (NullReferenceException)/(ObjectDisposedException) around the call.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 1fa86e1 by restoring the defensive NullReferenceException/ObjectDisposedException handling around the immediate settings update.

}
};
session.ItemsUpdated += itemsUpdatedHandler;
completionTask.TrySetResult(session);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📍 Python/Tests/Core.UI/IntellisenseTests.cs:49
The handler only subscribes to session.ItemsUpdated and waits for a future event containing executable. If the completion set already contains executable when CompletionTriggered fires (fast/cached path) and no further ItemsUpdated is raised, executableTask never completes and Wait(60000) times out. The old synchronous GetComputedItems(...) could not miss already-present items. Subscribe-then-check: after subscribing, inspect the current computed items once and TrySetResult if executable is already present, closing the race in both directions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 1fa86e1 by subscribing to ItemsUpdated first and then checking GetComputedItems(...) immediately, so the test handles both already-present and later-updated completion items.

@rchiodo

rchiodo commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Overall the cleanup is sound. Two non-blocking items worth a look: defensive exception handling lost in OnSettingsChanged during teardown, and a potential race in the updated IntellisenseTests if 'executable' is already present when completion triggers.

@rchiodo rchiodo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved via Review Center.

@rchiodo

rchiodo commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Overall this cleanup looks good. Two robustness follow-ups worth a look: (1) the now-immediate settings update lost the defensive try/catch the old timer callback had for teardown, and (2) the new test only waits on ItemsUpdated and can miss the case where 'executable' is already present when completion triggers.

@rchiodo rchiodo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved via Review Center.

Restore defensive handling for settings updates during teardown and close the completion item race in the IntelliSense UI test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@rchiodo rchiodo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved via Review Center.

@bschnurr

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@bschnurr bschnurr merged commit 3afb9ef into microsoft:main Jun 29, 2026
8 checks passed
@sonarqubecloud

Copy link
Copy Markdown

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.

2 participants