matthiasblaesing commented on code in PR #8401: URL: https://github.com/apache/netbeans/pull/8401#discussion_r2083597159
########## webcommon/javascript2.vue/src/org/netbeans/modules/javascript2/vue/editor/embedding/VueHtmlEmbeddingProvider.java: ########## @@ -56,17 +61,26 @@ public List<Embedding> getEmbeddings(final Snapshot snapshot) { try { while (ts.moveNext()) { - Token<?> t = ts.token(); - TokenId id = t.id(); + Token<?> token = ts.token(); + TokenId id = token.id(); - if (id.equals(VueTokenId.HTML)) { - embeddings.add(snapshot.create(ts.offset(), t.length(), TARGET_MIME_TYPE)); + if (token.text() != null && id instanceof VueTokenId) { + switch ((VueTokenId) id) { + //javascript, css, scss, less require content embedding due to braces matcher issue + case HTML, JAVASCRIPT, CSS -> { + embeddings.add(snapshot.create(ts.offset(), token.length(), TARGET_MIME_TYPE)); + } + case STYLE_SCSS, STYLE_LESS -> { + String fake = new String(new char[token.text().length()]).replace("\0", FILLER); //NOI18N + embeddings.add(snapshot.create(fake, TARGET_MIME_TYPE)); + } + } Review Comment: This looks strange. The VueHtmlEmbeddingProvider should provide embedding for HTML. The other embeddings should be handled/and are being handled by their respecitve counter parts. ########## webcommon/javascript2.vue/src/org/netbeans/modules/javascript2/vue/editor/embedding/VueJsEmbeddingProvider.java: ########## @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.javascript2.vue.editor.embedding; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.netbeans.api.lexer.Token; +import org.netbeans.api.lexer.TokenHierarchy; +import org.netbeans.api.lexer.TokenId; +import org.netbeans.api.lexer.TokenSequence; +import org.netbeans.modules.javascript2.vue.editor.VueLanguage; +import static org.netbeans.modules.javascript2.vue.editor.embedding.VueJsEmbeddingProvider.TARGET_MIME_TYPE; +import org.netbeans.modules.javascript2.vue.editor.lexer.VueTokenId; +import org.netbeans.modules.parsing.api.Embedding; +import org.netbeans.modules.parsing.api.Snapshot; +import org.netbeans.modules.parsing.spi.EmbeddingProvider; + +/** + * + * + * @author bhaidu + */ Review Comment: Please remove. The author information is available from git history. ########## ide/css.lib/src/org/netbeans/modules/css/lib/nbparser/CssParser.java: ########## @@ -81,24 +81,40 @@ public void parse(Snapshot snapshot, Task task, SourceModificationEvent event) t if (snapshot == null) { return; } - + this.snapshot = snapshot; FileObject fo = snapshot.getSource().getFileObject(); - String fileName = fo == null ? "no file" : fo.getPath(); //NOI18N - String mimeType = topLevelSnapshotMimetype != null ? topLevelSnapshotMimetype : (fo == null ? null : fo.getMIMEType()); + String fileName; + String mimeType; + if (fo != null) { + fileName= fo.getPath(); + MimePath mimePath = snapshot.getMimePath(); + + //scss, less mime embedding is a top layer for text/css + //positioned at the penultimate position + if (mimePath != null && mimePath.size() > 2) { + mimeType = mimePath.getMimeType(mimePath.size() - 2); + } else { + mimeType = fo.getMIMEType(); + } + } else { + fileName = "no file"; + mimeType = topLevelSnapshotMimetype; + } Review Comment: ```suggestion if (topLevelSnapshotMimetype == null) { fileName= fo.getPath(); MimePath mimePath = snapshot.getMimePath(); //scss, less mime embedding is a top layer for text/css //positioned at the penultimate position if (mimePath != null && mimePath.size() > 2) { mimeType = mimePath.getMimeType(mimePath.size() - 2); } else { mimeType = snapshot.getMimeType(); } } else { fileName = "no file"; mimeType = topLevelSnapshotMimetype; } ``` ########## webcommon/javascript2.vue/src/org/netbeans/modules/javascript2/vue/grammar/antlr4/coloring/VueAntlrColoringLexer.g4: ########## @@ -85,16 +100,34 @@ SCRIPT_ATTR_QUOTE : '"' {this.setAttrQuoteState(true);}->type(QUOTE_ATTR); SCRIPT_ATTR_OTHER : . ->type(JAVASCRIPT_ATTR); EXIT_SCRIPT_ATTR_EOF : EOF->type(HTML),popMode; +mode INSIDE_STYLE_TAG_START; + +STYLE_LANG_ATTR : 'lang=' StringLiteral {this.setStyleLanguage();}->type(HTML); Review Comment: see comment about HTML5 structure above. ########## webcommon/javascript2.vue/src/org/netbeans/modules/javascript2/vue/editor/lexer/VueTokenId.java: ########## @@ -37,8 +40,12 @@ public enum VueTokenId implements TokenId { HTML("html"), // NOI18N CSS("css"), // NOI18N + STYLE_SCSS("css"), // NOI18N + STYLE_LESS("css"), // NOI18N Review Comment: Will this scale? Webdevelopers have the tendency to reinvent the wheel (LESS, SCSS, SASS and now also JS variants). ########## webcommon/javascript2.vue/src/org/netbeans/modules/javascript2/vue/grammar/antlr4/coloring/ColoringLexerAdaptor.java: ########## @@ -76,4 +61,43 @@ public void setVarInterpolationOpened(boolean state) { public boolean isVarInterpolationOpened() { return varInterpolationOpened; } + + public void setScriptLanguage(String lang) { + scriptLanguage = lang; + } + + public void setScriptLanguage() { + scriptLanguage = extractLangFromInput(); + } + + public String getScriptLanguage() { + return scriptLanguage; + } + + public void setStyleLanguage(String lang) { + scriptLanguage = lang; + } + + public void setStyleLanguage() { + styleLanguage = extractLangFromInput(); + } + + public String getStyleLanguage() { + return styleLanguage; + } + + private String extractLangFromInput() { + String input = this.getText(); + String langAttrEq = LANG_ATTR + "="; //NOI18N + if (input == null || !input.startsWith(langAttrEq)) { + return null; + } + String langValue = input.substring(langAttrEq.length()); + //check if only quotes + if (langValue.length() == 2) { + return null; + } + + return langValue.substring(1, langValue.length() - 1); Review Comment: Is this safe? HTML allows unquoted attributes and there maybe spaces between attribute, equals sign and value. Is the same true for vue? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org For additional commands, e-mail: notifications-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists