-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve signature help by more stable position calculation + better named arg support #19214
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 12 commits
c465c09
1a38639
811d130
f447ba2
0426165
a859a1a
83e337e
13a0dcd
0a3181d
018244f
fa584ad
676a594
6647c71
329a2eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -552,13 +552,18 @@ class DottyLanguageServer extends LanguageServer | |
override def signatureHelp(params: TextDocumentPositionParams) = computeAsync { canceltoken => | ||
val uri = new URI(params.getTextDocument.getUri) | ||
val driver = driverFor(uri) | ||
implicit def ctx: Context = driver.currentCtx | ||
|
||
val pos = sourcePosition(driver, uri, params.getPosition) | ||
val trees = driver.openedTrees(uri) | ||
val path = Interactive.pathTo(trees, pos) | ||
val (paramN, callableN, signatures) = Signatures.signatureHelp(path, pos.span) | ||
new SignatureHelp(signatures.map(signatureToSignatureInformation).asJava, callableN, paramN) | ||
driver.compilationUnits.get(uri) match | ||
case Some(unit) => | ||
given newCtx: Context = driver.currentCtx.fresh.setCompilationUnit(unit) | ||
val pos = sourcePosition(driver, uri, params.getPosition) | ||
val adjustedSpan = pos.span.withEnd(pos.span.end + 1) | ||
val path = Interactive.pathTo(ctx.compilationUnit.tpdTree, adjustedSpan) | ||
val (paramN, callableN, signatures) = Signatures.signatureHelp(path, adjustedSpan) | ||
|
||
new SignatureHelp(signatures.map(signatureToSignatureInformation).asJava, callableN, paramN) | ||
|
||
case _ => new SignatureHelp() | ||
|
||
} | ||
|
||
|
@@ -930,23 +935,25 @@ object DottyLanguageServer { | |
|
||
/** Convert `signature` to a `SignatureInformation` */ | ||
def signatureToSignatureInformation(signature: Signatures.Signature): lsp4j.SignatureInformation = { | ||
val tparams = signature.tparams.map(Signatures.Param("", _)) | ||
val paramInfoss = | ||
(tparams ::: signature.paramss.flatten).map(paramToParameterInformation) | ||
(signature.paramss.flatten).map(paramToParameterInformation) | ||
val paramLists = | ||
if signature.paramss.forall(_.isEmpty) && tparams.nonEmpty then | ||
"" | ||
else | ||
signature.paramss | ||
.map { paramList => | ||
val labels = paramList.map(_.show) | ||
val prefix = if paramList.exists(_.isImplicit) then "using " else "" | ||
labels.mkString(prefix, ", ", "") | ||
} | ||
.mkString("(", ")(", ")") | ||
val tparamsLabel = if (signature.tparams.isEmpty) "" else signature.tparams.mkString("[", ", ", "]") | ||
signature.paramss | ||
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 assume this whole duplication is because there is no good place for it, such that it could be used by both modules. 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. Dotty language server should actually be removed from the repository as it is no longer necessary. It is not so easy tho as the test coverage is different. This change was only made to make the tests pass |
||
.map { paramList => | ||
val labels = paramList.map(_.show) | ||
val isImplicit = paramList.exists: | ||
case p: Signatures.MethodParam => p.isImplicit | ||
case _ => false | ||
val prefix = if isImplicit then "using " else "" | ||
val isTypeParams = paramList.forall(_.isInstanceOf[Signatures.TypeParam]) && paramList.nonEmpty | ||
val wrap: String => String = label => if isTypeParams then | ||
s"[$label]" | ||
else | ||
s"($label)" | ||
wrap(labels.mkString(prefix, ", ", "")) | ||
}.mkString | ||
val returnTypeLabel = signature.returnType.map(t => s": $t").getOrElse("") | ||
val label = s"${signature.name}$tparamsLabel$paramLists$returnTypeLabel" | ||
val label = s"${signature.name}$paramLists$returnTypeLabel" | ||
val documentation = signature.doc.map(DottyLanguageServer.markupContent) | ||
val sig = new lsp4j.SignatureInformation(label) | ||
sig.setParameters(paramInfoss.asJava) | ||
|
Uh oh!
There was an error while loading. Please reload this page.