Skip to content

Commit 670a488

Browse files
committed
Provide #fragment snippet
See redhat-developer/vscode-quarkus#563 Signed-off-by: azerr <[email protected]>
1 parent 1600156 commit 670a488

13 files changed

+118
-32
lines changed

qute.ls/com.redhat.qute.ls/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<maven.build.timestamp.format>yyyyMMdd-HHmm</maven.build.timestamp.format>
4040
<dev.build.timestamp>${maven.build.timestamp}</dev.build.timestamp>
4141
<lsp4j.version>0.14.0</lsp4j.version>
42-
<qute.version>2.7.0.Final</qute.version>
42+
<qute.version>2.15.3.Final</qute.version>
4343
<junit.version>5.6.1</junit.version>
4444
<jboss.releases.repo.id>jboss-releases-repository</jboss.releases.repo.id>
4545
<jboss.releases.repo.url>https://repository.jboss.org/nexus/service/local/staging/deploy/maven2/</jboss.releases.repo.url>

qute.ls/com.redhat.qute.ls/src/main/java/com/redhat/qute/ls/commons/snippets/Snippet.java

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class Snippet {
3939

4040
private ISnippetContext<?> context;
4141

42+
private List<String> urls;
43+
4244
public String getLabel() {
4345
return label;
4446
}
@@ -94,6 +96,14 @@ public String getSortText() {
9496
public void setSortText(String sortText) {
9597
this.sortText = sortText;
9698
}
99+
100+
public List<String> getUrls() {
101+
return urls;
102+
}
103+
104+
public void setUrls(List<String> urls) {
105+
this.urls = urls;
106+
}
97107

98108
public ISnippetContext<?> getContext() {
99109
return context;

qute.ls/com.redhat.qute.ls/src/main/java/com/redhat/qute/ls/commons/snippets/SnippetDeserializer.java

+16
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class SnippetDeserializer implements JsonDeserializer<Snippet> {
4040
private static final String SORTTEXT_ELT = "sortText";
4141
private static final String BODY_ELT = "body";
4242
private static final String CONTEXT_ELT = "context";
43+
private static final String URL_ELT = "url";
4344

4445
private final TypeAdapter<? extends ISnippetContext<?>> contextDeserializer;
4546

@@ -139,6 +140,21 @@ public Snippet deserialize(JsonElement json, Type typeOfT, JsonDeserializationCo
139140
}
140141
}
141142

143+
// url
144+
List<String> urls = new ArrayList<>();
145+
JsonElement urlElt = snippetObj.get(URL_ELT);
146+
if (urlElt != null) {
147+
if (urlElt.isJsonArray()) {
148+
JsonArray urlArray = (JsonArray) urlElt;
149+
urlArray.forEach(elt -> {
150+
urls.add(elt.getAsString());
151+
});
152+
} else if (urlElt.isJsonPrimitive()) {
153+
urls.add(urlElt.getAsString());
154+
}
155+
}
156+
snippet.setUrls(urls);
157+
142158
return snippet;
143159
}
144160

qute.ls/com.redhat.qute.ls/src/main/java/com/redhat/qute/utils/DocumentationUtils.java

+25-6
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ public static MarkupContent getDocumentation(Snippet snippet, boolean markdown)
282282
documentation.append(snippet.getDescription());
283283
}
284284

285+
addUrls(snippet.getUrls(), documentation, markdown);
286+
285287
return createMarkupContent(documentation, markdown);
286288
}
287289

