-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2637 from tanishiking/prettify-signature
Related #2495 ## Problem Previously, metals shows - fully qualified name for types in completion items - e.g. `foo(arg: very.long.prefix.Type): very.long.prefix.Type` - print evidence params as it is. - e.g. `foo[T](arg: Type)(implicit evidence$1: Ordering[T]): Type` for `foo[T: Ordering](arg: Type): Type` - don't show belonging package for Class and Modules - `NoClassDefFoundError: class and object NoClassDefFoundError` as it's completion's label, for `java.lang.NoClassDefFoundError`. ## This PR fixes those problems ### shorten type signature when the prefix can be seen from the context - e.g. if `very.long.prefix` is imported in the context (scope) - before: `foo(arg: very.long.prefix.Type): very.long.prefix.Type` - ![Screen Shot 2021-03-25 at 0 26 41](https://user-images.githubusercontent.com/9353584/112758255-50958580-9028-11eb-9227-b9449062e138.png) - after: `foo(arg: prefix.Type): prefix.Type` - <img width="522" alt="Screen Shot 2021-03-29 at 0 39 45" src="https://user-images.githubusercontent.com/9353584/112758238-3360b700-9028-11eb-81aa-e7473fc0eafb.png"> ### Pretty-print context bounds, and remove evidence params - before `foo[T](arg: Type)(implicit evidence$1: Ordering[T]): Type` - <img width="518" alt="Screen Shot 2021-03-29 at 0 43 36" src="https://user-images.githubusercontent.com/9353584/112758287-7fabf700-9028-11eb-8558-048fb73e0efc.png"> - after `foo[T: Ordering](arg: Type): Type` - <img width="516" alt="Screen Shot 2021-03-29 at 0 45 34" src="https://user-images.githubusercontent.com/9353584/112758288-8470ab00-9028-11eb-8cdf-35478122e7b1.png"> ### Show parent packages in detail section of completionItem - e.g. for `java.langInteger` - before: - <img width="505" alt="Screen Shot 2021-03-29 at 0 24 03" src="https://user-images.githubusercontent.com/9353584/112758313-a1a57980-9028-11eb-88f1-305f06ababbd.png"> - after: - <img width="503" alt="Screen Shot 2021-03-29 at 0 25 45" src="https://user-images.githubusercontent.com/9353584/112758326-b97cfd80-9028-11eb-9bb6-c38a29653bbd.png"> ## out of scope from this scope - print default value (not needed for completions) - https://github.com/scalameta/metals/blob/45eaa4151ac5f54cabddce73de3d888d5157b1f3/mtags/src/main/scala-2/scala/meta/internal/pc/Signatures.scala#L399 - Compute type parameters based on the qualifier. - https://github.com/scalameta/metals/blob/45eaa4151ac5f54cabddce73de3d888d5157b1f3/mtags/src/main/scala-2/scala/meta/internal/pc/completions/Completions.scala#L258-L262 - Gonna fix in another PR - include documentation
- Loading branch information
1 parent
9de2f3e
commit 374f159
Showing
9 changed files
with
531 additions
and
288 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
mtags/src/main/scala-3/scala/meta/internal/pc/Params.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package scala.meta.internal.pc | ||
|
||
import dotty.tools.dotc.core.Contexts.Context | ||
import dotty.tools.dotc.core.Symbols.Symbol | ||
import dotty.tools.dotc.core.Flags._ | ||
|
||
case class Params( | ||
labels: Seq[String], | ||
kind: Params.Kind | ||
) | ||
|
||
object Params { | ||
enum Kind { | ||
case TypeParameter, Normal, Implicit, Using | ||
} | ||
|
||
def paramsKind(syms: List[Symbol])(using Context): Params.Kind = { | ||
syms match { | ||
case head :: _ => | ||
if (head.isType) Kind.TypeParameter | ||
else if (head.is(Given)) Kind.Using | ||
else if (head.is(Implicit)) Kind.Implicit | ||
else Kind.Normal | ||
case Nil => Kind.Normal | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.