Exemplo n.º 1
0
        public async Task TestGotoDefinitionAsync_MappedFile()
        {
            var markup =
                @"class A
{
    string aString = 'hello';
    void M()
    {
        var len = aString.Length;
    }
}";

            using var testLspServer = await CreateTestLspServerAsync(string.Empty);

            AddMappedDocument(testLspServer.TestWorkspace, markup);

            var position = new LSP.Position {
                Line = 5, Character = 18
            };
            var results = await RunGotoDefinitionAsync(testLspServer, new LSP.Location
            {
                Uri   = new Uri($"C:\\{TestSpanMapper.GeneratedFileName}"),
                Range = new LSP.Range {
                    Start = position, End = position
                }
            });

            AssertLocationsEqual(ImmutableArray.Create(TestSpanMapper.MappedFileLocation), results);
        }
Exemplo n.º 2
0
        public async Task TestFindImplementationAsync_MappedFile()
        {
            var markup =
@"interface IA
{
    void M();
}
class A : IA
{
    void IA.M()
    {
    }
}";
            using var testLspServer = await CreateTestLspServerAsync(string.Empty);

            AddMappedDocument(testLspServer.TestWorkspace, markup);

            var position = new LSP.Position { Line = 2, Character = 9 };
            var results = await RunFindImplementationAsync(testLspServer, new LSP.Location
            {
                Uri = new Uri($"C:\\{TestSpanMapper.GeneratedFileName}"),
                Range = new LSP.Range { Start = position, End = position }
            });
            AssertLocationsEqual(ImmutableArray.Create(TestSpanMapper.MappedFileLocation), results);
        }
Exemplo n.º 3
0
 public LSP.Position GetDocumentPosition(LSP.Position currentCellPos)
 {
     return(new LSP.Position {
         Line = currentCellPos.Line + _previousCellsLineCount,
         Character = currentCellPos.Character,
     });
 }
Exemplo n.º 4
0
        public async Task TestRename_WithMappedFileAsync()
        {
            var markup =
                @"class A
{
    void M()
    {
    }
    void M2()
    {
        M()
    }
}";

            using var testLspServer = CreateTestLspServer(string.Empty, out _);

            AddMappedDocument(testLspServer.TestWorkspace, markup);

            var startPosition = new LSP.Position {
                Line = 2, Character = 9
            };
            var endPosition = new LSP.Position {
                Line = 2, Character = 10
            };
            var renameText   = "RENAME";
            var renameParams = CreateRenameParams(
                new LSP.Location
            {
                Uri   = new Uri($"C:\\{TestSpanMapper.GeneratedFileName}"),
                Range = new LSP.Range {
                    Start = startPosition, End = endPosition
                }
            },
                "RENAME"
                );

            var results = await RunRenameAsync(testLspServer, renameParams);

            // There are two rename locations, so we expect two mapped locations.
            var expectedMappedRanges = ImmutableArray.Create(
                TestSpanMapper.MappedFileLocation.Range,
                TestSpanMapper.MappedFileLocation.Range
                );
            var expectedMappedDocument = TestSpanMapper.MappedFileLocation.Uri;

            var documentEdit = results.DocumentChanges.Value.First.Single();

            Assert.Equal(expectedMappedDocument, documentEdit.TextDocument.Uri);
            Assert.Equal(expectedMappedRanges, documentEdit.Edits.Select(edit => edit.Range));
            Assert.True(documentEdit.Edits.All(edit => edit.NewText == renameText));
        }
Exemplo n.º 5
0
            static LSP.Location GetLocationPlusOne(LSP.Location originalLocation)
            {
                var newPosition = new LSP.Position {
                    Character = originalLocation.Range.Start.Character + 1, Line = originalLocation.Range.Start.Line
                };

                return(new LSP.Location
                {
                    Uri = originalLocation.Uri,
                    Range = new LSP.Range {
                        Start = newPosition, End = newPosition
                    }
                });
            }
Exemplo n.º 6
0
        public async Task <object> GetCompletions(LSP.Position position, LSP.CompletionContext context, CancellationToken token)
        {
            var completionParams = new LSP.CompletionParams()
            {
                TextDocument = new LSP.TextDocumentIdentifier()
                {
                    Uri = DocumentUri,
                },
                Position = GetDocumentPosition(position),
                Context  = context,
            };

            var res = await _client.InvokeTextDocumentCompletionAsync(completionParams, token);

            return(res);
        }
Exemplo n.º 7
0
 public async Task <object> GetAnalysisCompletions(LSP.Position position, LSP.CompletionContext context, CancellationToken token)
 {
     return((await(_evaluator as IPythonInteractiveIntellisense)?.GetAnalysisCompletions(position, context, token))
            ?? Array.Empty <LSP.CompletionItem>());
 }
Exemplo n.º 8
0
 public static LinePosition PositionToLinePosition(LSP.Position position)
 {
     return(new LinePosition(position.Line, position.Character));
 }
Exemplo n.º 9
0
 public static LinePosition PositionToLinePosition(LSP.Position position)
 => new LinePosition(position.Line, position.Character);
Exemplo n.º 10
0
 public Task <object> GetAnalysisCompletions(LSP.Position triggerPoint, LSP.CompletionContext context, CancellationToken token)
 {
     // No analysis completions for debug repl
     return(Task.FromResult <object>(null));
 }
Exemplo n.º 11
0
        internal static SnapshotPoint GetSnapshotPositionFromProtocolPosition(this ITextSnapshot textSnapshot, LSP.Position position)
        {
            var snapshotPosition = textSnapshot.GetLineFromLineNumber(position.Line).Start + position.Character;

            return(new SnapshotPoint(textSnapshot, snapshotPosition));
        }