@@ -340,14 +342,31 @@ private static void addUrl(String url, StringBuilder documentation, boolean mark
340342
if (!StringUtils.isEmpty(url)) {
341343
documentation.append(System.lineSeparator());
342344
documentation.append("See ");
343-
if (markdown) {
344-
documentation.append("[here](");
345-
documentation.append(url);
346-
documentation.append(")");
347-
} else {
348-
documentation.append(url);
345+
addUrl(url, "here", documentation, markdown);
346+
documentation.append(" for more informations.");
347+
}
348+
}
349+
350+
private static void addUrls(List<String> urls, StringBuilder documentation, boolean markdown) {
351+
if (urls != null && !urls.isEmpty()) {
352+
documentation.append(System.lineSeparator());
353+
documentation.append("See ");
354+
for (String url : urls) {
355+
addUrl(url, "here", documentation, markdown);
349356
}
350357
documentation.append(" for more informations.");
351358
}
352359
}
360+
361+
private static void addUrl(String url, String label, StringBuilder documentation, boolean markdown) {
362+
if (markdown) {
363+
documentation.append("[");
364+
documentation.append(label);
365+
documentation.append("](");
366+
documentation.append(url);
367+
documentation.append(")");
368+
} else {
369+
documentation.append(url);
370+
}
371+
}
353372
}

qute.ls/com.redhat.qute.ls/src/main/resources/com/redhat/qute/services/snippets/qute-snippets.json

+47-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
1-
{ "#each": {
2-
"prefix": ["each", "{#"],
1+
{
2+
"#each": {
3+
"prefix": [
4+
"each",
5+
"{#"
6+
],
37
"body": [
48
"{#each ${1:items}}",
59
"\t{it.${2:name}}$0",
610
"{/each}"
711
],
8-
"description": "Loop section with implicit alias"
12+
"description": "Loop section with implicit alias",
13+
"url": "https://quarkus.io/guides/qute-reference#loop_section"
914
},
1015
"#eval": {
1116
"prefix": "eval",
1217
"body": [
1318
"{#eval ${1:content} /}$0"
1419
],
15-
"description": "Parse and evaluate a template dynamically"
20+
"description": "Parse and evaluate a template dynamically",
21+
"url": "https://quarkus.io/guides/qute-reference#eval-section"
22+
},
23+
"#fragment": {
24+
"prefix": "fragment",
25+
"body": [
26+
"{#fragment id=\"${1:item}\"}",
27+
"\t$0",
28+
"{/fragment}"
29+
],
30+
"description": "A fragment represents a part of the template that can be treated as a separate template, i.e. rendered separately.",
31+
"url": [
32+
"https://quarkus.io/guides/qute-reference#fragments",
33+
"https://quarkus.io/guides/qute-reference#type_safe_fragments"
34+
]
1635
},
1736
"#for": {
1837
"prefix": "for",
@@ -21,7 +40,8 @@
2140
"\t{${1:item}.${3:name}}$0",
2241
"{/for}"
2342
],
24-
"description": "Loop section with alias"
43+
"description": "Loop section with alias",
44+
"url": "https://quarkus.io/guides/qute-reference#loop_section"
2545
},
2646
"#if": {
2747
"prefix": "if",
@@ -30,7 +50,8 @@
3050
"\t$0",
3151
"{/if}"
3252
],
33-
"description": "If section"
53+
"description": "If section",
54+
"url": "https://quarkus.io/guides/qute-reference#if_section"
3455
},
3556
"#else": {
3657
"prefix": "if-else",
@@ -41,7 +62,8 @@
4162
"\t$0",
4263
"{/if}"
4364
],
44-
"description": "Else section"
65+
"description": "Else section",
66+
"url": "https://quarkus.io/guides/qute-reference#if_section"
4567
},
4668
"#elseif": {
4769
"prefix": "if-elseif",
@@ -54,7 +76,8 @@
5476
"\t$0",
5577
"{/if}"
5678
],
57-
"description": "Else If section"
79+
"description": "Else If section",
80+
"url": "https://quarkus.io/guides/qute-reference#if_section"
5881
},
5982
"#include": {
6083
"prefix": "include",
@@ -63,7 +86,8 @@
6386
"\t$0",
6487
"{/include}"
6588
],
66-
"description": "Include section"
89+
"description": "Include section",
90+
"url": "https://quarkus.io/guides/qute-reference#include_helper"
6791
},
6892
"#insert": {
6993
"prefix": "insert",
@@ -72,7 +96,8 @@
7296
"\t$0",
7397
"{/insert}"
7498
],
75-
"description": "Insert section"
99+
"description": "Insert section",
100+
"url": "https://quarkus.io/guides/qute-reference#include_helper"
76101
},
77102
"#let": {
78103
"prefix": "let",
@@ -81,14 +106,16 @@
81106
"\t$0",
82107
"{/let}"
83108
],
84-
"description": "Let section"
109+
"description": "Let section",
110+
"url": "https://quarkus.io/guides/qute-reference#let_section"
85111
},
86112
"#parameter": {
87113
"prefix": "parameter",
88114
"body": [
89115
"{@${1:class} ${2:alias}}$0"
90116
],
91-
"description": "Insert parameter declaration"
117+
"description": "Insert parameter declaration",
118+
"url": "https://quarkus.io/guides/qute-reference#typesafe_expressions"
92119
},
93120
"#set": {
94121
"prefix": "set",
@@ -97,7 +124,8 @@
97124
"\t$0",
98125
"{/set}"
99126
],
100-
"description": "Let section"
127+
"description": "Let section",
128+
"url": "https://quarkus.io/guides/qute-reference#let_section"
101129
},
102130
"#switch": {
103131
"prefix": "switch",
@@ -106,7 +134,8 @@
106134
"\t{#case ${2:case}}$0",
107135
"{/switch}"
108136
],
109-
"description": "Switch section"
137+
"description": "Switch section",
138+
"url": "https://quarkus.io/guides/qute-reference#when_section"
110139
},
111140
"#with": {
112141
"prefix": "with",
@@ -115,7 +144,8 @@
115144
"\t{${2:name}}$0",
116145
"{/with}"
117146
],
118-
"description": "With section"
147+
"description": "With section",
148+
"url": "https://quarkus.io/guides/qute-reference#with_section"
119149
},
120150
"#when": {
121151
"prefix": "when",
@@ -124,6 +154,7 @@
124154
"\t{#is ${2:case}}$0",
125155
"{/when}"
126156
],
127-
"description": "When section"
157+
"description": "When section",
158+
"url": "https://quarkus.io/guides/qute-reference#when_section"
128159
}
129160
}

