Skip to content

Commit

Permalink
Add missing dialect in validation (#1076)
Browse files Browse the repository at this point in the history
Fix suggestions inside json nodes
  • Loading branch information
emilianoascona authored Oct 7, 2024
1 parent 14340b1 commit cdc1e74
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.mulesoft.als.suggestions.interfaces.AMLCompletionPlugin
import org.mulesoft.als.suggestions.{PlainText, RawSuggestion, SuggestionStructure}
import org.mulesoft.amfintegration.AmfImplicits._
import org.mulesoft.amfintegration.dialect.dialects.asyncapi20.AsyncApi20Dialect
import org.mulesoft.amfintegration.dialect.dialects.asyncapi26.AsyncApi26Dialect

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
Expand Down Expand Up @@ -56,22 +57,10 @@ trait AMLRefTagCompletionPlugin extends AMLCompletionPlugin {
(!yPartBranch.hasIncludeTag) && yPartBranch.brothers.isEmpty &&
isDeclarable(params) &&
isInFacet(params) &&
matchPrefixPatched(params) &&
!isExceptionCase(yPartBranch)
case _ => false
}

private def matchPrefixPatched(params: AmlCompletionRequest) =
params.astPartBranch.stringValue.isEmpty ||
isEmptyJsonValue(params) ||
params.astPartBranch.isArray ||
params.astPartBranch.stringValue.startsWith("$")

private def isEmptyJsonValue(params: AmlCompletionRequest) =
params.actualDialect.id.equals(AsyncApi20Dialect.DialectLocation) &&
params.baseUnit.id.endsWith(".json") &&
params.astPartBranch.stringValue.equals("{}")

private def isInFacet(params: AmlCompletionRequest): Boolean = isKeyAlone(params)

private def isKeyAlone(params: AmlCompletionRequest): Boolean =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"asyncapi": "2.0.0",
"asyncapi": "2.6.0",
"info": {
"title": "asyncjsonmac",
"version": "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,42 @@
"commitCharacters": null,
"command": null
},
{
"label": "$ref",
"kind": [

],
"detail": "unknown",
"documentation": "reference tag",
"deprecated": [

],
"preselect": [

],
"sortText": "0$ref",
"filterText": "\"\\$ref\": \"$1\"",
"insertText": null,
"insertTextFormat": [
2
],
"textEdit": {
"range": {
"start": {
"line": 15,
"character": 38
},
"end": {
"line": 15,
"character": 38
}
},
"newText": "\"\\$ref\": \"$1\""
},
"additionalTextEdits": null,
"commitCharacters": null,
"command": null
},
{
"label": "allOf",
"kind": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,42 @@
"commitCharacters": null,
"command": null
},
{
"label": "$ref",
"kind": [

],
"detail": "unknown",
"documentation": "reference tag",
"deprecated": [

],
"preselect": [

],
"sortText": "0$ref",
"filterText": "\"\\$ref\": \"$1\"",
"insertText": null,
"insertTextFormat": [
2
],
"textEdit": {
"range": {
"start": {
"line": 7,
"character": 10
},
"end": {
"line": 7,
"character": 10
}
},
"newText": "\"\\$ref\": \"$1\""
},
"additionalTextEdits": null,
"commitCharacters": null,
"command": null
},
{
"label": "allOf",
"kind": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,42 @@
"commitCharacters": null,
"command": null
},
{
"label": "$ref",
"kind": [

],
"detail": "unknown",
"documentation": "reference tag",
"deprecated": [

],
"preselect": [

],
"sortText": "0$ref",
"filterText": "\"\\$ref\": \"$1\"",
"insertText": null,
"insertTextFormat": [
2
],
"textEdit": {
"range": {
"start": {
"line": 5,
"character": 6
},
"end": {
"line": 5,
"character": 6
}
},
"newText": "\"\\$ref\": \"$1\""
},
"additionalTextEdits": null,
"commitCharacters": null,
"command": null
},
{
"label": "allOf",
"kind": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
[
{
"label": "$ref",
"kind": [

],
"detail": "unknown",
"documentation": "reference tag",
"deprecated": [

],
"preselect": [

],
"sortText": "0$ref",
"filterText": "\"\\$ref\": \"$1\"",
"insertText": null,
"insertTextFormat": [
2
],
"textEdit": {
"range": {
"start": {
"line": 7,
"character": 10
},
"end": {
"line": 7,
"character": 10
}
},
"newText": "\"\\$ref\": \"$1\""
},
"additionalTextEdits": null,
"commitCharacters": null,
"command": null
},
{
"label": "allOf",
"kind": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
[
{
"label": "$ref",
"kind": [

],
"detail": "unknown",
"documentation": "reference tag",
"deprecated": [

],
"preselect": [

],
"sortText": "0$ref",
"filterText": "\"\\$ref\": \"$1\"",
"insertText": null,
"insertTextFormat": [
2
],
"textEdit": {
"range": {
"start": {
"line": 15,
"character": 38
},
"end": {
"line": 15,
"character": 38
}
},
"newText": "\"\\$ref\": \"$1\""
},
"additionalTextEdits": null,
"commitCharacters": null,
"command": null
},
{
"label": "additionalProperties",
"kind": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,42 @@
"commitCharacters": null,
"command": null
},
{
"label": "$ref",
"kind": [

],
"detail": "unknown",
"documentation": "reference tag",
"deprecated": [

],
"preselect": [

],
"sortText": "0$ref",
"filterText": "\"\\$ref\": \"$1\"",
"insertText": null,
"insertTextFormat": [
2
],
"textEdit": {
"range": {
"start": {
"line": 15,
"character": 38
},
"end": {
"line": 15,
"character": 38
}
},
"newText": "\"\\$ref\": \"$1\""
},
"additionalTextEdits": null,
"commitCharacters": null,
"command": null
},
{
"label": "allOf",
"kind": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,42 @@
"commitCharacters": null,
"command": null
},
{
"label": "$ref",
"kind": [

],
"detail": "unknown",
"documentation": "reference tag",
"deprecated": [

],
"preselect": [

],
"sortText": "0$ref",
"filterText": "\"\\$ref\": \"$1\"",
"insertText": null,
"insertTextFormat": [
2
],
"textEdit": {
"range": {
"start": {
"line": 7,
"character": 10
},
"end": {
"line": 7,
"character": 10
}
},
"newText": "\"\\$ref\": \"$1\""
},
"additionalTextEdits": null,
"commitCharacters": null,
"command": null
},
{
"label": "allOf",
"kind": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,42 @@
"commitCharacters": null,
"command": null
},
{
"label": "$ref",
"kind": [

],
"detail": "unknown",
"documentation": "reference tag",
"deprecated": [

],
"preselect": [

],
"sortText": "0$ref",
"filterText": "\"\\$ref\": \"$1\"",
"insertText": null,
"insertTextFormat": [
2
],
"textEdit": {
"range": {
"start": {
"line": 5,
"character": 6
},
"end": {
"line": 5,
"character": 6
}
},
"newText": "\"\\$ref\": \"$1\""
},
"additionalTextEdits": null,
"commitCharacters": null,
"command": null
},
{
"label": "allOf",
"kind": [
Expand Down

0 comments on commit cdc1e74

Please sign in to comment.