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

Commit faac611

Browse files
Merge pull request #199 from AlexanderSher/Fix35
Fix issue #35: `AddBrackets` functionality not working when using new analysis engine in VSC
2 parents 044a70d + e56c88c commit faac611

File tree

11 files changed

+601
-377
lines changed

11 files changed

+601
-377
lines changed

src/Analysis/Engine/Test/AnalysisTest.cs

Lines changed: 1 addition & 332 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
namespace AnalysisTests {
4040
[TestClass]
41-
public partial class AnalysisTest {
41+
public class AnalysisTest {
4242
public TestContext TestContext { get; set; }
4343

4444
[TestInitialize]
@@ -864,102 +864,6 @@ import mod2
864864
}
865865
*/
866866

867-
[TestMethod, Priority(0)]
868-
public async Task PrivateMembers() {
869-
using (var server = await CreateServerAsync(PythonVersions.LatestAvailable2X)) {
870-
var uri = TestData.GetTempPathUri("test-module.py");
871-
872-
string code = @"
873-
class C:
874-
def __init__(self):
875-
self._C__X = 'abc' # Completions here should only ever show __X
876-
self.__X = 42
877-
878-
class D(C):
879-
def __init__(self):
880-
print(self.__X) # self. here shouldn't have __X or _C__X (could be controlled by Text Editor->Python->general->Hide advanced members to show _C__X)
881-
";
882-
883-
await server.SendDidOpenTextDocument(uri, code);
884-
await server.GetAnalysisAsync(uri);
885-
886-
var completions = await server.SendCompletion(uri, 4, 13);
887-
completions.Should().OnlyHaveLabels("__X", "__init__", "__doc__", "__class__");
888-
889-
completions = await server.SendCompletion(uri, 8, 19);
890-
completions.Should().OnlyHaveLabels("_C__X", "__init__", "__doc__", "__class__");
891-
892-
code = @"
893-
class C(object):
894-
def __init__(self):
895-
self.f(_C__A = 42) # sig help should be _C__A
896-
897-
def f(self, __A):
898-
pass
899-
900-
901-
class D(C):
902-
def __init__(self):
903-
self.f(_C__A=42) # sig help should be _C__A
904-
";
905-
906-
await server.SendDidChangeTextDocumentAsync(uri, code);
907-
await server.GetAnalysisAsync(uri);
908-
909-
var signatures = await server.SendSignatureHelp(uri, 3, 15);
910-
signatures.Should().HaveSingleSignature()
911-
.Which.Should().OnlyHaveParameterLabels("_C__A");
912-
913-
signatures = await server.SendSignatureHelp(uri, 11, 15);
914-
signatures.Should().HaveSingleSignature()
915-
.Which.Should().OnlyHaveParameterLabels("_C__A");
916-
917-
code = @"
918-
class C(object):
919-
def __init__(self):
920-
self.__f(_C__A = 42) # member should be __f
921-
922-
def __f(self, __A):
923-
pass
924-
925-
926-
class D(C):
927-
def __init__(self):
928-
self._C__f(_C__A=42) # member should be _C__f
929-
930-
";
931-
932-
await server.SendDidChangeTextDocumentAsync(uri, code);
933-
await server.GetAnalysisAsync(uri);
934-
935-
completions = await server.SendCompletion(uri, 3, 13);
936-
completions.Should().HaveLabels("__f", "__init__");
937-
938-
completions = await server.SendCompletion(uri, 11, 13);
939-
completions.Should().HaveLabels("_C__f", "__init__");
940-
941-
code = @"
942-
class C(object):
943-
__FOB = 42
944-
945-
def f(self):
946-
abc = C.__FOB # Completion should work here
947-
948-
949-
xyz = C._C__FOB # Advanced members completion should work here
950-
";
951-
952-
await server.SendDidChangeTextDocumentAsync(uri, code);
953-
await server.GetAnalysisAsync(uri);
954-
955-
completions = await server.SendCompletion(uri, 5, 16);
956-
completions.Should().HaveLabels("__FOB", "f");
957-
958-
completions = await server.SendCompletion(uri, 8, 8);
959-
completions.Should().HaveLabels("_C__FOB", "f");
960-
}
961-
}
962-
963867
[TestMethod, Priority(0)]
964868
public async Task BaseInstanceVariable() {
965869
var code = @"
@@ -3975,28 +3879,6 @@ def f(x = x):
39753879
}
39763880
}
39773881

3978-
[TestMethod, Priority(0)]
3979-
public async Task RecursiveClass() {
3980-
var code = @"
3981-
cls = object
3982-
3983-
class cls(cls):
3984-
abc = 42
3985-
3986-
a = cls().abc
3987-
b = cls.abc
3988-
";
3989-
using (var server = await CreateServerAsync()) {
3990-
var analysis = await server.OpenDefaultDocumentAndGetAnalysisAsync(code);
3991-
var completion = await server.SendCompletion(TestData.GetDefaultModuleUri(), 8, 0);
3992-
3993-
analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int)
3994-
.And.HaveVariable("b").OfType(BuiltinTypeId.Int);
3995-
3996-
completion.Should().HaveLabels("cls", "object");
3997-
}
3998-
}
3999-
40003882
[TestMethod, Priority(0)]
40013883
public async Task BadMethod() {
40023884
var code = @"
@@ -4134,43 +4016,6 @@ public async Task KeywordSplat(string functionDeclaration, int signatureLine, st
41344016
}
41354017
}
41364018

