Skip to content

Fixes #7673: document symbol responses by language server #7674

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

Conversation

andreamocci
Copy link
Contributor

As described in #7673, this PR fixes the document symbol responses in the language server.

  • Fixed range of symbols (using symbol position and not symbol name position), thus enabling breadcrumbs
  • Removed top level container object from the returned symbols
  • Improved symbol kinds (added enums, enum value/cases, traits as interfaces, and type params/fields)
  • Added local members (as in metals)
  • Fixed container names (stripping the module class suffix)

Screenshot of breadcrumbs working:
Breadcrumbs working

As a side modification, we found that in Typer.scala there is a likely missing Synthetic flag for the anon class.

- Fixed range of symbols (using symbol position and not symbol name position)
- Removed top level container object
- Improved symbol kinds (added enums, enum value/cases, traits as interfaces, and type params/fields)
- Added local members
- Fixed container names (stripping the module class suffix)
Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

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

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Commit Messages

We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).

Please stick to these guidelines for commit messages:

  1. Separate subject from body with a blank line
  2. When fixing an issue, start your commit message with Fix #<ISSUE-NBR>:
  3. Limit the subject line to 72 characters
  4. Capitalize the subject line
  5. Do not end the subject line with a period
  6. Use the imperative mood in the subject line ("Add" instead of "Added")
  7. Wrap the body at 80 characters
  8. Use the body to explain what and why vs. how

adapted from https://chris.beams.io/posts/git-commit

Have an awesome day! ☀️

@smarter
Copy link
Member

smarter commented Dec 3, 2019

There's a few test failures:

[error] Failed tests:
[error] 	dotty.tools.languageserver.WorksheetTest
[error] 	dotty.tools.languageserver.DocumentSymbolTest

You can run one of them from sbt like this:

> dotty-language-server/testOnly *WorksheetTest

Or to run a single test method:

> dotty-language-server/testOnly *WorksheetTest -- *worksheetDocumentSymbol

Let me know if you need help updating the tests.

@andreamocci
Copy link
Contributor Author

@smarter Thank you, and apologies for these failures. Indeed, these are expected failures since I didn't change any test (I've run just a plain sbt test). I've realized that too late. I've looked at the tests now and I am pretty confident I understood how they work (the interpolators for code markers are pretty amazing, by the way).
I have done the fixes but I'm going to check them again tomorrow morning before committing, and definitely add a few new ones that exercise and elicit the things I've changed.

- Fix failing tests in dotty.tools.languageserver.WorksheetTest
- Fix failing tests in dotty.tools.languageserver.DocumentSymbolTest
- Add tests for top-level decls, enums, type params in DocumentSymbolTest
- Remove erroneous trees and empty owner from document symbols
// and erroroneous trees.
val excludeLocalsFromSyntheticSymbols = (n: NameTree) => {
val owner = n.symbol.owner
n.symbol.is(Case) || {
Copy link
Member

@smarter smarter Dec 4, 2019

Choose a reason for hiding this comment

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

I think this makes too many assumptions about which trees to include or not, there might be non-synthetic definitions inside synthetic trees in other places than enums. It might not be enough but as a first step maybe we can just exclude type and term parameters of synthetic definitions:

Suggested change
n.symbol.is(Case) || {
!n.symbol.is(Param) || {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I'm going to commit this soon with the change below.

val excludeLocalsFromSyntheticSymbols = (n: NameTree) => {
val owner = n.symbol.owner
n.symbol.is(Case) || {
n.name != StdNames.nme.ERROR &&
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we ever want to return these ERROR trees, so we could add this check to the ones we do by default in https://github.com/lampepfl/dotty/blob/3a7dfd2c14e1bc146f79faef8fcad42efadcdaeb/compiler/src/dotty/tools/dotc/interactive/Interactive.scala#L187

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to move the condition. I wasn't sure this was the best way to check for an erroneous tree. Can you confirm this? Does this change impact tests other than the language server / worksheets?

Copy link
Member

Choose a reason for hiding this comment

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

I wasn't sure this was the best way to check for an erroneous tree. Can you confirm this?

It's the best way to deal with the error trees produced by Parser currently, typed error trees should already be handled.

Does this change impact tests other than the language server / worksheets?

I guess we'll have to run the tests and see :).

- Exclude type and term parameters of synthetic definitions
- Exclude erroneous trees from Interactive.namedTrees traverser
@smarter smarter self-assigned this Dec 9, 2019
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@smarter smarter merged commit d0a0b83 into scala:master Dec 10, 2019
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.

3 participants