Skip to content

Commit 525e741

Browse files
committed
VUE JS: include parametric embedding support for javascript, pug | jade, less, sass
remove uncessary antlr lexer flags update embeddng code test, update author comment
1 parent 1d08f46 commit 525e741

30 files changed

+946
-156
lines changed

Diff for: ide/css.lib/src/org/netbeans/modules/css/lib/nbparser/CssParser.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,23 @@ public void parse(Snapshot snapshot, Task task, SourceModificationEvent event) t
9393

9494
//parse just an empty string in case of an oversize snapshot
9595
CharSequence source = tooLargeSnapshot ? "" : snapshot.getText();
96-
96+
97+
String mimePath = snapshot.getMimePath() != null ? snapshot.getMimePath().getPath() : null;
98+
if (mimePath != null) {
99+
//vue plugin embedding
100+
if (mimePath.startsWith("text/x-vue/text/scss")) { //NOI18N
101+
mimeType = "text/scss"; //NOI18N
102+
} else if (mimePath.startsWith("text/x-vue/text/less")){ //NOI18N
103+
mimeType = "text/less"; //NOI18N
104+
}
105+
}
106+
97107
ExtCss3Lexer lexer = new ExtCss3Lexer(source, mimeType);
98108
TokenStream tokenstream = new ProgressingTokenStream(
99109
10_000_000,
100110
new CommonTokenStream(lexer));
101111
NbParseTreeBuilder builder = new NbParseTreeBuilder(source);
112+
102113
ExtCss3Parser parser = new ExtCss3Parser(tokenstream, builder, mimeType);
103114

