Skip to content

Commit b76b4f0

Browse files
Merge pull request microsoft#36 from AlexanderSher/master
Bug and test fixes
2 parents 1204f5d + 27843c4 commit b76b4f0

File tree

23 files changed

+148
-26
lines changed

23 files changed

+148
-26
lines changed

src/Analysis/Engine/Impl/Analyzer/DDG.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public void Analyze(Deque<AnalysisUnit> queue, CancellationToken cancel, Action<
7373
SetCurrentUnit(_unit);
7474
AnalyzedEntries.Add(_unit.ProjectEntry);
7575
_unit.Analyze(this, cancel);
76-
_unit.ProjectEntry.SetCompleteAnalysis();
7776
}
7877

7978
if (reportQueueSize != null) {

src/Analysis/Engine/Impl/Infrastructure/Extensions/TaskCompletionSourceExtensions.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919

2020
namespace Microsoft.PythonTools.Analysis.Infrastructure {
2121
internal static class TaskCompletionSourceExtensions {
22-
public static void TrySetResultOnThreadPool<T>(this TaskCompletionSource<T> taskCompletionSource, T result) {
23-
if (!taskCompletionSource.Task.IsCompleted) {
24-
ThreadPool.QueueUserWorkItem(new TrySetResultStateAction<T>(taskCompletionSource, result).Invoke);
25-
}
26-
}
27-
2822
public static CancellationTokenRegistration RegisterForCancellation<T>(this TaskCompletionSource<T> taskCompletionSource, CancellationToken cancellationToken)
2923
=> taskCompletionSource.RegisterForCancellation(-1, cancellationToken);
3024

src/Analysis/Engine/Impl/Infrastructure/PathUtils.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ public static FileStream OpenWithRetry(string file, FileMode mode, FileAccess ac
362362
return null;
363363
} catch (DirectoryNotFoundException) when (!create) {
364364
return null;
365+
} catch (UnauthorizedAccessException) {
366+
Thread.Sleep(10);
365367
} catch (IOException) {
366368
if (create) {
367369
var dir = Path.GetDirectoryName(file);

src/Analysis/Engine/Impl/Interpreter/Ast/AstScrapedPythonModule.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class AstScrapedPythonModule : IPythonModule
3939

4040
public AstScrapedPythonModule(string name, string filePath) {
4141
Name = name ?? throw new ArgumentNullException(nameof(name));
42+
ParseErrors = Enumerable.Empty<string>();
4243
_filePath = filePath;
4344
_members = new Dictionary<string, IMember>();
4445
_scraped = false;

src/Analysis/Engine/Impl/ProjectEntry.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,22 @@ public IPythonParse GetCurrentParse() {
152152
}
153153
}, cancellationToken);
154154

155-
return Task.WhenAny(timeoutTask, _analysisTcs.Task).Unwrap();
155+
return Task.WhenAny(timeoutTask, task).Unwrap();
156156
}
157157

158158
internal void SetCompleteAnalysis() {
159159
lock (this) {
160-
_analysisTcs.TrySetResultOnThreadPool(Analysis);
160+
_analysisTcs.TrySetResult(Analysis);
161161
}
162162
}
163163

164164
internal void ResetCompleteAnalysis() {
165+
TaskCompletionSource<ModuleAnalysis> analysisTcs;
165166
lock (this) {
166-
_analysisTcs = new TaskCompletionSource<ModuleAnalysis>();
167+
analysisTcs = _analysisTcs;
168+
_analysisTcs = new TaskCompletionSource<ModuleAnalysis>(TaskCreationOptions.RunContinuationsAsynchronously);
167169
}
170+
analysisTcs?.TrySetCanceled();
168171
}
169172

170173
public void SetCurrentParse(PythonAst tree, IAnalysisCookie cookie, bool notify = true) {

src/Analysis/Engine/Impl/PythonAnalyzer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ public void AnalyzeQueuedEntries(CancellationToken cancel) {
953953
var ddg = new DDG();
954954
ddg.Analyze(Queue, cancel, _reportQueueSize, _reportQueueInterval);
955955
foreach (var entry in ddg.AnalyzedEntries) {
956+
entry.SetCompleteAnalysis();
956957
entry.RaiseOnNewAnalysis();
957958
}
958959
}

src/Analysis/Engine/Test/AnalysisTest.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,21 +1489,14 @@ print abc
14891489
}
14901490
}
14911491

1492-
[TestMethod, Priority(0)]
1493-
public async Task LambdaInComprehension() {
1492+
[DataRow(PythonLanguageVersion.V27)]
1493+
[DataRow(PythonLanguageVersion.V31)]
1494+
[DataRow(PythonLanguageVersion.V33)]
1495+
[DataTestMethod, Priority(0)]
1496+
public async Task LambdaInComprehension(PythonLanguageVersion version) {
14941497
var text = "x = [(lambda a:[a**i for i in range(a+1)])(j) for j in range(5)]";
14951498

1496-
using (var server = await CreateServerAsync(PythonVersions.Required_Python27X)) {
1497-
var analysis = await server.OpenDefaultDocumentAndGetAnalysisAsync(text);
1498-
analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.List);
1499-
}
1500-
1501-
using (var server = await CreateServerAsync(PythonVersions.Required_Python31X)) {
1502-
var analysis = await server.OpenDefaultDocumentAndGetAnalysisAsync(text);
1503-
analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.List);
1504-
}
1505-
1506-
using (var server = await CreateServerAsync(PythonVersions.Required_Python33X)) {
1499+
using (var server = await CreateServerAsync(PythonVersions.GetRequiredCPythonConfiguration(version))) {
15071500
var analysis = await server.OpenDefaultDocumentAndGetAnalysisAsync(text);
15081501
analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.List);
15091502
}

src/Analysis/Engine/Test/PythonVersions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ public static class PythonVersions {
141141
Python27,
142142
Python27_x64).First();
143143

144+
public static InterpreterConfiguration GetRequiredCPythonConfiguration(PythonLanguageVersion version)
145+
=> GetCPythonVersion(version, InterpreterArchitecture.x86) ?? GetCPythonVersion(version, InterpreterArchitecture.x64) ?? NotInstalled(version.ToString());
146+
144147
private static IEnumerable<InterpreterConfiguration> GetVersions(params InterpreterConfiguration[] configurations) => configurations.Where(v => v != null);
145148

146149
private static InterpreterConfiguration GetCPythonVersion(PythonLanguageVersion version, InterpreterArchitecture arch) {

src/LanguageServer/Impl/LanguageServer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,12 +562,12 @@ private struct QueueItem {
562562
public bool IsAwaitable { get; }
563563

564564
public QueueItem(bool isAwaitable, CancellationToken cancellationToken) {
565-
_tcs = new TaskCompletionSource<IDisposable>();
565+
_tcs = new TaskCompletionSource<IDisposable>(TaskCreationOptions.RunContinuationsAsynchronously);
566566
IsAwaitable = isAwaitable;
567567
_tcs.RegisterForCancellation(cancellationToken).UnregisterOnCompletion(_tcs.Task);
568568
}
569569

570-
public void SetResult(IDisposable disposable) => _tcs.TrySetResultOnThreadPool(disposable);
570+
public void SetResult(IDisposable disposable) => _tcs.TrySetResult(disposable);
571571
}
572572

573573
private class PrioritizerDisposable : IDisposable {

src/UnitTests/Core/Impl/TestData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private static string CalculateTestDataRoot() {
4747
if (Directory.Exists(path)) {
4848
foreach (var landmark in new[] {
4949
"TestData",
50-
@"Python\Tests\TestData"
50+
@"src\UnitTests\TestData"
5151
}) {
5252
var candidate = PathUtils.GetAbsoluteDirectoryPath(path, landmark);
5353
if (Directory.Exists(candidate)) {

0 commit comments

Comments
 (0)