Skip to content
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

[READY] Add support for DocumentSymbol in document outline requests #1757

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

bstaletic
Copy link
Collaborator

@bstaletic bstaletic commented Aug 16, 2024

I'm not too happy about this.
Omnisharp LSP assumes clients support this.
We could, but it comes at the cost of manually flattening the hierarchy. That's what this pull request does.

Alternatives include:

  • Implementing this, but not advetising the capability. That way, servers that assume client support for it work, but those that don't won't have a performance impact.
  • Leave this mess out of the LanguageServerCompleter class and only add this hack into the LSP Omnisharp completer. This was done in [RFC] Switch C# completer to LSP #1752

EDIT: Switched to the first alternative, as discussed in gitter.


This change is Reviewable

@bstaletic bstaletic force-pushed the document_symbol_support branch 2 times, most recently from 77d333a to 936a5b6 Compare August 17, 2024 19:14
Copy link

codecov bot commented Aug 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.92%. Comparing base (1026c83) to head (3027d22).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1757      +/-   ##
==========================================
+ Coverage   95.90%   95.92%   +0.01%     
==========================================
  Files          84       84              
  Lines        8450     8462      +12     
  Branches      163      163              
==========================================
+ Hits         8104     8117      +13     
+ Misses        296      295       -1     
  Partials       50       50              

@bstaletic bstaletic changed the title [RFC] Add support for DocumentSymbol in document outline requests [READY] Add support for DocumentSymbol in document outline requests Aug 18, 2024
Copy link
Collaborator Author

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 LGTMs obtained


ycmd/completers/language_server/language_server_completer.py line 2659 at r1 (raw file):

    if any( 'range' in s for s in result ):
      LOGGER.debug( 'Hierarchical DocumentSymbol not supported.' )

I'm still logging this, to maybe catch another non-conforming server.


ycmd/tests/language_server/language_server_completer_test.py line 107 at r1 (raw file):

class LanguageServerCompleterTest( TestCase ):
  @IsolatedYcmd()
  def test_LanguageServerCompleter_DocumentSymbol_Hierarchical( self, app ):

This test was added just because we don't yet have a naughty server. Omnisharp would exercise this codepath properly.

@bstaletic bstaletic force-pushed the document_symbol_support branch 2 times, most recently from 0ed683b to facffef Compare August 18, 2024 07:07
Copy link
Member

@puremourning puremourning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

some bike shed comments included.

Reviewed 1 of 2 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: 1 of 2 LGTMs obtained (waiting on @bstaletic)


ycmd/completers/language_server/language_server_completer.py line 3433 at r2 (raw file):

  result = []
  for s in symbols:
    partial_results = [ s ]

if I' reading this right, partial_results doesn't do antything that results doesn't.

as in, is this not equivalent?

result = []
for s in symbols:
  result.append(s)
  result.extend(_FlattenDocumentSymbolHierarchy( s.get('children', [] ) ) )

maybe I just don't brain today.


ycmd/completers/language_server/language_server_completer.py line 3444 at r2 (raw file):

  """Convert a list of LSP DocumentSymbol into a YCM GoTo response"""

  def BuildGoToLocationFromSymbol( symbol ):

This is so similar to the same def in _SymbolListToGoTo that the diff algorithm confused the hell out of me.

Perhaps it's time to pull this out to a top-level function and save some duplication?


ycmd/tests/language_server/language_server_completer_test.py line 107 at r1 (raw file):

Previously, bstaletic (Boris Staletic) wrote…

This test was added just because we don't yet have a naughty server. Omnisharp would exercise this codepath properly.

nice. integration tests are great, but unit tests have their place too!

Copy link
Collaborator Author

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 LGTMs obtained (and 1 stale) (waiting on @puremourning)


ycmd/completers/language_server/language_server_completer.py line 3433 at r2 (raw file):

Previously, puremourning (Ben Jackson) wrote…

if I' reading this right, partial_results doesn't do antything that results doesn't.

as in, is this not equivalent?

result = []
for s in symbols:
  result.append(s)
  result.extend(_FlattenDocumentSymbolHierarchy( s.get('children', [] ) ) )

maybe I just don't brain today.

You're right. My brain just prefers to work with partial results when writing a recursive algorithm.

Fixed.


ycmd/completers/language_server/language_server_completer.py line 3444 at r2 (raw file):

Previously, puremourning (Ben Jackson) wrote…

This is so similar to the same def in _SymbolListToGoTo that the diff algorithm confused the hell out of me.

Perhaps it's time to pull this out to a top-level function and save some duplication?

Yes, the diff was confused.

Hmm... if I pull that out, then _DocumentSymbolListToGoTo and _SymbolInfoListToGoTo are exactly the same.

Please double check my implementation and the specs, because workspace symbol is also quite similar.

I did deduplicate, like you suggested.

We are intentionally not advertising the capability.
We do want a flat response, so receiving a DocumentSymbol is a
pessimisation.
Not advertising the capability means that conforming servers take the
faster code path and the likes of OmniSharp, that assume capabilities,
still work.

Yes, it's messy, but so is LSP.
Copy link
Collaborator Author

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 LGTMs obtained (and 1 stale) (waiting on @puremourning)


ycmd/completers/language_server/language_server_completer.py line 3444 at r2 (raw file):

Previously, bstaletic (Boris Staletic) wrote…

Yes, the diff was confused.

Hmm... if I pull that out, then _DocumentSymbolListToGoTo and _SymbolInfoListToGoTo are exactly the same.

Please double check my implementation and the specs, because workspace symbol is also quite similar.

I did deduplicate, like you suggested.

Well, all the tests are passing, which gives me more confidence in the changes.

Copy link
Collaborator Author

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 LGTMs obtained (and 1 stale) (waiting on @puremourning)


ycmd/completers/language_server/language_server_completer.py line 3444 at r2 (raw file):

Previously, bstaletic (Boris Staletic) wrote…

Well, all the tests are passing, which gives me more confidence in the changes.

I have rechecked the LSP specs. This implementation is fine.

@bstaletic
Copy link
Collaborator Author

I'll merge this, to progress the C# stuff.

@bstaletic bstaletic merged commit 5de7052 into ycm-core:master Aug 21, 2024
15 of 16 checks passed
@bstaletic bstaletic deleted the document_symbol_support branch August 21, 2024 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants