Skip to content

Commit

Permalink
Merge pull request #867 from aml-org/r/5.3.2
Browse files Browse the repository at this point in the history
R/5.3.2
  • Loading branch information
llibarona authored Dec 21, 2022
2 parents 9193442 + 475da03 commit cf04398
Show file tree
Hide file tree
Showing 215 changed files with 7,747 additions and 1,945 deletions.
26 changes: 26 additions & 0 deletions adrs/completion/0003-escape-for-non-snippets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 1. Structure completion by node Vendor

Date: 2022-11-28

## Status

Accepted

## Context
Reported bug in [this ticket](https://gus.lightning.force.com/lightning/r/ADM_Work__c/a07EE000017Kf7TYAS/view)

## Decision
Fix the suggestions starting with dollar sign ($) using this regex to capture groups: ```(\$)(?=\D)```

#### Escenario
```
$id= $1
"$comment": "$1",
```

#### Regex playgrounds:
* [RegexR](https://regexr.com/)
* [Regex 101](https://regex101.com/)

## Consequences
Avoid suggestion starting with dollar sign as plain text and use normal string scalar and snippet instead.
52 changes: 52 additions & 0 deletions als-actions/js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions als-actions/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@aml-org/amf-antlr-parsers": "0.5.18",
"ajv": "6.12.6"
},
"author": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import amf.core.client.scala.model.document.Document
import amf.core.client.scala.model.domain.AmfObject
import amf.core.internal.remote.{Mimes, Spec}
import org.mulesoft.als.actions.codeactions.TreeKnowledge
import org.mulesoft.als.common.ObjectInTree
import org.mulesoft.als.common.{ObjectInTree, YamlUtils}
import org.mulesoft.als.common.YamlUtils.isJson
import org.mulesoft.als.common.dtoTypes.PositionRange
import org.mulesoft.als.convert.LspRangeConverter
Expand All @@ -23,7 +23,7 @@ import scala.concurrent.Future
trait BaseElementDeclarableExtractors extends TreeKnowledge with DeclarationCreator {

protected val afterInfoRange: PositionRange =
afterInfoNode(params.bu, yPartBranch.map(_.isJson).getOrElse(params.bu.location().exists(_.endsWith(".json"))))
afterInfoNode(params.bu, yPartBranch.map(_.strict).getOrElse(YamlUtils.isJson(params.bu)))
.map(p => PositionRange(p, p))
.getOrElse(PositionRange.TopLine)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.mulesoft.als.actions.codeactions.plugins.base.{CodeActionRequestParam
import org.mulesoft.als.actions.codeactions.plugins.conversions.ShapeExtractor
import org.mulesoft.als.actions.codeactions.plugins.declarations.common.FileExtractor
import org.mulesoft.als.actions.codeactions.plugins.declarations.fragment.webapi.raml.FragmentBundle
import org.mulesoft.als.common.YamlUtils
import org.mulesoft.als.common.edits.codeaction.AbstractCodeAction
import org.mulesoft.lsp.edit.TextEdit
import org.mulesoft.lsp.feature.common.{Position, Range}
Expand Down Expand Up @@ -42,7 +43,7 @@ trait ExtractDeclarationToFragment extends CodeActionResponsePlugin with FileExt
.serialize(getSyntax, ef)

private def getSyntax: String =
if (yPartBranch.exists(_.isJson)) Mimes.`application/json`
if (YamlUtils.isJson(params.bu)) Mimes.`application/json`
else Mimes.`application/yaml`

private def externalFragmentTextEdit(ef: Fragment): Future[(String, TextEdit)] =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
package org.mulesoft.als.actions.formatting

import org.mulesoft.als.common.ASTElementWrapper
import org.mulesoft.als.actions.formatting.SyamlImpl.YPartImpl
import org.mulesoft.als.common.ASTElementWrapper.AlsPositionRange
import org.mulesoft.als.common.dtoTypes.PositionRange
import org.mulesoft.als.convert.LspRangeConverter
import org.mulesoft.amfintegration.ErrorsCollected
import org.mulesoft.lsp.configuration.FormattingOptions
import org.mulesoft.lsp.edit.TextEdit
import org.yaml.model._
import org.yaml.render.{JsonRender, JsonRenderOptions, YamlRender, YamlRenderOptions}
import org.yaml.render.{JsonRender, JsonRenderOptions, YamlRender}

case class RangeFormatting(
parentYPart: YPart,
formattingOptions: FormattingOptions,
isJson: Boolean,
syntaxErrors: ErrorsCollected,
raw: Option[String]
raw: Option[String],
initialIndentation: Int
) {

def format(): Seq[TextEdit] =
formatPart(parentYPart)

private def containsSyntaxError(ypart: YPart): Boolean =
syntaxErrors.errors.exists(_.position.exists(err => ypart.range.contains(err.range)))

private def formatPart(ypart: YPart): Seq[TextEdit] =
if (containsSyntaxError(ypart))
ypart.children.filterNot(_.isInstanceOf[YNonContent]).flatMap(formatPart)
else {
ypart match {
// todo: initial indentation for the value might be ignored if we emit an YMapEntry in YAML
case map: YMapEntry if !isJson => format(YMap(ypart.location, IndexedSeq(map)))
case e => format(e)
}
}

private def format(yPart: YPart): Seq[TextEdit] = {
val renderPart: YPart = yPart match {
case doc: YDocument => doc.node // do not format head comment
case _ => yPart
}
val initialIndentation =
raw.map(t => ASTElementWrapper.getIndentation(t, renderPart.range.toPositionRange.start)).getOrElse(0)
val range = LspRangeConverter.toLspRange(renderPart.range.toPositionRange)
def format(): Seq[TextEdit] = formatPart(parentYPart)

private def containsSyntaxError(part: YPart): Boolean =
syntaxErrors.errors.exists(_.position.exists(err => part.range.contains(err.range)))

private def formatPart(part: YPart): Seq[TextEdit] =
if (isJson && containsSyntaxError(part))
part.children.filterNot(_.isInstanceOf[YNonContent]).flatMap(formatPart)
else
format(part)

def applyOptions(s: String): String = {
var formatted = s
if (formattingOptions.getTrimTrailingWhitespace)
formatted = formatted.replaceAll("""(?m)[^\S\r\n]+$""", "") // strip spaces end of line except after colon
if (formattingOptions.getTrimFinalNewlines)
formatted = formatted.replaceAll("""\n+$""", "\n") // reduce trailing EOL
if (formattingOptions.getInsertFinalNewline && !formatted.endsWith("\n"))
formatted += "\n" // if no final EOL, add one
formatted
}

private def format(part: YPart): Seq[TextEdit] = {
val renderPart: YPart = part.format(formattingOptions.tabSize, initialIndentation)
val range = LspRangeConverter.toLspRange(part.range.toPositionRange)

val s: String = if (isJson) {
val renderOptions: JsonRenderOptions =
JsonRenderOptions(formattingOptions.tabSize, formattingOptions.insertSpaces, applyFormatting = true)
JsonRender.render(renderPart, initialIndentation, renderOptions)
} else {
val renderOptions: YamlRenderOptions =
YamlRenderOptions(formattingOptions.tabSize, applyFormatting = true)
JsonRender.render(
renderPart,
initialIndentation,
renderOptions
) // todo: add some logic to guess desired indentation
} else
YamlRender
.render(Seq(renderPart), expandReferences = false, renderOptions, initialIndentation)
.dropWhile(_ == ' ')

}

Seq(TextEdit(range, s))
.render(Seq(renderPart), expandReferences = false)

Seq(TextEdit(range, applyOptions(s)))
}
}
Loading

0 comments on commit cf04398

Please sign in to comment.