qute.ls/com.redhat.qute.ls/src/test/java/com/redhat/qute/QuteAssert.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public class QuteAssert {
106106

107107
private static final String FILE_URI = "test.qute";
108108

109-
public static final int SECTION_SNIPPET_SIZE = 14 /* #each, #for */ + 3 /* #user, #formElement */;
109+
public static final int SECTION_SNIPPET_SIZE = 15 /* #each, #for, ... #fragment ... */ + 3 /* #user, #formElement */;
110110

111111
public static String getFileUri(String templateFile) {
112112
return Paths.get(TEMPLATE_BASE_DIR + templateFile).toUri().toString();

qute.ls/com.redhat.qute.ls/src/test/java/com/redhat/qute/services/diagnostics/QuteDiagnosticsInExpressionTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ public void quoteNoteClosed() throws Exception {
511511
"{foo.getBytes('abcd)}";
512512
testDiagnosticsFor(template, //
513513
d(1, 22, 1, 22, QuteErrorCode.SyntaxError,
514-
"Parser error on line 2: unexpected non-text buffer at the end of the template - unterminated string literal: foo.getBytes('abcd)}",
514+
"Parser error: unexpected non-text buffer at the end of the template - unterminated string literal: foo.getBytes('abcd)}",
515515
DiagnosticSeverity.Error));
516516

517517
}

qute.ls/com.redhat.qute.ls/src/test/java/com/redhat/qute/services/diagnostics/QuteDiagnosticsInExpressionWithLetSectionTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void autoClose() throws Exception {
9494

9595
testDiagnosticsFor(template, //
9696
d(2, 6, 2, 6, QuteErrorCode.SyntaxError,
97-
"Parser error on line 3: no section start tag found for {/let}", DiagnosticSeverity.Error), //
97+
"Parser error: no section start tag found for {/let}", DiagnosticSeverity.Error), //
9898
d);
9999
testCodeActionsFor(template, d, //
100100
ca(d, te(0, 0, 0, 0, "{@java.lang.String name}\r\n")),

qute.ls/com.redhat.qute.ls/src/test/java/com/redhat/qute/services/diagnostics/QuteDiagnosticsInExpressionWithNamespaceTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void badNamespace() throws Exception {
130130
Diagnostic d = d(0, 1, 0, 2, QuteErrorCode.UndefinedNamespace, "No namespace resolver found for: `X`.",
131131
DiagnosticSeverity.Warning);
132132
testDiagnosticsFor(template,
133-
d(0, 0, 0, 3, QuteErrorCode.SyntaxError, "Parser error on line 1: empty expression found {X:}",
133+
d(0, 0, 0, 3, QuteErrorCode.SyntaxError, "Parser error on: empty expression found {X:}",
134134
DiagnosticSeverity.Error), //
135135
d);
136136

qute.ls/com.redhat.qute.ls/src/test/java/com/redhat/qute/services/diagnostics/QuteDiagnosticsSyntaxErrorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class QuteDiagnosticsSyntaxErrorTest {
2929
public void emptyParameterDeclaration() {
3030
String template = "{@}";
3131
testDiagnosticsFor(template, //
32-
d(0, 2, 0, 2, QuteErrorCode.SyntaxError, "Parser error on line 1: invalid parameter declaration {@}",
32+
d(0, 2, 0, 2, QuteErrorCode.SyntaxError, "Parser error: invalid parameter declaration {@}",
3333
DiagnosticSeverity.Error));
3434
}
3535
}

qute.ls/com.redhat.qute.ls/src/test/java/com/redhat/qute/services/diagnostics/QuteDiagnosticsWithIncludeSectionTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void templateNotDefined() throws Exception {
3131
testDiagnosticsFor(template, //
3232
// error coming from the real Qute parser
3333
d(0, 11, 0, 11, QuteErrorCode.SyntaxError,
34-
"Parser error on line 1: mandatory section parameters not declared for {#include /}: [template]",
34+
"Parser error: mandatory section parameters not declared for {#include /}: [template]",
3535
DiagnosticSeverity.Error), //
3636
// error coming from Qute LS parser
3737
d(0, 1, 0, 9, QuteErrorCode.TemplateNotDefined, "Template id must be defined as parameter.",

qute.ls/com.redhat.qute.ls/src/test/java/com/redhat/qute/services/hover/QuteHoverInTag.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ public void coreTag() throws Exception {
3838
assertHover(template, "**#for** section tag " + //
3939
System.lineSeparator() + //
4040
System.lineSeparator() + //
41-
"Loop section with alias", //
41+
"Loop section with alias" + //
42+
System.lineSeparator() + //
43+
"See [here](https://quarkus.io/guides/qute-reference#loop_section) for more informations.", //
4244
r(0, 1, 0, 5));
4345
}
4446

qute.ls/com.redhat.qute.ls/src/test/java/com/redhat/qute/services/hover/QuteHoverInUserTag.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ public void parameterPropertyPart() throws Exception {
4444
System.lineSeparator() + //
4545
"String org.acme.Item.name" + //
4646
System.lineSeparator() + //
47-
"```", //
47+
"```" + //
48+
System.lineSeparator() + //
49+
"---" + //
50+
System.lineSeparator() + //
51+
"The name of the item", //
4852
r(1, 17, 1, 21));
4953
}
5054

@@ -68,7 +72,11 @@ public void itParameterPropertyPart() throws Exception {
6872
System.lineSeparator() + //
6973
"String org.acme.Item.name" + //
7074
System.lineSeparator() + //
71-
"```", //
75+
"```" + //
76+
System.lineSeparator() + //
77+
"---" + //
78+
System.lineSeparator() + //
79+
"The name of the item", //
7280
r(1, 12, 1, 16));
7381
}
7482

0 commit comments

Comments
 (0)