mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-177766 Properly find in comments inside javascript
Fix for special case that javascript is inside html and html is inside template language like php / jsp
This commit is contained in:
@@ -608,7 +608,28 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
fixture.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
public void testFindInCommentsInJsInsideHtml() {
|
||||
FindModel findModel = FindManagerTestUtils.configureFindModel("@param t done");
|
||||
|
||||
String text = "<script>\n" +
|
||||
"/**\n" +
|
||||
" * @param t done\n" +
|
||||
" * @param t done\n" +
|
||||
" * @param t done\n" +
|
||||
"*/</script>";
|
||||
findModel.setSearchContext(FindModel.SearchContext.IN_COMMENTS);
|
||||
FindManager findManager = FindManager.getInstance(myProject);
|
||||
FindManagerTestUtils.runFindForwardAndBackward(findManager, findModel, text, "html");
|
||||
|
||||
findModel.setRegularExpressions(true);
|
||||
FindManagerTestUtils.runFindForwardAndBackward(findManager, findModel, text, "html");
|
||||
|
||||
FindManagerTestUtils.runFindForwardAndBackward(findManager, findModel, text, "php");
|
||||
findModel.setRegularExpressions(false);
|
||||
FindManagerTestUtils.runFindForwardAndBackward(findManager, findModel, text, "php");
|
||||
}
|
||||
|
||||
public void testFindInCommentsAndLiterals() {
|
||||
FindModel findModel = FindManagerTestUtils.configureFindModel("done");
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.intellij.lang.Language;
|
||||
import com.intellij.lang.LanguageParserDefinitions;
|
||||
import com.intellij.lang.LanguageUtil;
|
||||
import com.intellij.lang.ParserDefinition;
|
||||
import com.intellij.lexer.LayeredLexer;
|
||||
import com.intellij.lexer.Lexer;
|
||||
import com.intellij.navigation.NavigationItem;
|
||||
import com.intellij.notification.NotificationDisplayType;
|
||||
@@ -604,11 +605,19 @@ public class FindManagerImpl extends FindManager {
|
||||
|
||||
Matcher matcher = model.isRegularExpressions() ? compileRegExp(model, "") : null;
|
||||
StringSearcher searcher = matcher != null ? null : new StringSearcher(model.getStringToFind(), model.isCaseSensitive(), true);
|
||||
SyntaxHighlighterOverEditorHighlighter highlighterAdapter =
|
||||
new SyntaxHighlighterOverEditorHighlighter(highlighter, file, myProject);
|
||||
data =
|
||||
new CommentsLiteralsSearchData(file, relevantLanguages, highlighterAdapter, tokensOfInterest, searcher, matcher, model.clone());
|
||||
data.highlighter.restart(text);
|
||||
LayeredLexer.ourDisableLayersFlag.set(Boolean.TRUE);
|
||||
|
||||
try {
|
||||
SyntaxHighlighterOverEditorHighlighter highlighterAdapter =
|
||||
new SyntaxHighlighterOverEditorHighlighter(highlighter, file, myProject);
|
||||
data =
|
||||
new CommentsLiteralsSearchData(file, relevantLanguages, highlighterAdapter, tokensOfInterest, searcher, matcher, model.clone());
|
||||
data.highlighter.restart(text);
|
||||
}
|
||||
finally {
|
||||
LayeredLexer.ourDisableLayersFlag.set(null);
|
||||
}
|
||||
|
||||
model.putUserData(ourCommentsLiteralsSearchDataKey, data);
|
||||
}
|
||||
|
||||
|
||||
+5
-12
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.usages.impl;
|
||||
|
||||
import com.intellij.lexer.LayeredLexer;
|
||||
import com.intellij.lexer.Lexer;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.openapi.editor.ex.util.LayeredHighlighterIterator;
|
||||
@@ -43,19 +42,13 @@ public class SyntaxHighlighterOverEditorHighlighter implements SyntaxHighlighter
|
||||
lexer = highlighter.getHighlightingLexer();
|
||||
} else {
|
||||
highlighter = _highlighter;
|
||||
LayeredLexer.ourDisableLayersFlag.set(Boolean.TRUE);
|
||||
EditorHighlighter editorHighlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(project, file);
|
||||
|
||||
try {
|
||||
if (editorHighlighter instanceof LayeredLexerEditorHighlighter) {
|
||||
lexer = new LexerEditorHighlighterLexer(editorHighlighter, false);
|
||||
}
|
||||
else {
|
||||
lexer = highlighter.getHighlightingLexer();
|
||||
}
|
||||
|
||||
if (editorHighlighter instanceof LayeredLexerEditorHighlighter) {
|
||||
lexer = new LexerEditorHighlighterLexer(editorHighlighter, false);
|
||||
}
|
||||
finally {
|
||||
LayeredLexer.ourDisableLayersFlag.set(null);
|
||||
else {
|
||||
lexer = highlighter.getHighlightingLexer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ public class HtmlHighlightingLexer extends BaseHtmlLexer {
|
||||
private final Map<String, Lexer> scriptLexers = new HashMap<>();
|
||||
private final Map<String, Lexer> styleLexers = new HashMap<>();
|
||||
private boolean hasNoEmbeddments;
|
||||
private final boolean hasNoLayers;
|
||||
|
||||
public HtmlHighlightingLexer() {
|
||||
this(null);
|
||||
@@ -61,6 +62,7 @@ public class HtmlHighlightingLexer extends BaseHtmlLexer {
|
||||
|
||||
protected HtmlHighlightingLexer(Lexer lexer, boolean caseInsensitive, FileType styleFileType) {
|
||||
super(lexer, caseInsensitive);
|
||||
hasNoLayers = Boolean.TRUE.equals(LayeredLexer.ourDisableLayersFlag.get());
|
||||
ourStyleFileType = styleFileType;
|
||||
|
||||
XmlEmbeddmentHandler value = new XmlEmbeddmentHandler();
|
||||
@@ -87,66 +89,71 @@ public class HtmlHighlightingLexer extends BaseHtmlLexer {
|
||||
}
|
||||
|
||||
private void setEmbeddedLexer() {
|
||||
Lexer newLexer = null;
|
||||
if (hasSeenStyle()) {
|
||||
Lexer styleLexer = styleLexers.get(styleType);
|
||||
if (styleLexer == null) {
|
||||
if (hasSeenTag()) {
|
||||
IElementType currentStylesheetElementType = getCurrentStylesheetElementType();
|
||||
if (currentStylesheetElementType != null) {
|
||||
Language language = currentStylesheetElementType.getLanguage();
|
||||
styleLexer = SyntaxHighlighterFactory.getSyntaxHighlighter(language, null, null).getHighlightingLexer();
|
||||
if (hasNoLayers) LayeredLexer.ourDisableLayersFlag.set(Boolean.TRUE);
|
||||
try {
|
||||
Lexer newLexer = null;
|
||||
if (hasSeenStyle()) {
|
||||
Lexer styleLexer = styleLexers.get(styleType);
|
||||
if (styleLexer == null) {
|
||||
if (hasSeenTag()) {
|
||||
IElementType currentStylesheetElementType = getCurrentStylesheetElementType();
|
||||
if (currentStylesheetElementType != null) {
|
||||
Language language = currentStylesheetElementType.getLanguage();
|
||||
styleLexer = SyntaxHighlighterFactory.getSyntaxHighlighter(language, null, null).getHighlightingLexer();
|
||||
}
|
||||
else if (ourStyleFileType != null) {
|
||||
SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(ourStyleFileType, null, null);
|
||||
LOG.assertTrue(highlighter != null, ourStyleFileType);
|
||||
styleLexer = highlighter.getHighlightingLexer();
|
||||
}
|
||||
else {
|
||||
styleLexer = null;
|
||||
}
|
||||
styleLexers.put(styleType, styleLexer);
|
||||
}
|
||||
else if (ourStyleFileType != null) {
|
||||
SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(ourStyleFileType, null, null);
|
||||
LOG.assertTrue(highlighter != null, ourStyleFileType);
|
||||
styleLexer = highlighter.getHighlightingLexer();
|
||||
}
|
||||
else {
|
||||
styleLexer = null;
|
||||
}
|
||||
styleLexers.put(styleType, styleLexer);
|
||||
}
|
||||
else if (hasSeenAttribute()) {
|
||||
if (ourStyleFileType == null) {
|
||||
styleLexer = null;
|
||||
}
|
||||
else {
|
||||
SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(ourStyleFileType, null, null);
|
||||
LOG.assertTrue(highlighter != null, ourStyleFileType);
|
||||
styleLexer = highlighter.getHighlightingLexer();
|
||||
else if (hasSeenAttribute()) {
|
||||
if (ourStyleFileType == null) {
|
||||
styleLexer = null;
|
||||
}
|
||||
else {
|
||||
SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(ourStyleFileType, null, null);
|
||||
LOG.assertTrue(highlighter != null, ourStyleFileType);
|
||||
styleLexer = highlighter.getHighlightingLexer();
|
||||
}
|
||||
}
|
||||
}
|
||||
newLexer = styleLexer;
|
||||
}
|
||||
newLexer = styleLexer;
|
||||
}
|
||||
else if (hasSeenScript()) {
|
||||
Lexer scriptLexer = scriptLexers.get(scriptType);
|
||||
if (scriptLexer == null) {
|
||||
if (hasSeenTag()) {
|
||||
HtmlScriptContentProvider provider = findScriptContentProvider(scriptType);
|
||||
if (provider != null) {
|
||||
scriptLexer = provider.getHighlightingLexer();
|
||||
else if (hasSeenScript()) {
|
||||
Lexer scriptLexer = scriptLexers.get(scriptType);
|
||||
if (scriptLexer == null) {
|
||||
if (hasSeenTag()) {
|
||||
HtmlScriptContentProvider provider = findScriptContentProvider(scriptType);
|
||||
if (provider != null) {
|
||||
scriptLexer = provider.getHighlightingLexer();
|
||||
}
|
||||
else {
|
||||
scriptLexer = SyntaxHighlighterFactory.getSyntaxHighlighter(PlainTextLanguage.INSTANCE, null, null).getHighlightingLexer();
|
||||
}
|
||||
}
|
||||
else {
|
||||
scriptLexer = SyntaxHighlighterFactory.getSyntaxHighlighter(PlainTextLanguage.INSTANCE, null, null).getHighlightingLexer();
|
||||
else if (hasSeenAttribute()) {
|
||||
SyntaxHighlighter syntaxHighlighter =
|
||||
ourInlineScriptFileType != null ? SyntaxHighlighterFactory.getSyntaxHighlighter(ourInlineScriptFileType, null, null) : null;
|
||||
scriptLexer = syntaxHighlighter != null ? syntaxHighlighter.getHighlightingLexer() : null;
|
||||
}
|
||||
scriptLexers.put(scriptType, scriptLexer);
|
||||
}
|
||||
else if (hasSeenAttribute()) {
|
||||
SyntaxHighlighter syntaxHighlighter =
|
||||
ourInlineScriptFileType != null ? SyntaxHighlighterFactory.getSyntaxHighlighter(ourInlineScriptFileType, null, null) : null;
|
||||
scriptLexer = syntaxHighlighter != null ? syntaxHighlighter.getHighlightingLexer() : null;
|
||||
}
|
||||
scriptLexers.put(scriptType, scriptLexer);
|
||||
newLexer = scriptLexer;
|
||||
}
|
||||
else {
|
||||
newLexer = createELLexer(newLexer);
|
||||
}
|
||||
newLexer = scriptLexer;
|
||||
}
|
||||
else {
|
||||
newLexer = createELLexer(newLexer);
|
||||
}
|
||||
|
||||
if (newLexer != null) {
|
||||
embeddedLexer = newLexer;
|
||||
if (newLexer != null) {
|
||||
embeddedLexer = newLexer;
|
||||
}
|
||||
} finally {
|
||||
if (hasNoLayers) LayeredLexer.ourDisableLayersFlag.set(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user