Exemplo n.º 1
0
        private static LocationLink ValidateDefinitionResponse(LocationOrLocationLinks response)
        {
            // go to def should produce single result in all cases
            response.Should().HaveCount(1);
            var single = response.Single();

            single.IsLocation.Should().BeFalse();
            single.IsLocationLink.Should().BeTrue();

            single.Location.Should().BeNull();
            single.LocationLink.Should().NotBeNull();

            return(single.LocationLink !);
        }
Exemplo n.º 2
0
        public void LocationTest(string expected)
        {
            var model = new LocationOrLocationLinks(new Location()
            {
                Range = new Range(new Position(1, 1), new Position(3, 3)),
            });
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject <LocationOrLocationLinks>(expected);

            deresult.Should().BeEquivalentTo(model);
        }
        public async Task <LocationOrLocationLinks> Handle(DefinitionParams request, CancellationToken cancellationToken)
        {
            _router.Window.LogMessage(new LogMessageParams()
            {
                Type    = MessageType.Log,
                Message = "Go to definition request at line: " + (request.Position.Line + 1),
            });

            _threadManager.AssertBackgroundThread();

            var document = await Task.Factory.StartNew(
                () =>
            {
                _snapshotManager.TryResolveDocument(request.TextDocument.Uri.AbsolutePath, out var doc);
                return(doc);
            },
                CancellationToken.None,
                TaskCreationOptions.None,
                _threadManager.ForegroundScheduler);

            var syntaxTree = await document.GetSyntaxTreeAsync();

            var child = syntaxTree.Root.GetNodeAt((int)request.Position.Line, (int)request.Position.Character);

            if (child.Parent is MethodNode && (child is InputNode || child is OutputNode))
            {
                //var declaringTypeNode = FindDeclaringTypeNode(syntaxTree.Root, child.Content);
                var declaringTypeNode = syntaxTree.Root.Messages.SingleOrDefault(c => c.Name == child.Content).NameNode;
                if (declaringTypeNode != null)
                {
                    var declaringTypeNodeLocation = new LocationOrLocationLink(
                        new Location()
                    {
                        Range = new Range(
                            new Position(declaringTypeNode.StartLine, declaringTypeNode.StartCol),
                            new Position(declaringTypeNode.EndLine, declaringTypeNode.EndCol)),
                        Uri = request.TextDocument.Uri,
                    });
                    var locations = new LocationOrLocationLinks(declaringTypeNodeLocation);
                    return(locations);
                }
            }

            var emptyLocations = new LocationOrLocationLinks();

            return(emptyLocations);
        }
Exemplo n.º 4
0
        public void LocationsTest(string expected)
        {
            var model = new LocationOrLocationLinks(
                new Location {
                Range = new Range(new Position(1, 1), new Position(3, 3)),
            }, new Location {
                Range = new Range(new Position(1, 1), new Position(3, 3)),
            }
                );
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            var deresult = new LspSerializer(ClientVersion.Lsp3).DeserializeObject <LocationOrLocationLinks>(expected);

            deresult.Should().BeEquivalentTo(model, x => x.UsingStructuralRecordEquality());
        }
Exemplo n.º 5
0
        public Task <LocationOrLocationLinks> Handle(DefinitionParams request, CancellationToken cancellationToken)
        {
            var hash = Hash.StringHash(request.TextDocument.Uri.GetFileSystemPath());

            TreeSitter.FindDefinition(hash, request.Position.Line, request.Position.Character, out var defHash, out var origin, out var target, out var selection);

            if (defHash != 0)
            {
                LocationLink link = new LocationLink();
                link.TargetUri            = DocumentUri.FromFileSystemPath(hashNamer.hashToName[defHash]);
                link.OriginSelectionRange = ConvertRange(origin);
                link.TargetRange          = ConvertRange(target);
                link.TargetSelectionRange = ConvertRange(selection);
                LocationOrLocationLinks ll = new LocationOrLocationLinks(link);
                return(Task.FromResult(ll));
            }

            return(Task.FromResult(new LocationOrLocationLinks()));
        }
Exemplo n.º 6
0
        public void LocationLinkTest(string expected)
        {
            var model = new LocationOrLocationLinks(new LocationLink()
            {
                TargetSelectionRange = new Range(new Position(1, 1), new Position(3, 3)),
                TargetRange          = new Range(new Position(1, 1), new Position(3, 3)),
                TargetUri            = new Uri("file:///asdfasdf/a.tst"),
                OriginSelectionRange = new Range(new Position(1, 1), new Position(3, 3)),
            });
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject <LocationOrLocationLinks>(expected);

            deresult.Should().BeEquivalentTo(model, x => x
                                             .ComparingByMembers <LocationOrLocationLink>()
                                             );
        }
Exemplo n.º 7
0
        public override Task <LocationOrLocationLinks> Handle(DefinitionParams request, CancellationToken cancellationToken)
        {
            var progress = ProgressManager.For(request, cancellationToken);
            var work     = ProgressManager.WorkDone(request, new WorkDoneProgressBegin
            {
                Title   = "Resolve symbol definition location",
                Message = "Begin resolving definition under caret"
            });

            var editorData = DResolverWrapper.CreateEditorData(request, cancellationToken);
            var results    = DResolverWrapper.ResolveHoveredCodeLoosely(editorData, out LooseResolution.NodeResolutionAttempt resolutionAttempt, out ISyntaxRegion syntaxRegion);

            var result = new LocationOrLocationLinks(
                results.Select(ExpressionTypeEvaluation.GetResultMember)
                .Select(node => ToLocationOrLocationLink(node, Capability.LinkSupport, syntaxRegion)));

            progress?.OnNext(new Container <LocationOrLocationLink>(result));
            work.OnCompleted();

            return(Task.FromResult(progress != null ? new LocationOrLocationLinks() : result));
        }
Exemplo n.º 8
0
        public async Task CanSendDefinitionRequestAsync()
        {
            string scriptPath = NewTestFile(@"
function CanSendDefinitionRequest {

}

CanSendDefinitionRequest
");

            LocationOrLocationLinks locationOrLocationLinks =
                await PsesLanguageClient
                .SendRequest <DefinitionParams>(
                    "textDocument/definition",
                    new DefinitionParams
            {
                TextDocument = new TextDocumentIdentifier
                {
                    Uri = new Uri(scriptPath)
                },
                Position = new Position
                {
                    Line      = 5,
                    Character = 2
                }
            })
                .Returning <LocationOrLocationLinks>(CancellationToken.None).ConfigureAwait(false);

            LocationOrLocationLink locationOrLocationLink =
                Assert.Single(locationOrLocationLinks);

            Assert.Equal(1, locationOrLocationLink.Location.Range.Start.Line);
            Assert.Equal(9, locationOrLocationLink.Location.Range.Start.Character);
            Assert.Equal(1, locationOrLocationLink.Location.Range.End.Line);
            Assert.Equal(33, locationOrLocationLink.Location.Range.End.Character);
        }
Exemplo n.º 9
0
 protected void SetGoToDefinitionWithoutZeroIndexing(string file, int line, int col)
 {
     Client.TextDocument.DidOpen(file, "dfy");
     goneTo = Client.TextDocument.Definition(file, line - 1, col - 1).Result;
 }
Exemplo n.º 10
0
 public void ResetResult()
 {
     goneTo = default;
 }