-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -489,10 +489,22 @@ class DottyLanguageServer extends LanguageServer | |
|
||
val uriTrees = driver.openedTrees(uri) | ||
|
||
val defs = Interactive.namedTrees(uriTrees, Include.empty) | ||
// Excludes locals from synthetic symbols (with the exception of enums members) | ||
// and erroroneous trees. | ||
val excludeLocalsFromSyntheticSymbols = (n: NameTree) => { | ||
val owner = n.symbol.owner | ||
n.symbol.is(Case) || { | ||
n.name != StdNames.nme.ERROR && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's the best way to deal with the error trees produced by Parser currently, typed error trees should already be handled.
I guess we'll have to run the tests and see :). |
||
!owner.is(Synthetic) && | ||
!owner.isPrimaryConstructor | ||
} | ||
} | ||
|
||
val defs = Interactive.namedTrees(uriTrees, Include.local, excludeLocalsFromSyntheticSymbols) | ||
|
||
(for { | ||
d <- defs if !isWorksheetWrapper(d) | ||
info <- symbolInfo(d.tree.symbol, d.namePos) | ||
d <- defs if (!isWorksheetWrapper(d) && !isTopLevelWrapper(d)) | ||
info <- symbolInfo(d.tree.symbol, d.pos) | ||
} yield JEither.forLeft(info)).asJava | ||
} | ||
|
||
|
@@ -808,6 +820,14 @@ object DottyLanguageServer { | |
symbol.owner == ctx.definitions.EmptyPackageClass | ||
} | ||
|
||
/** | ||
* Is this symbol the wrapper object for top level definitions? | ||
*/ | ||
def isTopLevelWrapper(sourceTree: SourceTree)(implicit ctx: Context): Boolean = { | ||
val symbol = sourceTree.tree.symbol | ||
symbol.isPackageObject | ||
} | ||
|
||
/** Create an lsp4j.CompletionItem from a completion result */ | ||
def completionItem(completion: Completion)(implicit ctx: Context): lsp4j.CompletionItem = { | ||
def completionItemKind(sym: Symbol)(implicit ctx: Context): lsp4j.CompletionItemKind = { | ||
|
@@ -883,24 +903,34 @@ object DottyLanguageServer { | |
SK.Constructor | ||
else if (sym.is(Module)) | ||
SK.Module | ||
else if (sym.isAllOf(EnumCase) || sym.isAllOf(EnumValue)) | ||
SK.EnumMember | ||
else if (sym.is(Enum)) | ||
SK.Enum | ||
else if (sym.is(Trait)) | ||
SK.Interface | ||
else if (sym.isClass) | ||
SK.Class | ||
else if (sym.is(Mutable)) | ||
SK.Variable | ||
else if (sym.is(Method)) | ||
SK.Method | ||
else if (sym.is(TypeParam) || sym.isAbstractOrAliasType) | ||
SK.TypeParameter | ||
else | ||
SK.Field | ||
} | ||
def containerName(sym: Symbol): String = { | ||
val owner = if (sym.owner.exists && sym.owner.isPackageObject) sym.owner.owner else sym.owner | ||
if (owner.exists && !owner.isEmptyPackage) { | ||
owner.name.stripModuleClassSuffix.show | ||
} else | ||
null | ||
} | ||
|
||
val name = sym.name.stripModuleClassSuffix.show | ||
val containerName = | ||
if (sym.owner.exists && !sym.owner.isEmptyPackage) | ||
sym.owner.name.show | ||
else | ||
null | ||
|
||
location(pos).map(l => new lsp4j.SymbolInformation(name, symbolKind(sym), l, containerName)) | ||
location(pos).map(l => new lsp4j.SymbolInformation(name, symbolKind(sym), l, containerName(sym))) | ||
} | ||
|
||
/** Convert `signature` to a `SignatureInformation` */ | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
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:
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.
Makes sense. I'm going to commit this soon with the change below.