Ejemplo n.º 1
0
        public async Task <Location> GotoDeclaration(TextDocumentPositionParams @params, CancellationToken cancellationToken)
        {
            var uri = @params.textDocument.uri;

            _log?.Log(TraceEventType.Verbose, $"Goto Declaration in {uri} at {@params.position}");

            var analysis = await Document.GetAnalysisAsync(uri, Services, CompletionAnalysisTimeout, cancellationToken);

            var reference = new DeclarationSource(Services).FindDefinition(analysis, @params.position, out _);

            return(reference != null ? new Location {
                uri = reference.uri, range = reference.range
            } : null);
        }
Ejemplo n.º 2
0
        public async Task GotoDeclarationFromImportAs()
        {
            const string code     = @"
from logging import critical as crit
x = crit
";
            var          analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X);

            var ds = new DeclarationSource(Services);

            var reference = ds.FindDefinition(analysis, new SourceLocation(3, 6), out _);

            reference.Should().NotBeNull();
            reference.range.Should().Be(1, 32, 1, 36);
        }
Ejemplo n.º 3
0
        public async Task GotoBuiltinObject()
        {
            const string code     = @"
class A(object):
    pass
";
            var          analysis = await GetAnalysisAsync(code);

            var ds1       = new DefinitionSource(Services);
            var reference = ds1.FindDefinition(analysis, new SourceLocation(2, 12), out _);

            reference.Should().BeNull();

            var ds2 = new DeclarationSource(Services);

            reference = ds2.FindDefinition(analysis, new SourceLocation(2, 12), out _);
            reference.Should().BeNull();
        }
Ejemplo n.º 4
0
        public async Task GotoDeclarationFromImport()
        {
            const string code     = @"
from MultiValues import t
x = t
";
            var          analysis = await GetAnalysisAsync(code);

            var ds = new DeclarationSource(Services);

            var reference = ds.FindDefinition(analysis, new SourceLocation(3, 5), out _);

            reference.Should().NotBeNull();
            reference.range.Should().Be(1, 24, 1, 25);

            reference = ds.FindDefinition(analysis, new SourceLocation(2, 25), out _);
            reference.Should().NotBeNull();
            reference.range.Should().Be(2, 0, 2, 1);
            reference.uri.AbsolutePath.Should().Contain("MultiValues.py");
        }