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
23 commits
Select commit Hold shift + click to select a range
c6a9c22
Remove stale reference
Sep 30, 2019
1360827
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 1, 2019
ccaaa02
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 4, 2019
da40dcc
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 4, 2019
c348ac3
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 5, 2019
53bc044
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 7, 2019
484a92a
Merge branch 'master' of https://github.com/MikhailArkhipov/python-la…
Oct 7, 2019
e6df3aa
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 8, 2019
1d289d8
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 8, 2019
126f355
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 12, 2019
7e715f3
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 25, 2019
32923a5
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 31, 2019
1b72f4b
Merge branch 'master' of https://github.com/microsoft/python-language…
Nov 2, 2019
f74d5b6
Merge branch 'master' of https://github.com/microsoft/python-language…
Nov 7, 2019
0b28fa4
Merge branch 'master' of https://github.com/microsoft/python-language…
Nov 12, 2019
6109ac7
Don't suppress LHS diagnostics on augmented assign
Nov 12, 2019
bcfc3b7
Revert "Don't suppress LHS diagnostics on augmented assign"
Nov 12, 2019
dc286b8
Merge branch 'master' of https://github.com/microsoft/python-language…
Nov 13, 2019
0aab4f5
Merge branch 'master' of https://github.com/microsoft/python-language…
Nov 16, 2019
b953ce7
Merge branch 'master' of https://github.com/microsoft/python-language…
Nov 18, 2019
aef887d
Merge branch 'master' of https://github.com/microsoft/python-language…
Dec 10, 2019
86c20c6
Handle gotodef on unknown types
Dec 10, 2019
cf3c0dd
PR feedback
Dec 10, 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
5 changes: 4 additions & 1 deletion src/LanguageServer/Impl/Sources/DefinitionSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ private Reference HandleFromImport(IDocumentAnalysis analysis, SourceLocation lo
case ImplicitPackageImport packageImport:
module = mres.GetImportedModule(packageImport.FullName);
break;
case ImportNotFound _:
return null;
}

// Are we in the module name (i.e. A in 'from A import B')?
Expand Down Expand Up @@ -262,7 +264,8 @@ private Reference TryFromVariable(string name, IDocumentAnalysis analysis, Sourc
definingMember = null;

var m = analysis.ExpressionEvaluator.LookupNameInScopes(name, out var scope, LookupOptions.All);
if (m == null || scope.Module.ModuleType == ModuleType.Builtins || !(scope.Variables[name] is IVariable v)) {
var v = scope?.Variables[name];
if (m == null || scope == null || scope.Module.ModuleType == ModuleType.Builtins || v.IsUnknown()) {
return null;
}

Expand Down
22 changes: 22 additions & 0 deletions src/LanguageServer/Test/GoToDefinitionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -688,5 +688,27 @@ def c(): ...
reference.uri.AbsolutePath.Should().Contain("other.py");
reference.range.Should().Be(3, 4, 3, 5);
}

[TestMethod, Priority(0)]
public async Task UnknownType() {
const string code = @"
A
";
var analysis = await GetAnalysisAsync(code);
var ds = new DefinitionSource(Services);
var reference = ds.FindDefinition(analysis, new SourceLocation(2, 1), out _);
reference.Should().BeNull();
}

[TestMethod, Priority(0)]
public async Task UnknownImportedType() {
const string code = @"
from nonexistent import some
";
var analysis = await GetAnalysisAsync(code);
var ds = new DefinitionSource(Services);
var reference = ds.FindDefinition(analysis, new SourceLocation(2, 26), out _);
reference.Should().BeNull();
}
}
}