Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.redhat.qute.services.hover.HoverRequest;
import com.redhat.qute.utils.DocumentationUtils;
import com.redhat.qute.utils.QutePositionUtility;
import static com.redhat.qute.project.extensions.roq.JsonVertxConstants.IO_VERTX_CORE_JSON_JSON_OBJECT_CLASS;

/**
* Represents a Roq data file (YAML, JSON, etc.) as a top-level value resolver
Expand Down Expand Up @@ -157,6 +158,11 @@ public RoqDataFile(Path filePath, String namespace, DataLoader dataLoader) {
dataLoader.load(this);
}
}

@Override
public String getSignature() {
return getJavaElementType();
}

/**
* Creates a clone of this data file with a different namespace.
Expand All @@ -181,7 +187,6 @@ public RoqDataFile create(String namespace) {

// Copy the fields from this instance
resolver.setFields(getFields());
resolver.setSignature("name : Object");

return resolver;
}
Expand All @@ -201,19 +206,9 @@ public String getName() {
return name;
}

/**
* Returns the Java element type for this resolver.
*
* <p>
* Data files don't have a specific Java type (they're dynamic), so this returns
* null. The actual types are in the individual fields.
* </p>
*
* @return null - no specific Java type
*/
@Override
public String getJavaElementType() {
return null;
return IO_VERTX_CORE_JSON_JSON_OBJECT_CLASS;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,27 @@
},
// ------------- Vert.x Integration --------------
// See https://quarkus.io/guides/qute-reference#vertx_integration
// https://github.com/quarkusio/quarkus/blob/main/extensions/qute/runtime/src/main/java/io/quarkus/qute/runtime/jsonobject/JsonObjectValueResolver.java
{
"signature": "fieldNames(base : io.vertx.core.json.JsonObject) : java.util.Set<java.lang.String>",
"url": "https://quarkus.io/guides/qute-reference#vertx_integration"
},
{
"signature": "fields(base : io.vertx.core.json.JsonObject) : java.util.Set<java.lang.String>",
"url": "https://quarkus.io/guides/qute-reference#vertx_integration"
},
{
"signature": "size(base : io.vertx.core.json.JsonObject) : int",
"url": "https://quarkus.io/guides/qute-reference#vertx_integration"
},
{
"signature": "empty(base : io.vertx.core.json.JsonObject) : boolean",
"url": "https://quarkus.io/guides/qute-reference#vertx_integration"
},
{
"signature": "isEmpty(base : io.vertx.core.json.JsonObject) : boolean",
"url": "https://quarkus.io/guides/qute-reference#vertx_integration"
},
{
"signature": "get(base : io.vertx.core.json.JsonObject, key : java.lang.String) : java.lang.Object",
"matchNames": [
Expand All @@ -214,6 +235,10 @@
{
"signature": "get(base : io.vertx.core.json.JsonObject, key : java.lang.String) : java.lang.Object",
"url": "https://quarkus.io/guides/qute-reference#vertx_integration"
},
{
"signature": "containsKey(base : io.vertx.core.json.JsonObject) : boolean",
"url": "https://quarkus.io/guides/qute-reference#vertx_integration"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,31 @@ public void validInjectDataFile() throws Exception {
testDiagnosticsFor(template);
}

@Test
public void validInjectDataFileWithJsonObjectValueResolver() throws Exception {
// https://github.com/quarkusio/quarkus/blob/main/extensions/qute/runtime/src/main/java/io/quarkus/qute/runtime/jsonobject/JsonObjectValueResolver.java

// data/books.yaml
String template = "{inject:books-json.get('foo')}";
testDiagnosticsFor(template);
template = "{inject:books-json.list}";
testDiagnosticsFor(template);

// data/sandwiches.yaml
template = "{inject:sandwiches}";
testDiagnosticsFor(template);
template = "{inject:sandwiches.sandwiches}";
testDiagnosticsFor(template);
}

@Test
public void invalidInjectDataFile() throws Exception {
String template = "{inject:books-jsonXXX}";
testDiagnosticsFor(template, //
d(0, 8, 0, 21, QuteErrorCode.UndefinedObject, "`books-jsonXXX` cannot be resolved to an object.", //
"qute", DiagnosticSeverity.Warning));
template = "{inject:books-json.listXXX}";
testDiagnosticsFor(template, //
d(0, 19, 0, 26, QuteErrorCode.UnknownProperty,
"`listXXX` cannot be resolved or is not a field of `null` Java type.", //
"qute", DiagnosticSeverity.Error));
testDiagnosticsFor(template);
}

@Test
Expand All @@ -81,7 +95,8 @@ public void nestedFields() throws Exception {
@Test
public void invalidInjectDataFileInForSection() throws Exception {
// With JsonObject signature, any property is valid via get() value resolver
// So b.titleXXX doesn't generate an error - it resolves to JsonObject.get("titleXXX")
// So b.titleXXX doesn't generate an error - it resolves to
// JsonObject.get("titleXXX")
String template = "{#for b in inject:books-json.list}\r\n" + //
" {b.titleXXX}\r\n" + //
"{/for}";
Expand All @@ -92,7 +107,5 @@ private static void testDiagnosticsFor(String value, Diagnostic... expected) {
QuteAssert.testDiagnosticsFor(value, QuteAssert.FILE_URI, null, RoqProject.PROJECT_URI,
QuteAssert.TEMPLATE_BASE_DIR, false, null, expected);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ public void invalidInjectDataFile() throws Exception {
d(0, 8, 0, 16, QuteErrorCode.UndefinedObject, "`booksXXX` cannot be resolved to an object.", //
"qute", DiagnosticSeverity.Warning));
template = "{inject:books.listXXX}";
testDiagnosticsFor(template, //
d(0, 14, 0, 21, QuteErrorCode.UnknownProperty,
"`listXXX` cannot be resolved or is not a field of `null` Java type.", //
"qute", DiagnosticSeverity.Error));
testDiagnosticsFor(template);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ public void books() throws Exception {
@Test
public void books_invalid() throws Exception {
String template = "{inject:books-json.li|s}";
assertHover(template, null, null);
assertHover(template, //
"```java" + System.lineSeparator() + //
"Object get()" + System.lineSeparator() + //
"```" + System.lineSeparator() + //
"See [here](https://quarkus.io/guides/qute-reference#vertx_integration) for more informations.", //
r(0, 19, 0, 22));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ public void books() throws Exception {
@Test
public void books_invalid() throws Exception {
String template = "{inject:books.li|s}";
assertHover(template, null, null);
assertHover(template, //
"```java" + System.lineSeparator() + //
"Object get()" + System.lineSeparator() + //
"```" + System.lineSeparator() + //
"See [here](https://quarkus.io/guides/qute-reference#vertx_integration) for more informations.", //
r(0, 14, 0, 17));
}

@Test
Expand Down
Loading