Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public override SymbolInformationOrDocumentSymbol ReadJson(JsonReader reader, Ty
{
var result = JObject.Load(reader);

// Commands have a name, CodeActions do not
if (result["location"].Type == JTokenType.Object)
// SymbolInformation has property location, DocumentSymbol does not.
if (result["location"] != null)
{
return new SymbolInformationOrDocumentSymbol(result.ToObject<SymbolInformation>());
}
Expand Down
50 changes: 50 additions & 0 deletions test/Client.Tests/ClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,56 @@ public async Task DocumentHighlights_Success()
});
}

/// <summary>
/// Ensure that the language client can successfully request DocumentHighlight.
/// </summary>
[Fact(DisplayName = "Language client can successfully request document symbols")]
public async Task DocumentSymbols_DocumentSymbol_Success()
{
await Connect();

const int line = 5;
const int character = 6;
var expectedDocumentPath = AbsoluteDocumentPath;
var expectedDocumentUri = DocumentUri.FromFileSystemPath(expectedDocumentPath);
var detail = "some detail";

var documentSymbol = new DocumentSymbol {
Detail = detail,
Kind = SymbolKind.Class,
Range = new Range(new Position(line, character), new Position(line, character))
};
var expectedSymbols = new SymbolInformationOrDocumentSymbolContainer(
new SymbolInformationOrDocumentSymbol(documentSymbol));

ServerDispatcher.HandleRequest<DocumentSymbolParams, SymbolInformationOrDocumentSymbolContainer>(DocumentNames.DocumentSymbol, (request, cancellationToken) => {
Assert.NotNull(request.TextDocument);

Assert.Equal(expectedDocumentUri, request.TextDocument.Uri);

return Task.FromResult(expectedSymbols);
});
var documentSymbolParams = new DocumentSymbolParams {
TextDocument = new TextDocumentIdentifier(expectedDocumentUri)
};
var symbols = await LanguageClient.SendRequest<SymbolInformationOrDocumentSymbolContainer>(DocumentNames.DocumentSymbol, documentSymbolParams);

var actualSymbols = symbols.ToArray();
Assert.Collection(actualSymbols, actualSymbol => {
var expectedSymbol = expectedSymbols.Single();

Assert.True(expectedSymbol.IsDocumentSymbol);

Assert.NotNull(actualSymbol.DocumentSymbol);
Assert.Equal(expectedSymbol.DocumentSymbol.Detail, actualSymbol.DocumentSymbol.Detail);
Assert.Equal(expectedSymbol.DocumentSymbol.Kind, actualSymbol.DocumentSymbol.Kind);
Assert.Equal(expectedSymbol.DocumentSymbol.Range.Start.Line, actualSymbol.DocumentSymbol.Range.Start.Line);
Assert.Equal(expectedSymbol.DocumentSymbol.Range.Start.Character, actualSymbol.DocumentSymbol.Range.Start.Character);
Assert.Equal(expectedSymbol.DocumentSymbol.Range.End.Line, actualSymbol.DocumentSymbol.Range.End.Line);
Assert.Equal(expectedSymbol.DocumentSymbol.Range.End.Character, actualSymbol.DocumentSymbol.Range.End.Character);
});
}

/// <summary>
/// Ensure that the language client can successfully request FoldingRanges.
/// </summary>
Expand Down