Skip to content

Commit

Permalink
Merge pull request #1 from agusayerza/do-not-suggest-inside-comments
Browse files Browse the repository at this point in the history
Do not provide suggestions inside YAML comments
  • Loading branch information
peltevis authored Oct 20, 2023
2 parents 32166b8 + 49b06fa commit 6158b1f
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 469 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.mulesoft.als.suggestions

import org.mulesoft.als.common.YPartBranch
import org.mulesoft.als.common.{ASTPartBranch, YPartBranch, YamlUtils}
import org.mulesoft.als.suggestions.aml.AmlCompletionRequest
import org.mulesoft.als.suggestions.interfaces._
import org.mulesoft.common.client.lexical.Position
import org.mulesoft.lsp.feature.completion.CompletionItem
import org.yaml.model.YComment

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
Expand All @@ -22,6 +24,7 @@ class CompletionProviderAST(request: AmlCompletionRequest) extends CompletionPro

override def suggest(): Future[Seq[CompletionItem]] =
if (request.astPartBranch.isMultiline) Future.successful(Nil)
else if (isInsideComment(request.position.toAmfPosition, request.astPartBranch)) Future.successful(Nil)
else
request.completionsPluginHandler
.pluginSuggestions(request)
Expand All @@ -31,6 +34,20 @@ class CompletionProviderAST(request: AmlCompletionRequest) extends CompletionPro
.filterNot(rs => arraySiblings(rs.newText))
.map(request.styler.rawToStyledSuggestion)
})

private def isInsideComment(position: Position, astPartBranch: ASTPartBranch): Boolean =
astPartBranch match {
case yPart: YPartBranch =>
// we are inside a comment if the current node is an empty YScalar and the request position matches a YComment on the parent node
yPart.isEmptyNode && yPart.parentEntry.exists(parent => {
parent.children.exists {
case comment: YComment if YamlUtils.contains(comment.range, position) => true
case _ => false
}

})
case _ => false
}
}

object CompletionProviderAST {
Expand Down
Loading

0 comments on commit 6158b1f

Please sign in to comment.