line comment action: correct for the case of embedded part on the line

- when the selected line contains embedded fragment with the other language,
line still can be commented with the wrapping language comment symbols

WEB-29018 vue files with jade/pug as lang - comments not working!
This commit is contained in:
Irina.Chernushina
2017-10-12 14:09:26 +02:00
parent a3483dbfd8
commit 4f771a9e92
2 changed files with 17 additions and 1 deletions
@@ -332,11 +332,20 @@ public class PsiTreeUtil {
@Nullable
public static PsiElement findFirstParent(@Nullable PsiElement element, boolean strict, Condition<PsiElement> condition) {
//noinspection unchecked
return findFirstParent(element, strict, condition, Condition.FALSE);
}
@Nullable
public static PsiElement findFirstParent(@Nullable PsiElement element, boolean strict,
@NotNull final Condition<PsiElement> condition,
@NotNull final Condition<PsiElement> stopCondition) {
if (strict && element != null) {
element = element.getParent();
}
while (element != null) {
if (stopCondition.value(element)) return null;
if (condition.value(element)) {
return element;
}
@@ -133,7 +133,14 @@ public class PsiUtilBase extends PsiUtilCore implements PsiEditorUtil {
lang = language;
}
else if (lang != language) {
return null;
// correctly process the case when leaf element is a part of embedded fragment, but it is totally contained inside
// "parent" language
Language finalLang = lang;
final TextRange range = new TextRange(start, end);
final PsiElement wrappingParent = PsiTreeUtil.findFirstParent(
elt, false, element -> file.equals(element.getContainingFile()) && finalLang.equals(element.getLanguage()),
element -> element.getTextRange() != null && !range.contains(element.getTextRange()));
if (wrappingParent == null) return null;
}
}
TextRange range = elt.getTextRange();