104115
if (cancelled.get()) {

Diff for: webcommon/javascript2.jade/nbproject/project.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,10 @@
338338
</test-dependency>
339339
</test-type>
340340
</test-dependencies>
341-
<public-packages/>
341+
<friend-packages>
342+
<friend>org.netbeans.modules.javascript2.vue</friend>
343+
<package>org.netbeans.modules.javascript2.jade.editor.lexer</package>
344+
</friend-packages>
342345
</data>
343346
</configuration>
344347
</project>

Diff for: webcommon/javascript2.vue/nbproject/project.xml

+33
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@
8585
<release-version>1</release-version>
8686
</run-dependency>
8787
</dependency>
88+
<dependency>
89+
<code-name-base>org.netbeans.modules.javascript2.jade</code-name-base>
90+
<build-prerequisite/>
91+
<compile-dependency/>
92+
<run-dependency>
93+
<release-version>1</release-version>
94+
<specification-version>0.34</specification-version>
95+
</run-dependency>
96+
</dependency>
8897
<dependency>
8998
<code-name-base>org.netbeans.modules.javascript2.lexer</code-name-base>
9099
<build-prerequisite/>
@@ -177,6 +186,10 @@
177186
<compile-dependency/>
178187
<test/>
179188
</test-dependency>
189+
<test-dependency>
190+
<code-name-base>org.netbeans.modules.editor.mimelookup.impl</code-name-base>
191+
<recursive/>
192+
</test-dependency>
180193
<test-dependency>
181194
<code-name-base>org.netbeans.modules.javascript2.lexer</code-name-base>
182195
<recursive/>
@@ -189,17 +202,37 @@
189202
<compile-dependency/>
190203
<test/>
191204
</test-dependency>
205+
<test-dependency>
206+
<code-name-base>org.netbeans.modules.lexer</code-name-base>
207+
<recursive/>
208+
<compile-dependency/>
209+
<test/>
210+
</test-dependency>
211+
<test-dependency>
212+
<code-name-base>org.netbeans.modules.lexer.nbbridge</code-name-base>
213+
<compile-dependency/>
214+
</test-dependency>
192215
<test-dependency>
193216
<code-name-base>org.netbeans.modules.nbjunit</code-name-base>
194217
<recursive/>
195218
<compile-dependency/>
196219
</test-dependency>
220+
<test-dependency>
221+
<code-name-base>org.netbeans.modules.projectapi.nb</code-name-base>
222+
</test-dependency>
197223
<test-dependency>
198224
<code-name-base>org.netbeans.modules.parsing.api</code-name-base>
199225
<recursive/>
200226
<compile-dependency/>
201227
<test/>
202228
</test-dependency>
229+
<test-dependency>
230+
<code-name-base>org.netbeans.modules.parsing.nb</code-name-base>
231+
</test-dependency>
232+
<test-dependency>
233+
<code-name-base>org.netbeans.modules.parsing.api</code-name-base>
234+
<test/>
235+
</test-dependency>
203236
<test-dependency>
204237
<code-name-base>org.netbeans.modules.projectapi</code-name-base>
205238
<recursive/>

Diff for: webcommon/javascript2.vue/src/org/netbeans/modules/javascript2/vue/editor/VueLanguage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
*
4848
* @author bogdan.haidu
4949
*/
50-
@LanguageRegistration(mimeType = "text/x-vue", useMultiview = true) //NOI18N
50+
@LanguageRegistration(mimeType = "text/x-vue", useMultiview = true)
5151
public class VueLanguage extends DefaultLanguageConfig {
5252

5353
public static final String MIME_TYPE = "text/x-vue"; //NOI18N

Diff for: webcommon/javascript2.vue/src/org/netbeans/modules/javascript2/vue/editor/embedding/VueCssEmbeddingProvider.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.netbeans.api.lexer.TokenId;
2727
import org.netbeans.api.lexer.TokenSequence;
2828
import org.netbeans.modules.javascript2.vue.editor.VueLanguage;
29+
import static org.netbeans.modules.javascript2.vue.editor.embedding.VueCssEmbeddingProvider.TARGET_MIME_TYPE;
2930
import org.netbeans.modules.javascript2.vue.editor.lexer.VueTokenId;
3031
import org.netbeans.modules.parsing.api.Embedding;
3132
import org.netbeans.modules.parsing.api.Snapshot;
@@ -38,7 +39,7 @@
3839
*/
3940
@EmbeddingProvider.Registration(
4041
mimeType = VueLanguage.MIME_TYPE,
41-
targetMimeType = "text/css")
42+
targetMimeType = TARGET_MIME_TYPE)
4243
public class VueCssEmbeddingProvider extends EmbeddingProvider {
4344
public static final String TARGET_MIME_TYPE = "text/css"; //NOI18N
4445

Diff for: webcommon/javascript2.vue/src/org/netbeans/modules/javascript2/vue/editor/embedding/VueHtmlEmbeddingProvider.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,22 @@
3333

3434
/**
3535
* this will enable braces matches of html elements
36-
*
36+
*
3737
* @author bhaidu
3838
*/
3939
@EmbeddingProvider.Registration(
4040
mimeType = VueLanguage.MIME_TYPE,
4141
targetMimeType = "text/html")
4242
public class VueHtmlEmbeddingProvider extends EmbeddingProvider {
43+
4344
public static final String FILLER = " "; //NOI18N
4445
public static final String TARGET_MIME_TYPE = "text/html"; //NOI18N
4546

4647
@Override
4748
public List<Embedding> getEmbeddings(final Snapshot snapshot) {
4849
TokenHierarchy<?> tokenHierarchy = snapshot.getTokenHierarchy();
4950
TokenSequence<?> ts = tokenHierarchy.tokenSequence();
50-
51+
5152
if (ts == null || !ts.isValid()) {
5253
return Collections.emptyList();
5354
}
@@ -61,12 +62,16 @@ public List<Embedding> getEmbeddings(final Snapshot snapshot) {
6162

6263
if (id.equals(VueTokenId.HTML)) {
6364
embeddings.add(snapshot.create(ts.offset(), t.length(), TARGET_MIME_TYPE));
65+
} else if (t.text() != null) {
66+
//issue with bracematcher
67+
String fake = new String(new char[t.text().toString().length()]).replace("\0", FILLER); //NOI18N
68+
embeddings.add(snapshot.create(fake, TARGET_MIME_TYPE));
6469
}
6570
}
6671
} catch (Exception ex) {
6772
return Collections.emptyList();
6873
}
69-
74+
7075
if (embeddings.isEmpty()) {
7176
return Collections.emptyList();
7277
} else {
@@ -80,5 +85,6 @@ public int getPriority() {
8085
}
8186

8287
@Override
83-
public void cancel() { }
88+
public void cancel() {
89+
}
8490
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.netbeans.modules.javascript2.vue.editor.embedding;
20+
21+
import java.util.ArrayList;
22+
import java.util.Collections;
23+
import java.util.List;
24+
import org.netbeans.api.lexer.Token;
25+
import org.netbeans.api.lexer.TokenHierarchy;
26+
import org.netbeans.api.lexer.TokenId;
27+
import org.netbeans.api.lexer.TokenSequence;
28+
import org.netbeans.modules.javascript2.vue.editor.VueLanguage;
29+
import static org.netbeans.modules.javascript2.vue.editor.embedding.VueJsEmbeddingProvider.TARGET_MIME_TYPE;
30+
import org.netbeans.modules.javascript2.vue.editor.lexer.VueTokenId;
31+
import org.netbeans.modules.parsing.api.Embedding;
32+
import org.netbeans.modules.parsing.api.Snapshot;
33+
import org.netbeans.modules.parsing.spi.EmbeddingProvider;
34+
35+
/**
36+
*
37+
*
38+
* @author bhaidu
39+
*/
40+
@EmbeddingProvider.Registration(
41+
mimeType = VueLanguage.MIME_TYPE,
42+
targetMimeType = TARGET_MIME_TYPE)
43+
public class VueJsEmbeddingProvider extends EmbeddingProvider {
44+
public static final String TARGET_MIME_TYPE = "text/javascript"; //NOI18N
45+
46+
@Override
47+
public List<Embedding> getEmbeddings(Snapshot snapshot) {
48+
TokenHierarchy<?> tokenHierarchy = snapshot.getTokenHierarchy();
49+
TokenSequence<?> ts = tokenHierarchy.tokenSequence();
50+
51+
if (ts == null || !ts.isValid()) {
52+
return Collections.emptyList();
53+
}
54+
55+
ts.moveStart();
56+
57+
List<Embedding> embeddings = new ArrayList<>();
58+
59+
while (ts.moveNext()) {
60+
Token<?> token = ts.token();
61+
TokenId id = token.id();
62+
if (id.equals(VueTokenId.JAVASCRIPT)) {
63+
embeddings.add(snapshot.create(ts.offset(), token.length(), TARGET_MIME_TYPE));
64+
}
65+
}
66+
67+
if (embeddings.isEmpty()) {
68+
return Collections.emptyList();
69+
}
70+
return Collections.singletonList(Embedding.create(embeddings));
71+
72+
}
73+
74+
@Override
75+
public int getPriority() {
76+
return 220;
77+
}
78+
79+
@Override
80+
public void cancel() {
81+
// nothing so far
82+
}
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.netbeans.modules.javascript2.vue.editor.embedding;
20+
21+
import java.util.ArrayList;
22+
import java.util.Collections;
23+
import java.util.List;
24+
import org.netbeans.api.lexer.Token;
25+
import org.netbeans.api.lexer.TokenHierarchy;
26+
import org.netbeans.api.lexer.TokenId;
27+
import org.netbeans.api.lexer.TokenSequence;
28+
import org.netbeans.modules.javascript2.vue.editor.VueLanguage;
29+
import static org.netbeans.modules.javascript2.vue.editor.embedding.VueLessEmbeddingProvider.TARGET_MIME_TYPE;
30+
import org.netbeans.modules.javascript2.vue.editor.lexer.VueTokenId;
31+
import org.netbeans.modules.parsing.api.Embedding;
32+
import org.netbeans.modules.parsing.api.Snapshot;
33+
import org.netbeans.modules.parsing.spi.EmbeddingProvider;
34+
35+
/**
36+
*
37+
*
38+
* @author bhaidu
39+
*/
40+
@EmbeddingProvider.Registration(
41+
mimeType = VueLanguage.MIME_TYPE,
42+
targetMimeType = TARGET_MIME_TYPE)
43+
public class VueLessEmbeddingProvider extends EmbeddingProvider {
44+
public static final String TARGET_MIME_TYPE = "text/less"; //NOI18N
45+
46+
@Override
47+
public List<Embedding> getEmbeddings(Snapshot snapshot) {
48+
TokenHierarchy<?> tokenHierarchy = snapshot.getTokenHierarchy();
49+
TokenSequence<?> ts = tokenHierarchy.tokenSequence();
50+
51+
if (ts == null || !ts.isValid()) {
52+
return Collections.emptyList();
53+
}
54+
55+
ts.moveStart();
56+
57+
List<Embedding> embeddings = new ArrayList<>();
58+
59+
while (ts.moveNext()) {
60+
Token<?> token = ts.token();
61+
TokenId id = token.id();
62+
if (id.equals(VueTokenId.STYLE_LESS)) {
63+
embeddings.add(snapshot.create(ts.offset(), token.length(), TARGET_MIME_TYPE));
64+
}
65+
}
66+
67+
if (embeddings.isEmpty()) {
68+
return Collections.emptyList();
69+
}
70+
return Collections.singletonList(Embedding.create(embeddings));
71+
72+
}
73+
74+
@Override
75+
public int getPriority() {
76+
return 220;
77+
}
78+
79+
@Override
80+
public void cancel() {
81+
// nothing so far
82+
}
83+
}

0 commit comments

Comments
 (0)