public void ReturnDocumentTokensFromScratch()
        {
            var document = new SemanticTokensDocument(_legend);

            {
                var builder = document.Create();
                Tokenize(ExampleDocumentText, builder);
                builder.Commit();
            }

            var result = document.GetSemanticTokens();

            result.ResultId.Should().Be(document.Id);
            var data = Normalize(ExampleDocumentText, result.Data).ToArray();

            _logger.LogInformation("Some Data {Data}", data.AsEnumerable());
            var expectedResponse = new NormalizedToken[]
            {
                "using (macro:async|deprecated)", "System (macro:async|deprecated)", "using (event:none)", "System (number:none)",
                "Collections (struct:readonly)",
                "Generic (class:none)", "using (variable:modification|defaultLibrary)", "System (comment:static|deprecated)", "Linq (comment:definition)",
                "using (comment:none)",
                "System (enumMember:none)", "Text (comment:static|deprecated)", "using (comment:none)", "System (comment:declaration)",
                "Threading (comment:static|defaultLibrary)",
                "Tasks (comment:none)", "namespace (comment:readonly)", "CSharpTutorials (comment:none)", "{ (struct:documentation)", "class (enumMember:none)",
                "Program (comment:none)", "{ (comment:none)", "static (regexp:documentation)", "void (macro:none)", "Main (macro:none)",
                "string[] (property:declaration|abstract)",
                "args (macro:none)", "{ (interface:documentation|declaration|deprecated)", "string (struct:none)", "message (enum:none)", "= (label:none)",
                "Hello (comment:none)",
                "World!! (enum:none)", "Console (interface:static)", "WriteLine (event:async|modification)", "message (interface:static)", "} (operator:none)",
                "} (enum:async|deprecated)", "} (function:declaration|async)"
            };

            data.Should().ContainInOrder(expectedResponse);
        }
Beispiel #2
0
        public void ReturnDocumentTokensFromScratch()
        {
            var document = new SemanticTokensDocument(_legend);

            {
                var builder = document.Create();
                Tokenize(ExampleDocumentText, builder);
                builder.Commit();
            }

            var result = document.GetSemanticTokens();

            result.ResultId.Should().Be(document.Id);
            var data = Normalize(ExampleDocumentText, result.Data).ToArray();

            _logger.LogInformation("Some Data {Data}", data.AsEnumerable());
            var expectedResponse = new NormalizedToken[] {
                "using (member:static|abstract)", "System (member:static|abstract)", "using (parameter:none)",
                "System (string:none)", "Collections (namespace:deprecated)", "Generic (type:none)",
                "using (property:none)", "System (documentation:definition|abstract)",
                "Linq (documentation:definition)", "using (documentation:none)", "System (label:none)",
                "Text (documentation:definition|abstract)", "using (documentation:none)",
                "System (documentation:documentation)", "Threading (documentation:definition|readonly)",
                "Tasks (documentation:none)", "namespace (documentation:abstract)",
                "CSharpTutorials (documentation:none)", "{ (type:documentation)", "class (label:none)",
                "Program (documentation:none)", "{ (documentation:none)", "static (number:documentation)",
                "void (function:none)", "Main (function:none)", "string[] (function:documentation|static)",
                "args (function:none)", "{ (struct:declaration|abstract)", "string (type:none)", "message (class:none)",
                "= (macro:none)", "Hello (documentation:none)", "World!! (class:none)", "Console (struct:definition)",
                "WriteLine (parameter:definition|readonly)", "message (struct:definition)", "} (regexp:none)",
                "} (class:static|abstract)", "} (enum:declaration|definition)"
            };

            data.Should().ContainInOrder(expectedResponse);
        }
Beispiel #3
0
        public void ReturnDocumentTokensFromScratch_ForRange(Range range, IEnumerable <NormalizedToken> expectedTokens)
        {
            var document = new SemanticTokensDocument(_legend);

            {
                var builder = document.Create();
                Tokenize(ExampleDocumentText, builder);
                builder.Commit();
            }

            var result = document.GetSemanticTokens(range);

            result.ResultId.Should().Be(document.Id);
            var data = Normalize(ExtractRange(ExampleDocumentText, range), result.Data).ToArray();

            _logger.LogInformation("Some Data {Data}", data.AsEnumerable());
            data.Should().ContainInOrder(expectedTokens);
        }
        public void ReturnDocumentEdits(
            string originalText, string modifiedText,
            IEnumerable <NormalizedToken> expectedTokens
            )
        {
            var document = new SemanticTokensDocument(_legend);

            SemanticTokens originalTokens;

            {
                var builder = document.Create();
                Tokenize(originalText, builder);
                builder.Commit();
                originalTokens = document.GetSemanticTokens();
                builder        = document.Edit(
                    new SemanticTokensDeltaParams
                {
                    PreviousResultId = document.Id,
                }
                    );
                Tokenize(modifiedText, builder);
                builder.Commit();
            }

            var result = document.GetSemanticTokensEdits();

            result.IsDelta.Should().BeTrue();
            var edits = result.Delta !;

            edits.ResultId.Should().Be(document.Id);
            edits.Edits.Should().HaveCount(1);
            var edit1 = edits.Edits.First();

            var edit1Tokens = originalTokens.Data
                              .RemoveRange(edit1.Start, edit1.DeleteCount)
                              .InsertRange(edit1.Start, edit1.Data !);

            var edit1Data = Normalize(modifiedText, edit1Tokens).ToArray();

            _logger.LogDebug("Some Data {Data}", edit1Data.AsEnumerable());
            edit1Data.Should().ContainInOrder(expectedTokens);
        }