예제 #1
0
        public async Task NoRenameInLibrary()
        {
            const string code     = @"from logging import BASIC_FORMAT";
            var          analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X);

            var rs = new RenameSource(Services);

            var wse = await rs.RenameAsync(analysis.Document.Uri, new SourceLocation(1, 10), "z");

            wse.Should().BeNull();

            wse = await rs.RenameAsync(analysis.Document.Uri, new SourceLocation(1, 23), "z");

            wse.Should().BeNull();
        }
예제 #2
0
        public async Task SingleFile()
        {
            const string code     = @"
x = 1

def func(x):
    return x

y = func(x)
x = 2
";
            var          analysis = await GetAnalysisAsync(code);

            var rs  = new RenameSource(Services);
            var wse = await rs.RenameAsync(analysis.Document.Uri, new SourceLocation(8, 1), "z");

            var uri = analysis.Document.Uri;

            wse.changes.Should().HaveCount(1);
            wse.changes[uri].Should().HaveCount(3);
            wse.changes[uri][0].range.Should().Be(1, 0, 1, 1);
            wse.changes[uri][1].range.Should().Be(6, 9, 6, 10);
            wse.changes[uri][2].range.Should().Be(7, 0, 7, 1);
            wse.changes[uri].All(x => x.newText.EqualsOrdinal("z")).Should().BeTrue();
        }
예제 #3
0
        public async Task NoRenameInCompiled()
        {
            const string code = "from sys import path";

            var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X);

            var rs = new RenameSource(Services);

            var wse = await rs.RenameAsync(analysis.Document.Uri, new SourceLocation(1, 7), "z");

            wse.Should().BeNull();

            wse = await rs.RenameAsync(analysis.Document.Uri, new SourceLocation(1, 18), "z");

            wse.Should().BeNull();
        }
예제 #4
0
        public async Task Rename_ImportSubmodule()
        {
            const string packageInitCode = @"x = 1";
            const string moduleCode      = @"import package.submodule
y = package.x";
            var          initPyUri       = TestData.GetTestSpecificUri("package", "__init__.py");
            var          moduleUri       = TestData.GetTestSpecificUri("module.py");

            await CreateServicesAsync(PythonVersions.LatestAvailable3X);

            var rdt    = Services.GetService <IRunningDocumentTable>();
            var initPy = rdt.OpenDocument(initPyUri, packageInitCode);
            var module = rdt.OpenDocument(moduleUri, moduleCode);

            await initPy.GetAnalysisAsync();

            await module.GetAnalysisAsync();

            var rs  = new RenameSource(Services);
            var wse = await rs.RenameAsync(initPyUri, new SourceLocation(1, 1), "z");

            wse.changes.Should().HaveCount(2);

            wse.changes[initPyUri].Should().HaveCount(1);
            wse.changes[initPyUri][0].range.Should().Be(0, 0, 0, 1);

            wse.changes[moduleUri].Should().HaveCount(1);
            wse.changes[moduleUri][0].range.Should().Be(1, 12, 1, 13);
        }
        public async Task NoRenameInUserLibrary()
        {
            const string code     = @"
import Library1
Library1.make_foo()
";
            var          analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X);

            var rs = new RenameSource(Services);

            var wse = await rs.RenameAsync(analysis.Document.Uri, new SourceLocation(3, 16), "z");

            wse.Should().BeNull();
        }
예제 #6
0
        public async Task ClosedFiles()
        {
            const string code     = @"
x = 1

def func(x):
    return x

y = func(x)
x = 2
";
            const string mod2Code = @"
from module import x
y = x
";
            const string mod3Code = @"
from module import x
y = x
";
            var          uri2     = await TestData.CreateTestSpecificFileAsync("module2.py", mod2Code);

            var uri3 = await TestData.CreateTestSpecificFileAsync("module3.py", mod3Code);

            var analysis = await GetAnalysisAsync(code);

            var uri1 = analysis.Document.Uri;

            var rs  = new RenameSource(Services);
            var wse = await rs.RenameAsync(analysis.Document.Uri, new SourceLocation(7, 10), "z");

            wse.changes.Should().HaveCount(3);

            wse.changes[uri1].Should().HaveCount(3);
            wse.changes[uri1][0].range.Should().Be(1, 0, 1, 1);
            wse.changes[uri1][1].range.Should().Be(6, 9, 6, 10);
            wse.changes[uri1][2].range.Should().Be(7, 0, 7, 1);

            wse.changes[uri2].Should().HaveCount(2);
            wse.changes[uri2][0].range.Should().Be(1, 19, 1, 20);
            wse.changes[uri2][1].range.Should().Be(2, 4, 2, 5);

            wse.changes[uri3].Should().HaveCount(2);
            wse.changes[uri3][0].range.Should().Be(1, 19, 1, 20);
            wse.changes[uri3][1].range.Should().Be(2, 4, 2, 5);
        }
예제 #7
0
        public async Task TwoOpenFiles()
        {
            const string code1 = @"
x = 1

def func(x):
    return x

y = func(x)
x = 2
";
            var          uri1  = TestData.GetDefaultModuleUri();
            var          uri2  = TestData.GetNextModuleUri();

            var code2 = $@"
from {Path.GetFileNameWithoutExtension(uri1.AbsolutePath)} import x
y = x
";

            await CreateServicesAsync(PythonVersions.LatestAvailable3X, uri1.AbsolutePath);

            var rdt  = Services.GetService <IRunningDocumentTable>();
            var doc1 = rdt.OpenDocument(uri1, code1);
            var doc2 = rdt.OpenDocument(uri2, code2);

            var analysis = await GetDocumentAnalysisAsync(doc1);

            await GetDocumentAnalysisAsync(doc2);

            var rs  = new RenameSource(Services);
            var wse = await rs.RenameAsync(analysis.Document.Uri, new SourceLocation(7, 10), "z");

            wse.changes.Should().HaveCount(2);

            wse.changes[uri1].Should().HaveCount(3);
            wse.changes[uri1][0].range.Should().Be(1, 0, 1, 1);
            wse.changes[uri1][1].range.Should().Be(6, 9, 6, 10);
            wse.changes[uri1][2].range.Should().Be(7, 0, 7, 1);

            wse.changes[uri2].Should().HaveCount(2);
            wse.changes[uri2][0].range.Should().Be(1, 19, 1, 20);
            wse.changes[uri2][1].range.Should().Be(2, 4, 2, 5);
        }