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

Commit 02d6e19

Browse files
author
MikhailArkhipov
committed
Merge branch 'master' of https://github.com/Microsoft/python-language-server into overloads
2 parents 6df890b + ade27a4 commit 02d6e19

15 files changed

Lines changed: 2905 additions & 18 deletions

src/Analysis/Engine/Impl/Analyzer/FunctionAnalysisUnit.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ private bool ProcessAbstractDecorators(IAnalysisSet decorator) {
101101

102102
// Only handle these if they are specialized
103103
foreach (var d in decorator.OfType<SpecializedCallable>()) {
104-
if (d.DeclaringModule?.ModuleName != "abc") {
104+
if (d.DeclaringModule != null
105+
&& d.DeclaringModule.ModuleName != "abc") {
105106
continue;
106107
}
107108

src/Analysis/Engine/Impl/Infrastructure/Extensions/StringBuilderExtensions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,21 @@ public static StringBuilder TrimEnd(this StringBuilder sb) {
2424
}
2525
return sb;
2626
}
27+
28+
public static StringBuilder EnsureEndsWithSpace(this StringBuilder sb, int count = 1, bool allowLeading = false) {
29+
if (sb.Length == 0 && !allowLeading) {
30+
return sb;
31+
}
32+
33+
for (var i = sb.Length - 1; i >= 0 && char.IsWhiteSpace(sb[i]); i--) {
34+
count--;
35+
}
36+
37+
if (count > 0) {
38+
sb.Append(new string(' ', count));
39+
}
40+
41+
return sb;
42+
}
2743
}
2844
}

src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ public override IEnumerable<ILocationInfo> Locations {
217217
}
218218
}
219219

220+
public override string Name => _original == null ? base.Name : this._original.Name;
221+
220222
public override IEnumerable<OverloadResult> Overloads {
221223
get {
222224
if (_original == null) {

src/Analysis/Engine/Test/InheritanceTests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
using System.Text;
44
using System.Threading.Tasks;
55
using Microsoft.Python.LanguageServer.Implementation;
6+
using Microsoft.PythonTools.Analysis;
67
using Microsoft.PythonTools.Analysis.FluentAssertions;
78
using Microsoft.PythonTools.Interpreter;
89
using Microsoft.VisualStudio.TestTools.UnitTesting;
910
using TestUtilities;
1011

11-
namespace Microsoft.PythonTools.Analysis {
12+
namespace AnalysisTests {
1213
[TestClass]
1314
public class InheritanceTests {
1415
public TestContext TestContext { get; set; }
@@ -38,5 +39,30 @@ def virt():
3839
analysis.Should().HaveVariable("b").OfType(BuiltinTypeId.Int);
3940
}
4041
}
42+
43+
[TestMethod]
44+
public async Task AbstractPropertyReturnTypeIgnored() {
45+
var code = @"
46+
import abc
47+
48+
class A:
49+
@abc.abstractproperty
50+
def virt():
51+
pass
52+
53+
class B(A):
54+
@property
55+
def virt():
56+
return 42
57+
58+
a = A()
59+
b = a.virt";
60+
61+
using (var server = await new Server().InitializeAsync(PythonVersions.Required_Python36X)) {
62+
var analysis = await server.OpenDefaultDocumentAndGetAnalysisAsync(code);
63+
64+
analysis.Should().HaveVariable("b").OfType(BuiltinTypeId.Int);
65+
}
66+
}
4167
}
4268
}

src/Analysis/Engine/Test/LanguageServerTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,42 @@ public async Task ParseAndAnalysisDiagnostics() {
992992
);
993993
}
994994

995+
[TestMethod, Priority(0)]
996+
public async Task OnTypeFormatting() {
997+
using (var s = await CreateServer()) {
998+
var uri = await AddModule(s, "def foo ( ) :\n x = a + b\n x+= 1");
999+
1000+
// Extended tests for line formatting are in LineFormatterTests.
1001+
// These just verify that the language server formats and returns something correct.
1002+
var edits = await s.SendDocumentOnTypeFormatting(uri, new SourceLocation(2, 1), "\n");
1003+
edits.Should().OnlyContain(new TextEdit {
1004+
newText = "def foo():",
1005+
range = new Range {
1006+
start = new SourceLocation(1, 1),
1007+
end = new SourceLocation(1, 15)
1008+
}
1009+
});
1010+
1011+
edits = await s.SendDocumentOnTypeFormatting(uri, new SourceLocation(3, 1), "\n");
1012+
edits.Should().OnlyContain(new TextEdit {
1013+
newText = "x = a + b",
1014+
range = new Range {
1015+
start = new SourceLocation(2, 5),
1016+
end = new SourceLocation(2, 14)
1017+
}
1018+
});
1019+
1020+
edits = await s.SendDocumentOnTypeFormatting(uri, new SourceLocation(4, 1), "\n");
1021+
edits.Should().OnlyContain(new TextEdit {
1022+
newText = "x += 1",
1023+
range = new Range {
1024+
start = new SourceLocation(3, 5),
1025+
end = new SourceLocation(3, 10)
1026+
}
1027+
});
1028+
}
1029+
}
1030+
9951031
class GetAllExtensionProvider : ILanguageServerExtensionProvider {
9961032
public Task<ILanguageServerExtension> CreateAsync(IPythonLanguageServer server, IReadOnlyDictionary<string, object> properties, CancellationToken cancellationToken) {
9971033
return Task.FromResult<ILanguageServerExtension>(new GetAllExtension((Server)server, properties));

0 commit comments

Comments
 (0)