-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement: show both type symbol and object in scala 3 completions
- Loading branch information
1 parent
9ef4859
commit 6ccc512
Showing
8 changed files
with
145 additions
and
157 deletions.
There are no files selected for viewing
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
51 changes: 25 additions & 26 deletions
51
mtags/src/main/scala-3/scala/meta/internal/pc/completions/CompletionSuffix.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 |
---|---|---|
@@ -1,48 +1,47 @@ | ||
package scala.meta.internal.pc.completions | ||
|
||
/** | ||
* @param brace should we add "()" suffix? | ||
* @param bracket should we add "[]" suffix? | ||
* @param template should we add "{}" suffix? | ||
* @param suffixes which we should insert | ||
* @param snippet which suffix should we insert the snippet $0 | ||
*/ | ||
case class CompletionSuffix( | ||
brace: Boolean, | ||
bracket: Boolean, | ||
template: Boolean, | ||
suffixes: Set[SuffixKind], | ||
snippet: SuffixKind, | ||
): | ||
def labelSnippet = | ||
suffixes.collectFirst { | ||
case SuffixKind.Bracket(1) => "[T]" | ||
case SuffixKind.Bracket(n) => | ||
(for (i <- 1 to n) yield s"T$i").mkString("[", ", ", "]") | ||
} | ||
def hasSnippet = snippet != SuffixKind.NoSuffix | ||
def chain(copyFn: CompletionSuffix => CompletionSuffix) = copyFn(this) | ||
def withNewSuffix(kind: SuffixKind) = | ||
CompletionSuffix(suffixes + kind, snippet) | ||
def withNewSuffixSnippet(kind: SuffixKind) = | ||
CompletionSuffix(suffixes + kind, kind) | ||
def toEdit: String = | ||
if !hasSuffix then "" | ||
else | ||
val braceSuffix = | ||
if brace && snippet == SuffixKind.Brace then "($0)" | ||
else if brace then "()" | ||
else "" | ||
val bracketSuffix = | ||
if bracket && snippet == SuffixKind.Bracket then "[$0]" | ||
else if bracket then "[]" | ||
else "" | ||
val templateSuffix = | ||
if template && snippet == SuffixKind.Template then " {$0}" | ||
else if template then " {}" | ||
else "" | ||
s"$bracketSuffix$braceSuffix$templateSuffix" | ||
def loop(suffixes: List[SuffixKind]): String = | ||
def cursor = if suffixes.head == snippet then "$0" else "" | ||
suffixes match | ||
case SuffixKind.Brace :: tail => s"($cursor)" + loop(tail) | ||
case SuffixKind.Bracket(_) :: tail => s"[$cursor]" + loop(tail) | ||
case SuffixKind.Template :: tail => s" {$cursor}" + loop(tail) | ||
case _ => "" | ||
loop(suffixes.toList) | ||
def toEditOpt: Option[String] = | ||
val edit = toEdit | ||
if edit.nonEmpty then Some(edit) else None | ||
private def hasSuffix = brace || bracket || template | ||
end CompletionSuffix | ||
|
||
object CompletionSuffix: | ||
val empty = CompletionSuffix( | ||
brace = false, | ||
bracket = false, | ||
template = false, | ||
suffixes = Set.empty, | ||
snippet = SuffixKind.NoSuffix, | ||
) | ||
|
||
enum SuffixKind: | ||
case Brace, Bracket, Template, NoSuffix | ||
case Brace extends SuffixKind | ||
case Bracket(typeParamsCount: Int) extends SuffixKind | ||
case Template extends SuffixKind | ||
case NoSuffix extends SuffixKind |
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
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
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
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
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.