4137-
[TestMethod, Priority(0)]
4138-
public async Task ForwardRef() {
4139-
var code = @"
4140-
4141-
class D(object):
4142-
def oar(self, x):
4143-
abc = C()
4144-
abc.fob(2)
4145-
a = abc.fob(2.0)
4146-
a.oar(('a', 'b', 'c', 'd'))
4147-
4148-
class C(object):
4149-
def fob(self, x):
4150-
D().oar('abc')
4151-
D().oar(['a', 'b', 'c'])
4152-
return D()
4153-
def baz(self): pass
4154-
";
4155-
using (var server = await CreateServerAsync(PythonVersions.LatestAvailable2X)) {
4156-
var analysis = await server.OpenDefaultDocumentAndGetAnalysisAsync(code);
4157-
var completionInD = await server.SendCompletion(TestData.GetDefaultModuleUri(), 3, 4);
4158-
var completionInOar = await server.SendCompletion(TestData.GetDefaultModuleUri(), 5, 8);
4159-
var completionForAbc = await server.SendCompletion(TestData.GetDefaultModuleUri(), 5, 12);
4160-
4161-
completionInD.Should().HaveLabels("C", "D", "oar")
4162-
.And.NotContainLabels("a", "abc", "self", "x", "fob", "baz");
4163-
4164-
completionInOar.Should().HaveLabels("C", "D", "a", "oar", "abc", "self", "x")
4165-
.And.NotContainLabels("fob", "baz");
4166-
4167-
completionForAbc.Should().HaveLabels("baz", "fob");
4168-
4169-
analysis.Should().HaveClass("D").WithFunction("oar")
4170-
.Which.Should().HaveParameter("x").OfTypes(BuiltinTypeId.List, BuiltinTypeId.Str, BuiltinTypeId.Tuple);
4171-
}
4172-
}
4173-
41744019

41754020
[TestMethod, Priority(0)]
41764021
public async Task Builtins() {
@@ -4277,28 +4122,6 @@ def g(a, b):
42774122
}
42784123
}
42794124

4280-
[TestMethod, Priority(0)]
4281-
public async Task SimpleGlobals() {
4282-
var code = @"
4283-
class x(object):
4284-
def abc(self):
4285-
pass
4286-
4287-
a = x()
4288-
x.abc()
4289-
";
4290-
using (var server = await CreateServerAsync()) {
4291-
var objectMemberNames = server.GetBuiltinTypeMemberNames(BuiltinTypeId.Object);
4292-
4293-
var uri = await server.OpenDefaultDocumentAndGetUriAsync(code);
4294-
var completion = await server.SendCompletion(uri, 6, 0);
4295-
var completionX = await server.SendCompletion(uri, 6, 2);
4296-
4297-
completion.Should().HaveLabels("a", "x").And.NotContainLabels("abc", "self");
4298-
completionX.Should().HaveLabels(objectMemberNames).And.HaveLabels("abc");
4299-
}
4300-
}
4301-
43024125
[TestMethod, Priority(0)]
43034126
public async Task FuncCallInIf() {
43044127
var code = @"
@@ -4403,67 +4226,6 @@ def f(a, b, c=0):
44034226
}
44044227
}
44054228

