public static async Task <ILanguageClient> StartServerWithText(string text, DocumentUri uri, Action <LanguageClientOptions>?onClientOptions = null) { var diagnosticsPublished = new TaskCompletionSource <PublishDiagnosticsParams>(); var client = await IntegrationTestHelper.StartServerWithClientConnection(options => { onClientOptions?.Invoke(options); options.OnPublishDiagnostics(p => diagnosticsPublished.SetResult(p)); }); // send open document notification client.DidOpenTextDocument(TextDocumentParamHelper.CreateDidOpenDocumentParams(uri, text, 0)); // notifications don't produce responses, // but our server should send us diagnostics when it receives the notification await IntegrationTestHelper.WithTimeout(diagnosticsPublished.Task); return(client); }
public async Task RequestDocumentSymbol_should_return_full_symbol_list() { var documentUri = DocumentUri.From("/template.bicep"); var diagsReceived = new TaskCompletionSource <PublishDiagnosticsParams>(); var client = await IntegrationTestHelper.StartServerWithClientConnection(options => { options.OnPublishDiagnostics(diags => { diagsReceived.SetResult(diags); }); }); // client opens the document client.TextDocument.DidOpenTextDocument(new DidOpenTextDocumentParams { TextDocument = new TextDocumentItem { LanguageId = "bicep", Version = 0, Uri = documentUri, Text = @" param myParam string = 'test' resource myRes 'myRp/provider@2019-01-01' = { name = 'test' } output myOutput string = 'myOutput' ", }, }); // client requests symbols var symbols = await client.TextDocument.RequestDocumentSymbol(new DocumentSymbolParams { TextDocument = new TextDocumentIdentifier { Uri = documentUri, }, }); symbols.Should().SatisfyRespectively( x => { x.DocumentSymbol.Name.Should().Be("myParam"); x.DocumentSymbol.Kind.Should().Be(SymbolKind.Field); x.DocumentSymbol.Range.Should().HaveRange((1, 0), (2, 0)); }, x => { x.DocumentSymbol.Name.Should().Be("myRes"); x.DocumentSymbol.Kind.Should().Be(SymbolKind.Object); x.DocumentSymbol.Range.Should().HaveRange((2, 0), (5, 0)); }, x => { x.DocumentSymbol.Name.Should().Be("myOutput"); x.DocumentSymbol.Kind.Should().Be(SymbolKind.Interface); x.DocumentSymbol.Range.Should().HaveRange((5, 2), (6, 0)); } ); // client deletes the output and renames the resource client.TextDocument.DidChangeTextDocument(new DidChangeTextDocumentParams { TextDocument = new VersionedTextDocumentIdentifier { Version = 1, Uri = documentUri, }, ContentChanges = new Container <TextDocumentContentChangeEvent>( // for now we're sending the full document every time, nothing fancy.. new TextDocumentContentChangeEvent { Text = @" param myParam string = 'test' resource myRenamedRes 'myRp/provider@2019-01-01' = { name = 'test' } ", } ) }); // client requests symbols symbols = await client.TextDocument.RequestDocumentSymbol(new DocumentSymbolParams { TextDocument = new TextDocumentIdentifier { Uri = documentUri, }, }); symbols.Should().SatisfyRespectively( x => { x.DocumentSymbol.Name.Should().Be("myParam"); x.DocumentSymbol.Kind.Should().Be(SymbolKind.Field); x.DocumentSymbol.Range.Should().HaveRange((1, 0), (2, 0)); }, x => { x.DocumentSymbol.Name.Should().Be("myRenamedRes"); x.DocumentSymbol.Kind.Should().Be(SymbolKind.Object); x.DocumentSymbol.Range.Should().HaveRange((2, 0), (5, 0)); } ); }
public async Task RequestDocumentSymbol_should_return_full_symbol_list() { var documentUri = DocumentUri.From("/template.bicep"); var diagsReceived = new TaskCompletionSource <PublishDiagnosticsParams>(); var client = await IntegrationTestHelper.StartServerWithClientConnection(options => { options.OnPublishDiagnostics(diags => { diagsReceived.SetResult(diags); }); }); // client opens the document client.TextDocument.DidOpenTextDocument(TextDocumentParamHelper.CreateDidOpenDocumentParams(documentUri, @" param myParam string = 'test' resource myRes 'myRp/provider@2019-01-01' = { name = 'test' } output myOutput string = 'myOutput' ", 0)); // client requests symbols var symbols = await client.TextDocument.RequestDocumentSymbol(new DocumentSymbolParams { TextDocument = new TextDocumentIdentifier { Uri = documentUri, }, }); symbols.Should().SatisfyRespectively( x => { x.DocumentSymbol.Name.Should().Be("myParam"); x.DocumentSymbol.Kind.Should().Be(SymbolKind.Field); x.DocumentSymbol.Range.Should().HaveRange((1, 0), (1, 29)); }, x => { x.DocumentSymbol.Name.Should().Be("myRes"); x.DocumentSymbol.Kind.Should().Be(SymbolKind.Object); x.DocumentSymbol.Range.Should().HaveRange((2, 0), (4, 3)); }, x => { x.DocumentSymbol.Name.Should().Be("myOutput"); x.DocumentSymbol.Kind.Should().Be(SymbolKind.Interface); x.DocumentSymbol.Range.Should().HaveRange((5, 2), (5, 37)); } ); // client deletes the output and renames the resource client.TextDocument.DidChangeTextDocument(TextDocumentParamHelper.CreateDidChangeTextDocumentParams(documentUri, @" param myParam string = 'test' resource myRenamedRes 'myRp/provider@2019-01-01' = { name = 'test' } ", 1)); // client requests symbols symbols = await client.TextDocument.RequestDocumentSymbol(new DocumentSymbolParams { TextDocument = new TextDocumentIdentifier { Uri = documentUri, }, }); symbols.Should().SatisfyRespectively( x => { x.DocumentSymbol.Name.Should().Be("myParam"); x.DocumentSymbol.Kind.Should().Be(SymbolKind.Field); x.DocumentSymbol.Range.Should().HaveRange((1, 0), (1, 29)); }, x => { x.DocumentSymbol.Name.Should().Be("myRenamedRes"); x.DocumentSymbol.Kind.Should().Be(SymbolKind.Object); x.DocumentSymbol.Range.Should().HaveRange((2, 0), (4, 3)); } ); }
public async Task DidOpenTextDocument_should_trigger_PublishDiagnostics() { var documentUri = DocumentUri.From("/template.bicep"); var diagsReceived = new TaskCompletionSource <PublishDiagnosticsParams>(); var client = await IntegrationTestHelper.StartServerWithClientConnection(options => { options.OnPublishDiagnostics(diags => { diagsReceived.SetResult(diags); }); }); // open document client.TextDocument.DidOpenTextDocument(TextDocumentParamHelper.CreateDidOpenDocumentParams(documentUri, @" param myParam string = 2 resource myRes 'invalidFormat' = { } randomToken ", 1)); var response = await IntegrationTestHelper.WithTimeout(diagsReceived.Task); response.Diagnostics.Should().SatisfyRespectively( d => { d.Range.Should().HaveRange((1, 23), (1, 24)); d.Should().HaveCodeAndSeverity("BCP027", DiagnosticSeverity.Error); }, d => { d.Range.Should().HaveRange((2, 15), (2, 30)); d.Should().HaveCodeAndSeverity("BCP029", DiagnosticSeverity.Error); }, d => { d.Range.Should().HaveRange((5, 0), (5, 11)); d.Should().HaveCodeAndSeverity("BCP007", DiagnosticSeverity.Error); } ); // change document diagsReceived = new TaskCompletionSource <PublishDiagnosticsParams>(); client.TextDocument.DidChangeTextDocument(TextDocumentParamHelper.CreateDidChangeTextDocumentParams(documentUri, @" param myParam string = 'fixed!' resource myRes 'invalidFormat' = { } randomToken ", 2)); response = await IntegrationTestHelper.WithTimeout(diagsReceived.Task); response.Diagnostics.Should().SatisfyRespectively( d => { d.Range.Should().HaveRange((2, 15), (2, 30)); d.Should().HaveCodeAndSeverity("BCP029", DiagnosticSeverity.Error); }, d => { d.Range.Should().HaveRange((5, 0), (5, 11)); d.Should().HaveCodeAndSeverity("BCP007", DiagnosticSeverity.Error); } ); // close document diagsReceived = new TaskCompletionSource <PublishDiagnosticsParams>(); client.TextDocument.DidCloseTextDocument(TextDocumentParamHelper.CreateDidCloseTextDocumentParams(documentUri, 3)); response = await IntegrationTestHelper.WithTimeout(diagsReceived.Task); response.Diagnostics.Should().BeEmpty(); }
public async Task DidOpenTextDocument_should_trigger_PublishDiagnostics() { var documentUri = DocumentUri.From("/template.bicep"); var diagsReceived = new TaskCompletionSource <PublishDiagnosticsParams>(); var client = await IntegrationTestHelper.StartServerWithClientConnection(options => { options.OnPublishDiagnostics(diags => { diagsReceived.SetResult(diags); }); }); client.TextDocument.DidOpenTextDocument(new DidOpenTextDocumentParams { TextDocument = new TextDocumentItem { LanguageId = "bicep", Version = 1, Uri = documentUri, Text = @" param myParam string = 2 resource myRes 'invalidFormat' = { } randomToken ", }, }); var response = await IntegrationTestHelper.WithTimeout(diagsReceived.Task); response.Diagnostics.Should().SatisfyRespectively( d => { d.Range.Should().HaveRange((1, 23), (1, 24)); d.Should().HaveCodeAndSeverity("BCP027", DiagnosticSeverity.Error); }, d => { d.Range.Should().HaveRange((2, 15), (2, 30)); d.Should().HaveCodeAndSeverity("BCP029", DiagnosticSeverity.Error); }, d => { d.Range.Should().HaveRange((5, 0), (5, 11)); d.Should().HaveCodeAndSeverity("BCP007", DiagnosticSeverity.Error); } ); diagsReceived = new TaskCompletionSource <PublishDiagnosticsParams>(); client.TextDocument.DidChangeTextDocument(new DidChangeTextDocumentParams { TextDocument = new VersionedTextDocumentIdentifier { Version = 2, Uri = documentUri, }, ContentChanges = new Container <TextDocumentContentChangeEvent>( new TextDocumentContentChangeEvent { Text = @" param myParam string = 'fixed!' resource myRes 'invalidFormat' = { } randomToken ", } ), }); response = await IntegrationTestHelper.WithTimeout(diagsReceived.Task); response.Diagnostics.Should().SatisfyRespectively( d => { d.Range.Should().HaveRange((2, 15), (2, 30)); d.Should().HaveCodeAndSeverity("BCP029", DiagnosticSeverity.Error); }, d => { d.Range.Should().HaveRange((5, 0), (5, 11)); d.Should().HaveCodeAndSeverity("BCP007", DiagnosticSeverity.Error); } ); }