-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #867 from aml-org/r/5.3.2
R/5.3.2
- Loading branch information
Showing
215 changed files
with
7,747 additions
and
1,945 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
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. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
76 changes: 38 additions & 38 deletions
76
als-actions/shared/src/main/scala/org/mulesoft/als/actions/formatting/RangeFormatting.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 |
---|---|---|
@@ -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))) | ||
} | ||
} |
Oops, something went wrong.