Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 4d7e953

Browse files
Fix couple of bugs (#566)
* Handle enableUnresolvedImportWarning and enableUseBeforeDefWarning options in PLS * Fix nuspec folder * Fix PTVS issue #5026: Imported packages remain unresolved once a new environment is finished being created
1 parent e501c64 commit 4d7e953

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ private PathResolverSnapshot(PythonLanguageVersion pythonLanguageVersion, string
6969

7070
public IEnumerable<string> GetAllModuleNames() => GetModuleNames(_roots.Prepend(_nonRooted).Append(_builtins));
7171
public IEnumerable<string> GetInterpreterModuleNames() => GetModuleNames(_roots.Skip(_userRootsCount).Append(_builtins));
72+
public IEnumerable<string> GetRootPaths() => _roots.Select(r => r.Name);
7273

7374
private static IEnumerable<string> GetModuleNames(IEnumerable<Node> roots) => roots
7475
.SelectMany(r => r.TraverseBreadthFirst(n => n.IsModule ? Enumerable.Empty<Node>() : n.Children))

src/Analysis/Engine/Impl/PythonAnalyzer.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public partial class PythonAnalyzer : IPythonAnalyzer, IDisposable {
6868
public static async Task<PythonAnalyzer> CreateAsync(IPythonInterpreterFactory factory, CancellationToken token = default) {
6969
var analyzer = new PythonAnalyzer(factory);
7070
try {
71-
await analyzer.ReloadModulesAsync(token).ConfigureAwait(false);
71+
await analyzer.ReloadModulesAsync(false, token).ConfigureAwait(false);
7272
} catch(Exception) {
7373
analyzer.Dispose();
7474
throw;
@@ -140,7 +140,9 @@ private void ReloadModulePaths(in IEnumerable<string> rootPaths) {
140140
/// This method should be called on the analysis thread and is usually invoked
141141
/// when the interpreter signals that it's modules have changed.
142142
/// </summary>
143-
public async Task ReloadModulesAsync(CancellationToken token = default) {
143+
public Task ReloadModulesAsync(CancellationToken token = default) => ReloadModulesAsync(true, token);
144+
145+
private async Task ReloadModulesAsync(bool reScanRoots, CancellationToken token) {
144146
if (!_reloadLock.Wait(0)) {
145147
// If we don't lock immediately, wait for the current reload to
146148
// complete and then return.
@@ -156,6 +158,11 @@ public async Task ReloadModulesAsync(CancellationToken token = default) {
156158
InterpreterFactory.NotifyImportNamesChanged();
157159
// Now initialize the interpreter
158160
Interpreter.Initialize(this);
161+
// Rescan roots for modules if requested
162+
if (reScanRoots) {
163+
ReloadModulePaths(CurrentPathResolver.GetRootPaths());
164+
}
165+
159166
// Reload importable modules
160167
Modules.Reload();
161168
// Load known types from the selected interpreter
@@ -760,7 +767,7 @@ public void AnalyzeQueuedEntries(CancellationToken cancel) {
760767

761768
if (_builtinModule == null) {
762769
Debug.Fail("Used analyzer without reloading modules");
763-
ReloadModulesAsync(cancel).WaitAndUnwrapExceptions();
770+
ReloadModulesAsync(true, cancel).WaitAndUnwrapExceptions();
764771
}
765772

766773
var ddg = new DDG();

src/PTVS/Microsoft.PythonTools.Analyzer/Impl/python-language-server-ptvs.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<file src="Microsoft.PythonTools.Analyzer.exe" target="lib/vs16" />
2424
<file src="Microsoft.PythonTools.Analyzer.exe.config" target="lib/vs16" />
2525
<file src="Microsoft.PythonTools.Analyzer.pdb" target="lib/vs16" />
26-
<file src="Typeshed/**" target="lib/vs16/Typeshed" />
26+
<file src="Typeshed/**" target="lib/vs16" />
2727
<file src="PythonScraper.py" target="lib/vs16" />
2828
<file src="BuiltinScraper.py" target="lib/vs16" />
2929
<file src="ExtensionScraper.py" target="lib/vs16" />

0 commit comments

Comments
 (0)