-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix detection of nested symbols in Document Outline #68107
Conversation
{ | ||
var parentRange = ProtocolConversions.RangeToLinePositionSpan(parent.Range); | ||
var childRange = ProtocolConversions.RangeToLinePositionSpan(child.Range); | ||
return childRange.Start > parentRange.Start && childRange.End <= parentRange.End; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 This is a move from comparing line number to comparing position number. Since the LSP Position
type didn't support the comparison, we convert to a Roslyn TextPosition
which provides the >
and <=
operators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh jeez. yeah.
@@ -194,9 +194,12 @@ public static LSP.VersionedTextDocumentIdentifier DocumentToVersionedTextDocumen | |||
public static LinePosition PositionToLinePosition(LSP.Position position) | |||
=> new LinePosition(position.Line, position.Character); | |||
|
|||
public static LinePositionSpan RangeToLinePositionSpan(LSP.Range range) | |||
=> new(PositionToLinePosition(range.Start), PositionToLinePosition(range.End)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 This is a restoration of a helper method that was recently removed in #68081 due to lack of use
@@ -107,7 +107,7 @@ protected async Task<DocumentOutlineTestMocks> CreateMocksAsync(string code) | |||
async Task<ManualInvocationResponse?> RequestAsync(ITextBuffer textBuffer, Func<JToken, bool> capabilitiesFilter, string languageServerName, string method, Func<ITextSnapshot, JToken> parameterFactory, CancellationToken cancellationToken) | |||
{ | |||
var request = parameterFactory(textBuffer.CurrentSnapshot).ToObject<RoslynDocumentSymbolParams>(); | |||
var response = await testLspServer.ExecuteRequestAsync<RoslynDocumentSymbolParams, DocumentSymbol[]>(method, request!, cancellationToken); | |||
var response = await testLspServer.ExecuteRequestAsync<RoslynDocumentSymbolParams, object[]>(method, request!, cancellationToken); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 The tests took longer than expected to write because this mock isn't the real call and didn't match the signature of the real call:
roslyn/src/Features/LanguageServer/Protocol/Handler/Symbols/DocumentSymbolsHandler.cs
Line 41 in 1497e87
public async Task<object[]> HandleRequestAsync(RoslynDocumentSymbolParams request, RequestContext context, CancellationToken cancellationToken) |
The use of DocumentSymbol[]
was forcing it to serialize DocumentSymbol
items, which is a base type of the actual RoslynDocumentSymbol
items contained in this array, so all the items in the tests failed to have the Glyph
property set.
Fixes #66012
Fixes #66473