[docker] IDEA-268617: Compose: port indentation is off for code completion

GitOrigin-RevId: 7d07e2ba708ccc47a69d97eb9add6cc6f145c943
This commit is contained in:
Andrii Zinchenko
2021-05-19 16:29:56 +02:00
committed by intellij-monorepo-bot
parent d6d1ba354e
commit 0790ff26fc
3 changed files with 31 additions and 12 deletions

View File

@@ -125,8 +125,14 @@ public abstract class YamlComposedTypeBase extends YamlMetaType {
}
else {
markup.append(":");
markup.increaseTabs(1);
markup.newLineAndTabs(relation == Field.Relation.SEQUENCE_ITEM);
if (relation == Field.Relation.SEQUENCE_ITEM) {
markup.doTabbedBlockForSequenceItem();
}
else {
markup.increaseTabs(1);
markup.newLineAndTabs();
}
}
markup.appendCaret();
}

View File

@@ -13,6 +13,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.*;
import org.jetbrains.yaml.YAMLBundle;
import org.jetbrains.yaml.formatter.YAMLCodeStyleSettings;
import org.jetbrains.yaml.psi.*;
import javax.swing.*;
@@ -210,13 +211,15 @@ public abstract class YamlMetaType {
private final String myTabSymbol;
private int myLevel;
private boolean myCaretAppended;
private final YAMLCodeStyleSettings mySettings;
public YamlInsertionMarkup(@NotNull InsertionContext context) {
this(getTabSymbol(context));
this(getTabSymbol(context), CodeStyle.getCustomSettings(context.getFile(), YAMLCodeStyleSettings.class));
}
public YamlInsertionMarkup(@NotNull String tabSymbol) {
public YamlInsertionMarkup(@NotNull String tabSymbol, YAMLCodeStyleSettings settings) {
myTabSymbol = tabSymbol;
mySettings = settings;
}
public void append(@NotNull String text) {
@@ -245,11 +248,26 @@ public abstract class YamlMetaType {
@NotNull
private String sequenceItemPrefix() {
String result = SEQUENCE_ITEM_MARKUP;
if(myTabSymbol.length() > result.length())
if (myTabSymbol.length() > result.length()) {
result += myTabSymbol.substring(result.length());
}
return result;
}
public void doTabbedBlockForSequenceItem(Runnable doWhenTabbed) {
var indent = mySettings.INDENT_SEQUENCE_VALUE ? 2 : 1;
doTabbedBlock(indent, () -> {
newLineAndTabs(true);
doWhenTabbed.run();
});
}
public void doTabbedBlockForSequenceItem() {
doTabbedBlockForSequenceItem(() -> {
});
}
public void appendCaret() {
if (!myCaretAppended) {
append(CARET_MARKUP);

View File

@@ -80,16 +80,11 @@ public abstract class YamlScalarType extends YamlMetaType {
}
case SEQUENCE_ITEM: {
markup.append(":");
markup.increaseTabs(2);
try {
markup.newLineAndTabs(true);
markup.doTabbedBlockForSequenceItem(() -> {
if (iteration.isEndOfPathReached()) {
markup.appendCaret();
}
}
finally {
markup.decreaseTabs(2);
}
});
break;
}
default: