public static void RegisterVSInternalExtensionConverters(this LspSerializer serializer)
        {
            if (serializer is null)
            {
                throw new ArgumentNullException(nameof(serializer));
            }

            // In all of the below we add our converters to both the serializer settings and the actual
            // JsonSerializer. The reasoning behind this choice is that OmniSharp framework is not consistent
            // in using one over the other so we want to protect ourselves.

            // We create a temporary serializer because the VS API's only have extension methods for adding converters to the top-level serializer type; therefore,
            // we effectively create a bag that the VS APIs can add to and then extract the added converters to add to the LSP serializer.
            var tempSerializer = new JsonSerializer();

            tempSerializer.Converters.Clear();
            tempSerializer.AddVSInternalExtensionConverters();

            var converters = tempSerializer.Converters;

            for (var i = 0; i < converters.Count; i++)
            {
                AddConverter(serializer, converters[i]);
            }
        }
Example #2
0
        public void SimpleTest(string expected)
        {
            var model = new TextDocumentEdit {
                TextDocument = new OptionalVersionedTextDocumentIdentifier {
                    Version = 1,
                    Uri     = new Uri("file:///abc/123/d.cs"),
                },
                Edits = new[] {
                    new TextEdit {
                        NewText = "new text",
                        Range   = new Range(new Position(1, 1), new Position(2, 2))
                    },
                    new TextEdit {
                        NewText = "new text2",
                        Range   = new Range(new Position(3, 3), new Position(4, 4))
                    }
                }
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

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

            deresult.Should().BeEquivalentTo(model, x => x.UsingStructuralRecordEquality());
        }
        public void SimpleTest(string expected)
        {
            var model = new CodeActionRegistrationOptions {
                DocumentSelector = new DocumentSelector(
                    new DocumentFilter {
                    Language = "csharp",
                    Pattern  = "pattern",
                    Scheme   = "scheme"
                }, new DocumentFilter {
                    Language = "vb",
                    Pattern  = "pattern",
                    Scheme   = "scheme"
                }
                    ),
                CodeActionKinds = new[] {
                    CodeActionKind.QuickFix,
                    CodeActionKind.Refactor,
                    CodeActionKind.RefactorExtract,
                    CodeActionKind.RefactorInline,
                    CodeActionKind.RefactorRewrite,
                    CodeActionKind.Source,
                    CodeActionKind.SourceOrganizeImports
                }
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

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

            deresult.Should().BeEquivalentTo(model);
        }
Example #4
0
        public void RegionTest()
        {
            var serializer = new LspSerializer();
            var json       = serializer.SerializeObject(FoldingRangeKind.Region);

            json.Should().Be("\"region\"");
        }
        public void SimpleTest(string expected)
        {
            var model = new CodeActionParams {
                Context = new CodeActionContext {
                    Diagnostics = new[] {
                        new Diagnostic {
                            Code     = new DiagnosticCode("abcd"),
                            Message  = "message",
                            Range    = new Range(new Position(1, 1), new Position(2, 2)),
                            Severity = DiagnosticSeverity.Error,
                            Source   = "csharp"
                        }
                    }
                },
                Range        = new Range(new Position(1, 1), new Position(2, 2)),
                TextDocument = new TextDocumentIdentifier {
                    Uri = new Uri("file:///test/123/d.cs")
                }
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

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

            deresult.Should().BeEquivalentTo(model);
        }
Example #6
0
        public void CustomBehavior_When_SymbolKind_Defined_By_Client()
        {
            var serializer = new LspSerializer();

            serializer.SetClientCapabilities(
                new ClientCapabilities {
                TextDocument = new TextDocumentClientCapabilities {
                    CodeAction = new Supports <CodeActionCapability?>(
                        true, new CodeActionCapability {
                        DynamicRegistration      = true,
                        CodeActionLiteralSupport = new CodeActionLiteralSupportOptions {
                            CodeActionKind = new CodeActionKindCapabilityOptions {
                                ValueSet = new Container <CodeActionKind>(CodeActionKind.RefactorInline)
                            }
                        }
                    }
                        )
                }
            }
                );

            var json = serializer.SerializeObject(
                new CodeAction {
                Kind = CodeActionKind.QuickFix
            }
                );

            var result = serializer.DeserializeObject <CodeAction>(json);

            result.Kind.Should().Be(CodeActionKind.RefactorInline);
        }
Example #7
0
        public void SimpleTest(string expected)
        {
            var model = new WorkspaceClientCapabilities {
                ApplyEdit     = true,
                WorkspaceEdit = new WorkspaceEditCapability {
                    DocumentChanges = true
                },
                DidChangeConfiguration = new DidChangeConfigurationCapability {
                    DynamicRegistration = true
                },
                DidChangeWatchedFiles = new DidChangeWatchedFilesCapability {
                    DynamicRegistration = true
                },
                ExecuteCommand = new ExecuteCommandCapability {
                    DynamicRegistration = true
                },
                Symbol = new WorkspaceSymbolCapability {
                    DynamicRegistration = true
                },
            };

            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

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

            deresult.Should().BeEquivalentTo(model, o => o.ConfigureForSupports(Logger));
        }
Example #8
0
        public void CustomBehavior_When_SymbolKind_Defined_By_Client()
        {
            var serializer = new LspSerializer();

            serializer.SetClientCapabilities(
                new ClientCapabilities {
                Workspace = new WorkspaceClientCapabilities {
                    Symbol = new Supports <WorkspaceSymbolCapability?>(
                        true, new WorkspaceSymbolCapability {
                        DynamicRegistration = true,
                        SymbolKind          = new SymbolKindCapabilityOptions {
                            ValueSet = new Container <SymbolKind>(SymbolKind.Class)
                        }
                    }
                        )
                }
            }
                );
            var json = serializer.SerializeObject(
                new SymbolInformation {
                Kind = SymbolKind.Event
            }
                );

            var result = serializer.DeserializeObject <SymbolInformation>(json);

            result.Kind.Should().Be(SymbolKind.Class);
        }
Example #9
0
        public void NonStandardCharactersTest(string expected)
        {
            var model = new ApplyWorkspaceEditParams {
                Edit = new WorkspaceEdit {
                    Changes = new Dictionary <DocumentUri, IEnumerable <TextEdit> > {
                        {
                            // Mörkö
                            new Uri("file:///abc/bc/123/M%C3%B6rk%C3%B6.cs"), new[] {
                                new TextEdit {
                                    NewText = "new text",
                                    Range   = new Range(new Position(1, 1), new Position(2, 2))
                                },
                                new TextEdit {
                                    NewText = "new text2",
                                    Range   = new Range(new Position(3, 3), new Position(4, 4))
                                }
                            }
                        }
                    }
                }
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

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

            deresult.Should().BeEquivalentTo(model, x => x.UsingStructuralRecordEquality());
        }
Example #10
0
        public void RelatedInformationTest(string expected)
        {
            var model = new Diagnostic {
                Code               = new DiagnosticCode("abcd"),
                Message            = "message",
                Range              = new Range(new Position(1, 1), new Position(2, 2)),
                Severity           = DiagnosticSeverity.Error,
                Source             = "csharp",
                RelatedInformation = new Container <DiagnosticRelatedInformation>(
                    new DiagnosticRelatedInformation {
                    Location = new Location {
                        Uri   = new Uri("file:///abc/def.cs"),
                        Range = new Range(new Position(1, 2), new Position(3, 4))
                    },
                    Message = "related message 1"
                },
                    new DiagnosticRelatedInformation {
                    Location = new Location {
                        Uri   = new Uri("file:///def/ghi.cs"),
                        Range = new Range(new Position(5, 6), new Position(7, 8))
                    },
                    Message = "related message 2"
                }
                    )
            };

            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

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

            deresult.Should().BeEquivalentTo(model, x => x.UsingStructuralRecordEquality());
        }
Example #11
0
        public void TagSupportObject()
        {
            var deresult = new LspSerializer(ClientVersion.Lsp3).DeserializeObject <PublishDiagnosticsCapability>("{\"tagSupport\":{\"valueSet\": [2,1]}}");

            deresult.TagSupport.IsSupported.Should().Be(true);
            deresult.TagSupport.Value !.ValueSet.Should().ContainInOrder(DiagnosticTag.Deprecated, DiagnosticTag.Unnecessary);
        }
        public void CustomBehavior_When_CompletionItemKinds_Defined_By_Client()
        {
            var serializer = new LspSerializer();

            serializer.SetClientCapabilities(
                new ClientCapabilities {
                TextDocument = new TextDocumentClientCapabilities {
                    Completion = new Supports <CompletionCapability?>(
                        true, new CompletionCapability {
                        DynamicRegistration = true,
                        CompletionItemKind  = new CompletionItemKindCapabilityOptions {
                            ValueSet = new Container <CompletionItemKind>(CompletionItemKind.Class)
                        }
                    }
                        )
                }
            }
                );

            var json = serializer.SerializeObject(
                new CompletionItem {
                Kind = CompletionItemKind.Event
            }
                );

            var result = serializer.DeserializeObject <CompletionItem>(json);

            result.Kind.Should().Be(CompletionItemKind.Class);
        }
        public void CustomBehavior_When_SymbolKind_Defined_By_Server()
        {
            var serializer = new LspSerializer();

            serializer.SetServerCapabilities(
                new ServerCapabilities {
                SemanticTokensProvider = new SemanticTokensRegistrationOptions.StaticOptions()
                {
                    Full = new SemanticTokensCapabilityRequestFull {
                        Delta = true
                    },
                    Legend = new SemanticTokensLegend {
                        TokenModifiers = new Container <SemanticTokenModifier>(SemanticTokenModifier.Deprecated),
                        TokenTypes     = new Container <SemanticTokenType>(SemanticTokenType.Comment),
                    },
                    Range = new SemanticTokensCapabilityRequestRange(),
                }
            }
                );

            var json = serializer.SerializeObject(
                new SemanticTokensLegend {
                TokenModifiers = new Container <SemanticTokenModifier>(SemanticTokenModifier.Deprecated),
                TokenTypes     = new Container <SemanticTokenType>(SemanticTokenType.Comment),
            }
                );

            var result = serializer.DeserializeObject <SemanticTokensLegend>(json);

            result.TokenModifiers.FirstOrDefault().Should().Be(SemanticTokenModifier.Deprecated);
            result.TokenTypes.FirstOrDefault().Should().Be(SemanticTokenType.Comment);
        }
Example #14
0
        public void SimpleTest(string expected)
        {
            var model = new ServerCapabilities {
                CodeActionProvider = true,
                CodeLensProvider   = new CodeLensRegistrationOptions.StaticOptions {
                    ResolveProvider = true,
                },
                CompletionProvider = new CompletionRegistrationOptions.StaticOptions {
                    ResolveProvider   = true,
                    TriggerCharacters = new[] { "a", "b", "c" }
                },
                DefinitionProvider         = true,
                DocumentFormattingProvider = true,
                DocumentHighlightProvider  = true,
                DocumentLinkProvider       = new DocumentLinkRegistrationOptions.StaticOptions {
                    ResolveProvider = true
                },
                DocumentOnTypeFormattingProvider = new DocumentOnTypeFormattingRegistrationOptions.StaticOptions {
                    FirstTriggerCharacter = ".",
                    MoreTriggerCharacter  = new[] { ";", " " }
                },
                DocumentRangeFormattingProvider = true,
                DocumentSymbolProvider          = true,
                ExecuteCommandProvider          = new ExecuteCommandRegistrationOptions.StaticOptions {
                    Commands = new[] { "command1", "command2" }
                },
                Experimental = new Dictionary <string, JToken> {
                    { "abc", "123" }
                },
                HoverProvider         = true,
                ReferencesProvider    = true,
                RenameProvider        = true,
                SignatureHelpProvider = new SignatureHelpRegistrationOptions.StaticOptions {
                    TriggerCharacters = new[] { ";", " " }
                },
                TextDocumentSync = new TextDocumentSync(
                    new TextDocumentSyncOptions {
                    Change    = TextDocumentSyncKind.Full,
                    OpenClose = true,
                    Save      = new SaveOptions {
                        IncludeText = true
                    },
                    WillSave          = true,
                    WillSaveWaitUntil = true
                }
                    ),
                WorkspaceSymbolProvider = true,
                ColorProvider           = true,
                FoldingRangeProvider    = true,
                ImplementationProvider  = true,
                TypeDefinitionProvider  = true
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

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

            deresult.Should().BeEquivalentTo(model, x => x.UsingStructuralRecordEquality());
        }
        public void SimpleTest(string expected)
        {
            var model = new WorkspaceEdit {
                Changes = new Dictionary <DocumentUri, IEnumerable <TextEdit> > {
                    {
                        new Uri("file:///abc/123/d.cs"), new[] {
                            new TextEdit {
                                NewText = "new text",
                                Range   = new Range(new Position(1, 1), new Position(2, 2))
                            },
                            new TextEdit {
                                NewText = "new text2",
                                Range   = new Range(new Position(3, 3), new Position(4, 4))
                            }
                        }
                    }
                }
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

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

            deresult.Should().BeEquivalentTo(model);
        }
Example #16
0
        public void ImportsTest()
        {
            var serializer = new LspSerializer();
            var json       = serializer.SerializeObject(FoldingRangeKind.Imports);

            json.Should().Be("\"imports\"");
        }
Example #17
0
        public void SimpleTest(string expected)
        {
            var model = new SignatureHelp {
                ActiveParameter = 1,
                ActiveSignature = 2,
                Signatures      = new[] {
                    new SignatureInformation {
                        Documentation = "ab",
                        Label         = "ab",
                        Parameters    = new[] {
                            new ParameterInformation {
                                Documentation = "param",
                                Label         = "param"
                            }
                        }
                    }
                }
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

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

            deresult.Should().BeEquivalentTo(model, x => x.UsingStructuralRecordEquality());
        }
Example #18
0
        public void SimpleTest(string expected)
        {
            var model = new CodeLens
            {
                Command = new Command
                {
                    Arguments = new JArray {
                        1, "2", true
                    },
                    Name  = "abc",
                    Title = "Cool story bro"
                },
                Data = JObject.FromObject(
                    new Dictionary <string, object>
                {
                    { "somethingCool", 1 }
                }
                    ),
                Range = new Range(new Position(1, 2), new Position(2, 3)),
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            // TODO: Come back and fix this...
            var deresult = new LspSerializer(ClientVersion.Lsp3).DeserializeObject <CodeLens>(expected);

            deresult.Should().BeEquivalentTo(model, x => x.UsingStructuralRecordEquality());
        }
Example #19
0
        public void TagSupportObject()
        {
            var deresult = new LspSerializer(ClientVersion.Lsp3).DeserializeObject <CompletionItemCapabilityOptions>("{\"tagSupport\":{\"valueSet\": [1]}}");

            deresult.TagSupport.IsSupported.Should().Be(true);
            deresult.TagSupport.Value !.ValueSet.Should().Contain(CompletionItemTag.Deprecated);
        }
Example #20
0
        public void LocationLinksTest(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)),
            },
                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 LspSerializer(ClientVersion.Lsp3).DeserializeObject <LocationOrLocationLinks>(expected);

            deresult.Should().BeEquivalentTo(
                model, x => x.UsingStructuralRecordEquality()
                .ComparingByMembers <LocationOrLocationLink>()
                .ComparingByMembers <Location>()
                .ComparingByMembers <LocationLink>()
                );
        }
        public void NonStandardCharactersTest(string expected)
        {
            var model = new CodeActionParams {
                Context = new CodeActionContext {
                    Diagnostics = new[] {
                        new Diagnostic {
                            Code     = new DiagnosticCode("abcd"),
                            Message  = "message",
                            Range    = new Range(new Position(1, 1), new Position(2, 2)),
                            Severity = DiagnosticSeverity.Error,
                            Source   = "csharp"
                        }
                    }
                },
                Range        = new Range(new Position(1, 1), new Position(2, 2)),
                TextDocument = new TextDocumentIdentifier {
                    // ТаЉ - Chinese for tree
                    Uri = new Uri("file:///test/123/%E6%A0%91.cs")
                }
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

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

            deresult.Should().BeEquivalentTo(model, x => x.UsingStructuralRecordEquality());
        }
Example #22
0
        public void CommentTest()
        {
            var serializer = new LspSerializer();
            var json       = serializer.SerializeObject(FoldingRangeKind.Comment);

            json.Should().Be("\"comment\"");
        }
Example #23
0
        public void TagSupportTrue()
        {
            var deresult = new LspSerializer(ClientVersion.Lsp3).DeserializeObject <CompletionItemCapabilityOptions>("{\"tagSupport\":true}");

            deresult.Should().BeEquivalentTo(
                new CompletionItemCapabilityOptions {
                TagSupport = new Supports <CompletionItemTagSupportCapabilityOptions?>(true)
            }
                );
        }
Example #24
0
        public void Null_Text_Document_Sync(string expected)
        {
            var model = new ServerCapabilities {
                TextDocumentSync = new TextDocumentSync(new TextDocumentSyncOptions())
            };

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

            deresult.Should().BeEquivalentTo(model, x => x.UsingStructuralRecordEquality());
        }
Example #25
0
        public void TagSupportTrue()
        {
            var deresult = new LspSerializer(ClientVersion.Lsp3).DeserializeObject <PublishDiagnosticsCapability>("{\"tagSupport\":true}");

            deresult.Should().BeEquivalentTo(
                new PublishDiagnosticsCapability {
                TagSupport = new Supports <PublishDiagnosticsTagSupportCapabilityOptions?>(true)
            }
                );
        }
Example #26
0
        public void SimpleTest(string expected)
        {
            var model  = new FileChangeType();
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

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

            deresult.Should().Be(model);
        }
Example #27
0
        public void OptionalTest(string expected)
        {
            var model  = new Diagnostic();
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

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

            deresult.Should().BeEquivalentTo(model, x => x.UsingStructuralRecordEquality());
        }
Example #28
0
        public void SimpleTest(string expected)
        {
            var model  = new TextDocumentIdentifier(new Uri("file:///abc/123/d.cs"));
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

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

            deresult.Should().BeEquivalentTo(model);
        }
Example #29
0
        public void Should_AcceptAString()
        {
            var model  = new BooleanNumberString("abc");
            var result = Fixture.SerializeObject(model);

            result.Should().Be("\"abc\"");

            var deresult = new LspSerializer(ClientVersion.Lsp3).DeserializeObject <BooleanNumberString>("\"abc\"");

            deresult.Should().BeEquivalentTo(model, x => x.UsingStructuralRecordEquality());
        }
Example #30
0
        public void SimpleTest(string expected)
        {
            var model  = new UnknownErrorCode("");
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

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

            deresult.Should().BeEquivalentTo(model, x => x.UsingStructuralRecordEquality());
        }