4406-
/// <summary>
4407-
/// http://pytools.codeplex.com/workitem/799
4408-
/// </summary>
4409-
[TestMethod, Priority(0)]
4410-
public async Task OverrideCompletions2X() {
4411-
var code = @"
4412-
class oar(list):
4413-
def
4414-
pass
4415-
";
4416-
using (var server = await CreateServerAsync(PythonVersions.LatestAvailable2X)) {
4417-
var uri = await server.OpenDefaultDocumentAndGetUriAsync(code);
4418-
var completions = await server.SendCompletion(uri, 2, 8);
4419-
4420-
completions.Should().HaveItem("append")
4421-
.Which.Should().HaveInsertText("append(self, value):\r\n return super(oar, self).append(value)");
4422-
}
4423-
}
4424-
4425-
[DataRow(PythonLanguageVersion.V36, "value")]
4426-
[DataRow(PythonLanguageVersion.V37, "object")]
4427-
[DataTestMethod, Priority(0)]
4428-
public async Task OverrideCompletions3X(PythonLanguageVersion version, string parameterName) {
4429-
var code = @"
4430-
class oar(list):
4431-
def
4432-
pass
4433-
";
4434-
using (var server = await CreateServerAsync(PythonVersions.GetRequiredCPythonConfiguration(version))) {
4435-
var uri = await server.OpenDefaultDocumentAndGetUriAsync(code);
4436-
var completions = await server.SendCompletion(uri, 2, 8);
4437-
4438-
completions.Should().HaveItem("append")
4439-
.Which.Should().HaveInsertText($"append(self, {parameterName}):\r\n return super().append({parameterName})");
4440-
}
4441-
}
4442-
4443-
[TestMethod, Priority(0)]
4444-
public async Task OverrideCompletionsNested() {
4445-
// Ensure that nested classes are correctly resolved.
4446-
var code = @"
4447-
class oar(int):
4448-
class fob(dict):
4449-
def
4450-
pass
4451-
def
4452-
pass
4453-
";
4454-
4455-
using (var server = await CreateServerAsync(PythonVersions.LatestAvailable2X)) {
4456-
var uri = await server.OpenDefaultDocumentAndGetUriAsync(code);
4457-
var completionsOar = await server.SendCompletion(uri, 5, 8);
4458-
var completionsFob = await server.SendCompletion(uri, 3, 12);
4459-
4460-
completionsOar.Should().NotContainLabels("keys", "items")
4461-
.And.HaveItem("bit_length");
4462-
completionsFob.Should().NotContainLabels("bit_length")
4463-
.And.HaveLabels("keys", "items");
4464-
}
4465-
}
4466-
44674229
/// <summary>
44684230
/// https://github.com/Microsoft/PTVS/issues/995
44694231
/// </summary>
@@ -6618,32 +6380,6 @@ def with_params_default_starargs(*args, **kwargs):
66186380
.And.HaveVariable("rf").WithDescription("method return_func of module.return_func_class objects...")
66196381
.WithDocumentation("some help");
66206382
}
6621-
6622-
6623-
}
6624-
6625-
[TestMethod, Priority(0)]
6626-
public async Task CompletionDocumentation() {
6627-
var text = @"
6628-
import sys
6629-
z = 43
6630-
6631-
class fob(object):
6632-
@property
6633-
def f(self): pass
6634-
6635-
def g(self): pass
6636-
6637-
d = fob()
6638-
";
6639-
using (var server = await CreateServerAsync()) {
6640-
var uri = await server.OpenDefaultDocumentAndGetUriAsync(text);
6641-
var completionD = await server.SendCompletion(uri, 15, 1);
6642-
completionD.Should().HaveItem("d")
6643-
.Which.Should().HaveDocumentation("fob");
6644-
completionD.Should().HaveItem("z")
6645-
.Which.Should().HaveDocumentation("int");
6646-
}
66476383
}
66486384

66496385
[TestMethod, Priority(0)]
@@ -6848,73 +6584,6 @@ print abc
68486584
}
68496585
}
68506586

6851-
[TestMethod, Priority(0)]
6852-
public async Task TypeAtEndOfMethod() {
6853-
var text = @"
6854-
class Fob(object):
6855-
def oar(self, a):
6856-
pass
6857-
6858-
6859-
def fob(self):
6860-
pass
6861-
6862-
x = Fob()
6863-
x.oar(100)
6864-
";
6865-
6866-
using (var server = await CreateServerAsync()) {
6867-
var uri = await server.OpenDefaultDocumentAndGetUriAsync(text);
6868-
var completion = await server.SendCompletion(uri, 5, 8);
6869-
completion.Should().HaveItem("a")
6870-
.Which.Should().HaveDocumentation("int");
6871-
}
6872-
}
6873-
6874-
[TestMethod, Priority(0)]
6875-
public async Task TypeAtEndOfIncompleteMethod() {
6876-
var text = @"
6877-
class Fob(object):
6878-
def oar(self, a):
6879-
6880-
6881-
6882-
6883-
6884-
x = Fob()
6885-
x.oar(100)
6886-
";
6887-
6888-
using (var server = await CreateServerAsync()) {
6889-
var uri = await server.OpenDefaultDocumentAndGetUriAsync(text);
6890-
var completion = await server.SendCompletion(uri, 5, 8);
6891-
completion.Should().HaveItem("a")
6892-
.Which.Should().HaveDocumentation("int");
6893-
}
6894-
}
6895-
6896-
[TestMethod, Priority(0)]
6897-
public async Task TypeIntersectionUserDefinedTypes() {
6898-
var text = @"
6899-
class C1(object):
6900-
def fob(self): pass
6901-
6902-
class C2(object):
6903-
def oar(self): pass
6904-
6905-
c = C1()
6906-
c.fob()
6907-
c = C2()
6908-
c.
6909-
";
6910-
6911-
using (var server = await CreateServerAsync()) {
6912-
var uri = await server.OpenDefaultDocumentAndGetUriAsync(text);
6913-
var completion = await server.SendCompletion(uri, 10, 2);
6914-
completion.Should().NotContainLabels("fob", "oar");
6915-
}
6916-
}
6917-
69186587
[TestMethod, Priority(0)]
69196588
public async Task UpdateMethodMultiFiles() {
69206589
var text1 = @"

0 commit comments

Comments
 (0)