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
20 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
ba7a029
Handle cls
Nov 13, 2019
6fb8abb
Remove temp test
Nov 13, 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: 3 additions & 3 deletions src/LanguageServer/Impl/Completion/ExpressionCompletion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ private static IEnumerable<CompletionItem> GetClassItems(IPythonClassType cls, E
// See if we are completing on self. Note that we may be inside inner function
// that does not necessarily have 'self' argument so we are looking beyond local
// scope. We then check that variable type matches the class type, if any.
var selfVariable = eval.LookupNameInScopes("self");
var completingOnSelf = cls.Equals(selfVariable?.GetPythonType()) && e is NameExpression nex && nex.Name == "self";
var classVariable = eval.LookupNameInScopes("self") ?? eval.LookupNameInScopes("cls");
var completingOnClass = cls.Equals(classVariable?.GetPythonType()) && e is NameExpression nex && (nex.Name == "self" || nex.Name == "cls");

var items = new List<CompletionItem>();
var names = cls.GetMemberNames().ToArray();
Expand All @@ -74,7 +74,7 @@ private static IEnumerable<CompletionItem> GetClassItems(IPythonClassType cls, E
var unmangledName = cls.UnmangleMemberName(t);
if (!string.IsNullOrEmpty(unmangledName)) {
// Hide private variables outside of the class scope.
if (!completingOnSelf && cls.IsPrivateMember(t)) {
if (!completingOnClass && cls.IsPrivateMember(t)) {
continue;
}
items.Add(context.ItemSource.CreateCompletionItem(unmangledName, m, cls));
Expand Down
25 changes: 25 additions & 0 deletions src/LanguageServer/Test/CompletionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1486,5 +1486,30 @@ public async Task ImportDotMembers() {
var result = cs.GetCompletions(analysis, new SourceLocation(1, 16));
result.Should().OnlyHaveLabels("m1", "m2");
}

[TestMethod, Priority(0)]
public async Task ClassPrivateMembers() {
const string code = @"
class Op:
__EQ = '0'
__NOT_EQ = '1'
__OP_LIST = [__EQ]

def print_EQ1(self):
self.

@classmethod
def print_EQ2(cls):
cls.
";
var analysis = await GetAnalysisAsync(code);
var cs = new CompletionSource(new PlainTextDocumentationSource(), ServerSettings.completion, Services);

var result = cs.GetCompletions(analysis, new SourceLocation(8, 14));
result.Should().HaveLabels("__EQ", "__NOT_EQ", "__OP_LIST");

result = cs.GetCompletions(analysis, new SourceLocation(12, 13));
result.Should().HaveLabels("__EQ", "__NOT_EQ", "__OP_LIST");
}
}
}