mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RUBY-18345: Fix YAML scalars content retrieval when template is injected
Now the "get content" routine is made agnostic to its token-type contents
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package org.jetbrains.yaml.psi.impl;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.yaml.YAMLTokenTypes;
|
||||
import org.jetbrains.yaml.YAMLUtil;
|
||||
|
||||
@@ -43,23 +45,31 @@ public abstract class YAMLBlockScalarImpl extends YAMLScalarImpl {
|
||||
|
||||
int thisLineStart = firstEol.getStartOffset() + 1;
|
||||
for (ASTNode child = firstEol.getTreeNext(); child != null; child = child.getTreeNext()) {
|
||||
if (child.getElementType() == getContentType()) {
|
||||
assert thisLineStart != -1;
|
||||
result.add(TextRange.create(thisLineStart, child.getTextRange().getEndOffset()).shiftRight(-myStart));
|
||||
thisLineStart = -1;
|
||||
}
|
||||
else if (child.getElementType() == YAMLTokenTypes.INDENT) {
|
||||
final IElementType childType = child.getElementType();
|
||||
final TextRange childRange = child.getTextRange();
|
||||
|
||||
if (childType == YAMLTokenTypes.INDENT && isEol(child.getTreePrev())) {
|
||||
thisLineStart = child.getStartOffset() + Math.min(indent, child.getTextLength());
|
||||
}
|
||||
if (child.getElementType() == YAMLTokenTypes.EOL) {
|
||||
else if (childType == YAMLTokenTypes.EOL) {
|
||||
if (thisLineStart != -1) {
|
||||
result.add(TextRange.create(thisLineStart, child.getStartOffset()).shiftRight(-myStart));
|
||||
}
|
||||
thisLineStart = child.getStartOffset() + 1;
|
||||
}
|
||||
else {
|
||||
if (isEol(child.getTreeNext())) {
|
||||
if (thisLineStart == -1) {
|
||||
Logger.getInstance(YAMLBlockScalarImpl.class).warn("thisLineStart == -1: '" + getText() + "'", new Throwable());
|
||||
continue;
|
||||
}
|
||||
result.add(TextRange.create(thisLineStart, childRange.getEndOffset()).shiftRight(-myStart));
|
||||
thisLineStart = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (thisLineStart != -1 && thisLineStart != getTextRange().getEndOffset()) {
|
||||
result.add(TextRange.create(thisLineStart, getTextRange().getEndOffset()).shiftRight(-myStart));
|
||||
result.add(TextRange.create(thisLineStart, getTextRange().getEndOffset()).shiftRight(-myStart));
|
||||
}
|
||||
|
||||
final int lastNonEmpty = ContainerUtil.lastIndexOf(result, range -> range.getLength() != 0);
|
||||
@@ -79,4 +89,8 @@ public abstract class YAMLBlockScalarImpl extends YAMLScalarImpl {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static boolean isEol(@Nullable ASTNode node) {
|
||||
return node != null && node.getElementType() == YAMLTokenTypes.EOL;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user