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

Fix bunch of issues with reference related tests#176

Merged
MikhailArkhipov merged 16 commits intomicrosoft:masterfrom
MikhailArkhipov:refs2
Oct 3, 2018
Merged

Fix bunch of issues with reference related tests#176
MikhailArkhipov merged 16 commits intomicrosoft:masterfrom
MikhailArkhipov:refs2

Conversation

@MikhailArkhipov
Copy link
Copy Markdown

  • Properly resolve function arguments vs global variables
  • Treat reassignments as reference, not as definition
  • Improve CancelAnalysis test (took forever with my 6500 files library)
  • Fix some dispose issues (queue was not always empty after dispose/cancel)
  • Dispose of stuff in order
  • Update signature test to new behavior
  • Update reference tests to new behavior

Comment thread src/Analysis/Engine/Impl/ModuleAnalysis.cs
Comment thread src/Analysis/Engine/Impl/ModuleAnalysis.cs
Comment thread src/LanguageServer/Impl/Implementation/Server.cs
LogMessage(MessageType.Error, t.Exception.Message);
return;
}
_shutdownCts.Token.ThrowIfCancellationRequested();
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.

It's enough to call it either here or in OnDocumentChangeProcessingCompleteAsync.

}

if (doc is IAnalyzable analyzable && enqueueForAnalysis) {
_shutdownCts.Token.ThrowIfCancellationRequested();
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.

We can check this unconditionally.


private async Task OnDocumentChangeProcessingCompleteAsync(IDocument doc, VersionCookie vc, bool enqueueForAnalysis, AnalysisPriority priority, IDisposable disposeWhenEnqueued) {
try {
_shutdownCts.Token.ThrowIfCancellationRequested();
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.

Then we don't need to call _disposableBag.ThrowIfDisposed(); here (and catch it at the end).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Actually OnDocumentChangeProcessingCompleteAsync is not even async anymore

foreach (var defScope in scope.EnumerateTowardsGlobal
.Where(s => s.ContainsVariable(name.Name) && (s == scope || s.VisibleToChildren || IsFirstLineOfFunction(scope, s, location)))) {
var scopeVariables = GetVariablesInScope(name, defScope).Distinct();
foreach (var s in scope.EnumerateTowardsGlobal) {
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.

Can we extract the body of if (expr is NameExpression name) { into separate method (something like GetVariablesFromNameExpression)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sure

@AlexanderSher
Copy link
Copy Markdown
Contributor

Do you want the last change to be part of the same review?

@MikhailArkhipov
Copy link
Copy Markdown
Author

MikhailArkhipov commented Oct 1, 2018

Yes. It actually fixes FindReferences test and makes it work as PyCharm does. Also adds test for class local variables.

@AlexanderSher
Copy link
Copy Markdown
Contributor

Ok, I'll take a look tomorrow morning.

";
await server.SendDidOpenTextDocument(uri, text);

var references = await server.SendFindReferences(uri, 3, 15);
references.Should().OnlyHaveReferences(
var expected = new (Uri documentUri, (int, int, int, int), ReferenceKind?) [] {
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.

You don't need documentUri here: var expected = new (Uri, (int, int, int, int), ReferenceKind?) [] {

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.

Or maybe we should just add an overload for OnlyHaveReferences with (Uri documentUri, (int, int, int, int), ReferenceKind) tuple.

Comment thread src/Analysis/Engine/Test/AnalysisTest.cs
@@ -5341,7 +5365,7 @@ class test():

var files = Directory.GetFiles(Path.Combine(configuration.PrefixPath, "Lib"), "*.py", SearchOption.AllDirectories);
Trace.TraceInformation($"Files count: {files}");
var contentTasks = files.Select(f => File.ReadAllTextAsync(f)).ToArray();
var contentTasks = files.Take(Math.Min(50, files.Length)).Select(f => File.ReadAllTextAsync(f)).ToArray();
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.

files.Take(50) is enough.
From sources:

    private static IEnumerable<TSource> TakeIterator<TSource>(IEnumerable<TSource> source, int count)
    {
      if (count > 0)
      {
        foreach (TSource source1 in source)
        {
          yield return source1;
          if (--count == 0)
            break;
        }
      }
    }

await server.SendDidOpenTextDocument(new Uri(files[i]), contentTasks[i].Result);
}

server.AnalysisQueue.Count.Should().NotBe(0);
} finally {
if (server != null) {
analysisCompleteTask = EventTaskSources.AnalysisQueue.AnalysisComplete.Create(server.AnalysisQueue, new CancellationTokenSource(10000).Token);
serverDisposeTask = Task.WhenAny(Task.Run(() => server.Dispose()), Task.Delay(1000));
serverDisposeTask = Task.WhenAny(Task.Run(() => server.Dispose()), Task.Delay(5000));
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.

Do we really need 5 seconds to dispose?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Not really.

class MyBaseClass1(object):
def base_method(self): pass
/*
[TestMethod, Priority(0)]
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.

The whole block of commented tests is offset, please undo it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

OK. Prob formatter.

@MikhailArkhipov MikhailArkhipov merged commit 6a20692 into microsoft:master Oct 3, 2018
@MikhailArkhipov MikhailArkhipov deleted the refs2 branch October 3, 2018 17:08
jakebailey pushed a commit to jakebailey/python-language-server that referenced this pull request Nov 1, 2019
Fix bunch of issues with reference related tests
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants