Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8bca56b
Fix #668 (partial)
Mar 1, 2019
a731c2a
Merge branch 'master' of https://github.com/Microsoft/python-language…
Mar 1, 2019
069910b
Merge branch 'master' of https://github.com/Microsoft/python-language…
Mar 5, 2019
7ffc9db
Tests
Mar 5, 2019
6303c45
Revert "Tests"
Mar 5, 2019
945451c
Merge branch 'master' of https://github.com/Microsoft/python-language…
Mar 5, 2019
034e437
Merge branch 'master' of https://github.com/Microsoft/python-language…
Mar 5, 2019
f997d68
Merge branch 'master' of https://github.com/Microsoft/python-language…
Mar 6, 2019
0e4ff95
Merge branch 'master' of https://github.com/Microsoft/python-language…
Mar 11, 2019
878c8c5
Merge branch 'master' of https://github.com/Microsoft/python-language…
Mar 13, 2019
35e1033
Merge branch 'master' of https://github.com/Microsoft/python-language…
Mar 13, 2019
1073711
Merge branch 'master' of https://github.com/Microsoft/python-language…
Mar 14, 2019
86028da
Merge branch 'master' of https://github.com/Microsoft/python-language…
Mar 14, 2019
4d4bca7
Merge branch 'master' of https://github.com/Microsoft/python-language…
Mar 18, 2019
ac04f76
Merge branch 'master' of https://github.com/Microsoft/python-language…
Mar 18, 2019
bab03da
Merge branch 'master' of https://github.com/Microsoft/python-language…
Mar 20, 2019
85ec685
Merge branch 'master' of https://github.com/Microsoft/python-language…
Mar 27, 2019
be7466d
Merge branch 'master' of https://github.com/Microsoft/python-language…
Mar 28, 2019
01781c0
Exp
Mar 27, 2019
f544f8a
Limit concurrency
Mar 28, 2019
01bd719
Concurrency limit
Mar 28, 2019
2f8e564
Drop cache after analysis
Mar 28, 2019
9a933bd
Merge branch 'master' of https://github.com/Microsoft/python-language…
Mar 28, 2019
4ad56bb
Fix regression
Mar 28, 2019
c280c55
Merge branch 'master' of https://github.com/Microsoft/python-language…
Apr 3, 2019
b21b8b8
Merge branch 'master' of https://github.com/Microsoft/python-language…
Apr 7, 2019
babaee4
Merge branch 'master' of https://github.com/Microsoft/python-language…
Apr 8, 2019
092efd6
Merge branch 'master' of https://github.com/Microsoft/python-language…
Apr 8, 2019
b97594d
Merge branch 'master' of https://github.com/Microsoft/python-language…
Apr 10, 2019
2a50eb9
Fix test
Apr 10, 2019
9c7f58d
Merge branch 'master' of https://github.com/Microsoft/python-language…
Apr 10, 2019
00faa5f
Merge branch 'master' of https://github.com/Microsoft/python-language…
Apr 12, 2019
4c8aa92
Merge branch 'master' of https://github.com/Microsoft/python-language…
Apr 12, 2019
1a67bc8
Merge branch 'master' of https://github.com/Microsoft/python-language…
Apr 12, 2019
7a13215
Merge branch 'master' of https://github.com/Microsoft/python-language…
Apr 16, 2019
3d907d8
Merge branch 'master' of https://github.com/Microsoft/python-language…
Apr 16, 2019
94a274f
Merge branch 'master' of https://github.com/Microsoft/python-language…
Apr 29, 2019
c1f3f3a
Correct module when going to a class
May 10, 2019
c57819d
Merge branch 'master' of https://github.com/Microsoft/python-language…
May 10, 2019
45a29e7
Make extension
May 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Analysis/Ast/Impl/Extensions/EvaluatorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.

using System;
using Microsoft.Python.Analysis.Analyzer;
using Microsoft.Python.Analysis.Types;
using Microsoft.Python.Analysis.Values;
Expand All @@ -23,5 +24,10 @@ public static IMember LookupNameInScopes(this IExpressionEvaluator eval, string
=> eval.LookupNameInScopes(name, out scope, out _, options);
public static IMember LookupNameInScopes(this IExpressionEvaluator eval, string name, LookupOptions options = LookupOptions.Normal)
=> eval.LookupNameInScopes(name, out _, out _, options);

public static IDisposable OpenScope(this IExpressionEvaluator eval, IPythonClassType cls)
=> eval.OpenScope(cls.DeclaringModule, cls.ClassDefinition);
public static IDisposable OpenScope(this IExpressionEvaluator eval, IPythonFunctionType ft)
=> eval.OpenScope(ft.DeclaringModule, ft.FunctionDefinition);
}
}
2 changes: 1 addition & 1 deletion src/Analysis/Ast/Impl/Extensions/PythonClassExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void AddMemberReference(this IPythonType type, string name, IExpre
if (m is LocatedMember lm) {
lm.AddReference(location);
} else if(type is IPythonClassType cls) {
using (eval.OpenScope(cls.DeclaringModule, cls.ClassDefinition)) {
using (eval.OpenScope(cls)) {
eval.LookupNameInScopes(name, out _, out var v, LookupOptions.Local);
v?.AddReference(location);
}
Expand Down
2 changes: 1 addition & 1 deletion src/LanguageServer/Impl/Sources/DefinitionSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private Reference FromMemberExpression(MemberExpression mex, IDocumentAnalysis a
case IPythonClassType cls:
// Data members may be instances that are not tracking locations.
// In this case we'll try look up the respective variable instead.
using (eval.OpenScope(analysis.Document, cls.ClassDefinition)) {
using (eval.OpenScope(cls)) {
eval.LookupNameInScopes(mex.Name, out _, out var v2, LookupOptions.Local);
if (v2 != null) {
definingMember = v2;
Expand Down
36 changes: 36 additions & 0 deletions src/LanguageServer/Test/GoToDefinitionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.Python.Analysis.Analyzer;
Expand Down Expand Up @@ -304,5 +307,38 @@ import helper
reference.range.Should().Be(0, 0, 0, 7);
reference.uri.AbsolutePath.Should().Contain("__init__.py");
}

[TestMethod, Priority(0)]
public async Task ImportedClassMember() {
await TestData.CreateTestSpecificFileAsync($"module{Path.DirectorySeparatorChar}bar.py", @"
class Bar:
def get_name(self): ...
");

const string code = @"
from .module.bar import Bar

class MainClass:
def __init__(self):
self.bar = Bar()

def foo(self):
return self.bar.get_name()
";
var root = TestData.GetTestSpecificRootUri().AbsolutePath;
await CreateServicesAsync(root, PythonVersions.LatestAvailable3X);
var rdt = Services.GetService<IRunningDocumentTable>();

var mainPath = TestData.GetTestSpecificUri("main.py");
var doc = rdt.OpenDocument(mainPath, code);

var analysis = await doc.GetAnalysisAsync(Timeout.Infinite);
var ds = new DefinitionSource(Services);

var reference = ds.FindDefinition(analysis, new SourceLocation(9, 27), out _);
reference.Should().NotBeNull();
reference.range.Should().Be(2, 8, 2, 16);
reference.uri.AbsolutePath.Should().Contain("bar.py");
}
}
}