-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: add multiline comment completion
- Loading branch information
1 parent
430012e
commit 9ed092b
Showing
6 changed files
with
87 additions
and
0 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
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
43 changes: 43 additions & 0 deletions
43
mtags/src/main/scala-2/scala/meta/internal/pc/completions/MultilineCommentCompletion.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,43 @@ | ||
package scala.meta.internal.pc.completions | ||
|
||
import scala.meta.internal.pc.MetalsGlobal | ||
|
||
import org.eclipse.{lsp4j => l} | ||
|
||
trait MultilineCommentCompletions { this: MetalsGlobal => | ||
case class MultilineCommentCompletion( | ||
editRange: l.Range, | ||
pos: Position, | ||
text: String | ||
) extends CompletionPosition { | ||
|
||
override def contribute: List[TextEditMember] = { | ||
val newText = | ||
if (clientSupportsSnippets) s" $$0 */" | ||
else s" */" | ||
List( | ||
new TextEditMember( | ||
"Multiline Comment", | ||
new l.TextEdit( | ||
editRange, | ||
newText | ||
), | ||
completionsSymbol("Multiline"), | ||
label = Some("/* */"), | ||
detail = Some("Multiline Comment") | ||
) | ||
) | ||
} | ||
} | ||
|
||
protected def isMultilineCommentStart( | ||
pos: Position, | ||
text: String | ||
): Boolean = { | ||
pos.isDefined && | ||
pos.point >= 2 && | ||
text.charAt(pos.point - 2) == '/' && | ||
text.charAt(pos.point - 1) == '*' | ||
} | ||
|
||
} |
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
16 changes: 16 additions & 0 deletions
16
mtags/src/main/scala-3/scala/meta/internal/pc/completions/MultilineCommentCompletion.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,16 @@ | ||
package scala.meta.internal.pc.completions | ||
|
||
import scala.meta.pc.PresentationCompilerConfig | ||
|
||
import dotty.tools.dotc.util.SourcePosition | ||
|
||
object MultilineCommentCompletion: | ||
|
||
def contribute(config: PresentationCompilerConfig): List[CompletionValue] = | ||
val newText = if config.isCompletionSnippetsEnabled then " $0 */" else " */" | ||
List(CompletionValue.document("/* */", newText, "Multiline Comment")) | ||
|
||
def isMultilineCommentCompletion(pos: SourcePosition, text: String): Boolean = | ||
pos.point >= 2 && | ||
text.charAt(pos.point - 2) == '/' && | ||
text.charAt(pos.point - 1) == '*' |
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