|
18 | 18 | using System.Threading.Tasks;
|
19 | 19 | using FluentAssertions;
|
20 | 20 | using Microsoft.Python.Analysis;
|
| 21 | +using Microsoft.Python.Analysis.Documents; |
21 | 22 | using Microsoft.Python.Analysis.Modules;
|
22 | 23 | using Microsoft.Python.Analysis.Types;
|
23 | 24 | using Microsoft.Python.Core;
|
@@ -706,6 +707,38 @@ public async Task InWithStatement() {
|
706 | 707 | result.Should().HaveNoCompletion();
|
707 | 708 | }
|
708 | 709 |
|
| 710 | + |
| 711 | + [TestMethod, Priority(0)] |
| 712 | + public async Task ImportInPackage() { |
| 713 | + var module1Path = TestData.GetTestSpecificUri("package", "module1.py"); |
| 714 | + var module2Path = TestData.GetTestSpecificUri("package", "module2.py"); |
| 715 | + var module3Path = TestData.GetTestSpecificUri("package", "sub_package", "module3.py"); |
| 716 | + |
| 717 | + var root = TestData.GetTestSpecificRootUri().AbsolutePath; |
| 718 | + await CreateServicesAsync(root, PythonVersions.LatestAvailable3X); |
| 719 | + var rdt = Services.GetService<IRunningDocumentTable>(); |
| 720 | + |
| 721 | + var module1 = rdt.OpenDocument(module1Path, "import package."); |
| 722 | + var module2 = rdt.OpenDocument(module2Path, "import package.sub_package."); |
| 723 | + var module3 = rdt.OpenDocument(module3Path, "import package."); |
| 724 | + |
| 725 | + var analysis1 = await module1.GetAnalysisAsync(-1); |
| 726 | + var analysis2 = await module2.GetAnalysisAsync(-1); |
| 727 | + var analysis3 = await module3.GetAnalysisAsync(-1); |
| 728 | + |
| 729 | + var cs = new CompletionSource(new PlainTextDocumentationSource(), ServerSettings.completion); |
| 730 | + |
| 731 | + var result = cs.GetCompletions(analysis1, new SourceLocation(1, 16)); |
| 732 | + result.Should().OnlyHaveLabels("module2", "sub_package"); |
| 733 | + result = cs.GetCompletions(analysis2, new SourceLocation(1, 16)); |
| 734 | + result.Should().OnlyHaveLabels("module1", "sub_package"); |
| 735 | + result = cs.GetCompletions(analysis2, new SourceLocation(1, 28)); |
| 736 | + result.Should().OnlyHaveLabels("module3"); |
| 737 | + result = cs.GetCompletions(analysis3, new SourceLocation(1, 16)); |
| 738 | + result.Should().OnlyHaveLabels("module1", "module2", "sub_package"); |
| 739 | + } |
| 740 | + |
| 741 | + |
709 | 742 | [TestMethod, Priority(0)]
|
710 | 743 | public async Task InImport() {
|
711 | 744 | var code = @"
|
@@ -860,6 +893,86 @@ import os
|
860 | 893 | result.Should().HaveLabels("split", @"getsize", @"islink", @"abspath");
|
861 | 894 | }
|
862 | 895 |
|
| 896 | + [TestMethod, Priority(0)] |
| 897 | + public async Task FromDotInRoot() { |
| 898 | + const string code = "from ."; |
| 899 | + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X); |
| 900 | + var cs = new CompletionSource(new PlainTextDocumentationSource(), ServerSettings.completion); |
| 901 | + |
| 902 | + var result = cs.GetCompletions(analysis, new SourceLocation(1, 7)); |
| 903 | + result.Should().HaveNoCompletion(); |
| 904 | + } |
| 905 | + |
| 906 | + [TestMethod, Priority(0)] |
| 907 | + public async Task FromDotInExplicitPackage() { |
| 908 | + var initPyPath = TestData.GetTestSpecificUri("package", "__init__.py"); |
| 909 | + var module1Path = TestData.GetTestSpecificUri("package", "module1.py"); |
| 910 | + var module2Path = TestData.GetTestSpecificUri("package", "module2.py"); |
| 911 | + var module3Path = TestData.GetTestSpecificUri("package", "sub_package", "module3.py"); |
| 912 | + |
| 913 | + var root = TestData.GetTestSpecificRootUri().AbsolutePath; |
| 914 | + await CreateServicesAsync(root, PythonVersions.LatestAvailable3X); |
| 915 | + var rdt = Services.GetService<IRunningDocumentTable>(); |
| 916 | + |
| 917 | + rdt.OpenDocument(initPyPath, "answer = 42"); |
| 918 | + var module = rdt.OpenDocument(module1Path, "from ."); |
| 919 | + rdt.OpenDocument(module2Path, string.Empty); |
| 920 | + rdt.OpenDocument(module3Path, string.Empty); |
| 921 | + |
| 922 | + var analysis = await module.GetAnalysisAsync(-1); |
| 923 | + var cs = new CompletionSource(new PlainTextDocumentationSource(), ServerSettings.completion); |
| 924 | + |
| 925 | + var result = cs.GetCompletions(analysis, new SourceLocation(1, 7)); |
| 926 | + result.Should().OnlyHaveLabels("module2", "sub_package", "answer"); |
| 927 | + } |
| 928 | + |
| 929 | + [TestMethod, Priority(0)] |
| 930 | + public async Task FromPartialName() { |
| 931 | + var initPyPath = TestData.GetTestSpecificUri("package", "__init__.py"); |
| 932 | + var module1Path = TestData.GetTestSpecificUri("package", "module1.py"); |
| 933 | + var module2Path = TestData.GetTestSpecificUri("package", "sub_package", "module2.py"); |
| 934 | + |
| 935 | + var root = TestData.GetTestSpecificRootUri().AbsolutePath; |
| 936 | + await CreateServicesAsync(root, PythonVersions.LatestAvailable3X); |
| 937 | + var rdt = Services.GetService<IRunningDocumentTable>(); |
| 938 | + |
| 939 | + var module = rdt.OpenDocument(initPyPath, "answer = 42"); |
| 940 | + var module1 = rdt.OpenDocument(module1Path, "from pa"); |
| 941 | + var module2 = rdt.OpenDocument(module2Path, "from package.su"); |
| 942 | + module1.Interpreter.ModuleResolution.GetOrLoadModule("package"); |
| 943 | + |
| 944 | + await module.GetAnalysisAsync(-1); |
| 945 | + var analysis1 = await module1.GetAnalysisAsync(-1); |
| 946 | + var analysis2 = await module2.GetAnalysisAsync(-1); |
| 947 | + var cs = new CompletionSource(new PlainTextDocumentationSource(), ServerSettings.completion); |
| 948 | + |
| 949 | + var result = cs.GetCompletions(analysis1, new SourceLocation(1, 8)); |
| 950 | + result.Should().HaveLabels("package").And.NotContainLabels("module2", "sub_package", "answer"); |
| 951 | + result = cs.GetCompletions(analysis2, new SourceLocation(1, 16)); |
| 952 | + result.Should().OnlyHaveLabels("module1", "sub_package", "answer"); |
| 953 | + } |
| 954 | + |
| 955 | + [TestMethod, Priority(0)] |
| 956 | + public async Task FromDotInImplicitPackage() { |
| 957 | + var module1 = TestData.GetTestSpecificUri("package", "module1.py"); |
| 958 | + var module2 = TestData.GetTestSpecificUri("package", "module2.py"); |
| 959 | + var module3 = TestData.GetTestSpecificUri("package", "sub_package", "module3.py"); |
| 960 | + |
| 961 | + var root = TestData.GetTestSpecificRootUri().AbsolutePath; |
| 962 | + await CreateServicesAsync(root, PythonVersions.LatestAvailable3X); |
| 963 | + var rdt = Services.GetService<IRunningDocumentTable>(); |
| 964 | + |
| 965 | + var module = rdt.OpenDocument(module1, "from ."); |
| 966 | + rdt.OpenDocument(module2, string.Empty); |
| 967 | + rdt.OpenDocument(module3, string.Empty); |
| 968 | + |
| 969 | + var analysis = await module.GetAnalysisAsync(-1); |
| 970 | + var cs = new CompletionSource(new PlainTextDocumentationSource(), ServerSettings.completion); |
| 971 | + |
| 972 | + var result = cs.GetCompletions(analysis, new SourceLocation(1, 7)); |
| 973 | + result.Should().OnlyHaveLabels("module2", "sub_package"); |
| 974 | + } |
| 975 | + |
863 | 976 | [DataRow(false)]
|
864 | 977 | [DataRow(true)]
|
865 | 978 | [DataTestMethod, Priority(0)]
|
|
0 commit comments