Skip to content

Commit

Permalink
fix: do not show completions in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Aug 22, 2024
1 parent 9ba2829 commit fa0a35b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class CompletionProvider(
autoImportsGen,
driver.settings,
referenceCounter,
unit.comments
).completions()

val items = completions.zipWithIndex.map { case (item, idx) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import scala.meta.internal.semver.SemVer
import scala.meta.pc.*

import dotty.tools.dotc.ast.tpd.*
import dotty.tools.dotc.core.Comments.Comment
import dotty.tools.dotc.core.Constants.Constant
import dotty.tools.dotc.core.Contexts.*
import dotty.tools.dotc.core.Flags
Expand Down Expand Up @@ -48,6 +49,7 @@ class Completions(
autoImports: AutoImportsGenerator,
options: List[String],
completionItemPriority: CompletionItemPriority,
comments: List[Comment]
)(using ReportContext):

implicit val context: Context = ctx
Expand Down Expand Up @@ -181,7 +183,7 @@ class Completions(
end calculateTypeInstanceAndNewPositions

def completions(): (List[CompletionValue], SymbolSearch.Result) =
val (advanced, exclusive) = advancedCompletions(path, pos, completionPos)
val (advanced, exclusive) = advancedCompletions(path, pos, completionPos, comments)
val (all, result) =
if exclusive then (advanced, SymbolSearch.Result.COMPLETE)
else
Expand Down Expand Up @@ -347,6 +349,7 @@ class Completions(
path: List[Tree],
pos: SourcePosition,
completionPos: CompletionPos,
comments: List[Comment]
): (List[CompletionValue], Boolean) =
lazy val rawPath = Paths
.get(pos.source.path)
Expand Down Expand Up @@ -375,6 +378,8 @@ class Completions(
val values = ScaladocCompletions.contribute(pos, text, config)
(values, true)

case _ if comments.exists(_.span.contains(pos.span)) => (Nil, true)

case MatchCaseExtractor.MatchExtractor(selector) =>
(
CaseKeywordCompletion.matchContribute(
Expand Down Expand Up @@ -525,7 +530,7 @@ class Completions(
// From Scala 3.1.3-RC3 (as far as I know), path contains
// `Literal(Constant(null))` on head for an incomplete program, in this case, just ignore the head.
case Literal(Constant(null)) :: tl =>
advancedCompletions(tl, pos, completionPos)
advancedCompletions(tl, pos, completionPos, comments)

// def foo(a@@)
case ParamDefinitionCompletions(allowKeywords) =>
Expand Down
16 changes: 2 additions & 14 deletions tests/cross/src/test/scala/tests/pc/CompletionKeywordSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ class CompletionKeywordSuite extends BaseCompletionSuite {
| // tr@@
|}
|""".stripMargin,
"",
compat = Map(
"3" -> """|transient scala (commit: '')
|transparentTrait(): transparentTrait (commit: '')
|transparentTrait - scala.annotation (commit: '')""".stripMargin
),
includeCommitCharacter = true
""
)

check(
Expand All @@ -60,13 +54,7 @@ class CompletionKeywordSuite extends BaseCompletionSuite {
| **/
|}
|""".stripMargin,
"",
compat = Map(
"3" -> """|transient scala (commit: '')
|transparentTrait(): transparentTrait (commit: '')
|transparentTrait - scala.annotation (commit: '')""".stripMargin
),
includeCommitCharacter = true
""
)

check(
Expand Down

0 comments on commit fa0a35b

Please sign in to comment.