Skip to content

Fix DocumentSymbol Json Converter #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2020
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