mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-181267 Invalid ranges during formatting in Language: FTL>
This commit is contained in:
@@ -15,13 +15,11 @@
|
||||
*/
|
||||
package com.intellij.formatting.templateLanguages;
|
||||
|
||||
import com.intellij.formatting.ASTBlock;
|
||||
import com.intellij.formatting.Block;
|
||||
import com.intellij.formatting.Indent;
|
||||
import com.intellij.formatting.Spacing;
|
||||
import com.intellij.formatting.*;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -148,8 +146,18 @@ class BlockUtil {
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreignBlocks.remove(fInd);
|
||||
foreignBlocks.addAll(fInd, buildChildWrappers(f.getOriginal()));
|
||||
Block original = f.getOriginal();
|
||||
List<DataLanguageBlockWrapper> children = buildChildWrappers(original);
|
||||
if (!children.isEmpty()) {
|
||||
foreignBlocks.remove(fInd);
|
||||
foreignBlocks.addAll(fInd, children);
|
||||
} else {
|
||||
result.addAll(splitLeafDataBlock(original, tlBlocks));
|
||||
fInd++;
|
||||
while (vInd < tlBlocks.size() && tlBlocks.get(vInd).getTextRange().getEndOffset() < original.getTextRange().getEndOffset()) {
|
||||
vInd++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,6 +170,86 @@ class BlockUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<Block> splitLeafDataBlock(Block block, List<TemplateLanguageBlock> allTlBlocks) {
|
||||
TextRange range = block.getTextRange();
|
||||
List<TemplateLanguageBlock> coveredTlBlocks = ContainerUtil.filter(allTlBlocks, b -> range.contains(b.getTextRange().getStartOffset()));
|
||||
|
||||
List<Block> result = new ArrayList<>();
|
||||
int dataStart = range.getStartOffset();
|
||||
for (TemplateLanguageBlock tlBlock : coveredTlBlocks) {
|
||||
int dataEnd = tlBlock.getTextRange().getStartOffset();
|
||||
if (dataStart < dataEnd) {
|
||||
result.add(createLeafFragmentBlock(dataStart, dataEnd));
|
||||
}
|
||||
dataStart = tlBlock.getTextRange().getEndOffset();
|
||||
if (dataStart < range.getEndOffset()) {
|
||||
result.add(tlBlock);
|
||||
}
|
||||
}
|
||||
|
||||
if (dataStart < range.getEndOffset()) {
|
||||
result.add(createLeafFragmentBlock(dataStart, range.getEndOffset()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Block createLeafFragmentBlock(int dataStart, int dataEnd) {
|
||||
return new Block() {
|
||||
@NotNull
|
||||
@Override
|
||||
public TextRange getTextRange() {
|
||||
return TextRange.create(dataStart, dataEnd);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<Block> getSubBlocks() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Wrap getWrap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Indent getIndent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Alignment getAlignment() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ChildAttributes getChildAttributes(int newChildIndex) {
|
||||
return ChildAttributes.DELEGATE_TO_NEXT_CHILD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncomplete() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaf() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<DataLanguageBlockWrapper> filterBlocksByRange(@NotNull List<DataLanguageBlockWrapper> list, @NotNull TextRange textRange) {
|
||||
int i = 0;
|
||||
|
||||
Reference in New Issue
Block a user