Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not provide suggestions inside YAML comments #984

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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