diff --git a/plugins/yaml/backend/testData/org/jetbrains/yaml/folding/data/abbreviationLimit1.yaml b/plugins/yaml/backend/testData/org/jetbrains/yaml/folding/data/abbreviationLimit1.yaml
new file mode 100644
index 000000000000..c38ace21d31e
--- /dev/null
+++ b/plugins/yaml/backend/testData/org/jetbrains/yaml/folding/data/abbreviationLimit1.yaml
@@ -0,0 +1,21 @@
+---
+veryLongKeyName:
+ - one
+ - two
+
+key: |
+ very
+ very
+ very
+ long
+ value
+
+---
+- |
+ just
+ long
+ scalar
+ value
+ without
+ key
+...
diff --git a/plugins/yaml/backend/testData/org/jetbrains/yaml/folding/data/abbreviationLimit2.yaml b/plugins/yaml/backend/testData/org/jetbrains/yaml/folding/data/abbreviationLimit2.yaml
new file mode 100644
index 000000000000..42f97b29f688
--- /dev/null
+++ b/plugins/yaml/backend/testData/org/jetbrains/yaml/folding/data/abbreviationLimit2.yaml
@@ -0,0 +1,21 @@
+---
+veryLongKeyName:
+ - one
+ - two
+
+key: |
+ very
+ very
+ very
+ long
+ value
+
+---
+- |
+ just
+ long
+ scalar
+ value
+ without
+ key
+...
diff --git a/plugins/yaml/backend/testData/org/jetbrains/yaml/folding/data/abbreviationLimit8.yaml b/plugins/yaml/backend/testData/org/jetbrains/yaml/folding/data/abbreviationLimit8.yaml
new file mode 100644
index 000000000000..49ee869d0a53
--- /dev/null
+++ b/plugins/yaml/backend/testData/org/jetbrains/yaml/folding/data/abbreviationLimit8.yaml
@@ -0,0 +1,23 @@
+---
+veryLongKeyName:
+ - one
+ - two
+
+key: |
+ very
+ very
+ very
+ long
+ value
+
+---
+- |
+ just
+ long
+ scalar
+ value
+ without
+ key
+...
diff --git a/plugins/yaml/backend/testData/org/jetbrains/yaml/folding/data/noAbbreviation.yaml b/plugins/yaml/backend/testData/org/jetbrains/yaml/folding/data/noAbbreviation.yaml
new file mode 100644
index 000000000000..c011e88957ae
--- /dev/null
+++ b/plugins/yaml/backend/testData/org/jetbrains/yaml/folding/data/noAbbreviation.yaml
@@ -0,0 +1,31 @@
+---
+veryLongKeyName:
+ - one
+ - two
+
+key: |
+ very
+ very
+ very
+ long
+ value
+
+---
+- |
+ just
+ long
+ scalar
+ value
+ without
+ key
+...
diff --git a/plugins/yaml/backend/testSrc/folding/YAMLFoldingTest.java b/plugins/yaml/backend/testSrc/folding/YAMLFoldingTest.java
index 9d51453c0958..1cbe58b3f059 100644
--- a/plugins/yaml/backend/testSrc/folding/YAMLFoldingTest.java
+++ b/plugins/yaml/backend/testSrc/folding/YAMLFoldingTest.java
@@ -10,27 +10,57 @@ public class YAMLFoldingTest extends BasePlatformTestCase {
public static final String TEST_DATA_PATH = PathManagerEx.getCommunityHomePath() + RELATIVE_TEST_DATA_PATH;
public void testFolding() {
- defaultTest();
+ withFoldingSettings()
+ .execute(() -> defaultTest());
}
public void testSequenceFolding() {
- defaultTest();
+ withFoldingSettings()
+ .execute(() -> defaultTest());
}
public void testRuby18677() {
- defaultTest();
+ withFoldingSettings()
+ .execute(() -> defaultTest());
}
public void testRuby22423() {
- defaultTest();
+ withFoldingSettings()
+ .execute(() -> defaultTest());
}
-
+
public void testComments() {
- defaultTest();
+ withFoldingSettings()
+ .execute(() -> defaultTest());
}
public void testRegionFolding() {
- defaultTest();
+ withFoldingSettings()
+ .execute(() -> defaultTest());
+ }
+
+ public void testAbbreviationLimit1() {
+ withFoldingSettings()
+ .withAbbreviationLengthLimit(1)
+ .execute(() -> defaultTest());
+ }
+
+ public void testAbbreviationLimit2() {
+ withFoldingSettings()
+ .withAbbreviationLengthLimit(2)
+ .execute(() -> defaultTest());
+ }
+
+ public void testAbbreviationLimit8() {
+ withFoldingSettings()
+ .withAbbreviationLengthLimit(8)
+ .execute(() -> defaultTest());
+ }
+
+ public void testNoAbbreviation() {
+ withFoldingSettings()
+ .withUseAbbreviation(false)
+ .execute(() -> defaultTest());
}
public void defaultTest() {
@@ -41,4 +71,43 @@ public class YAMLFoldingTest extends BasePlatformTestCase {
protected String getTestDataPath() {
return TEST_DATA_PATH + "/folding/data/";
}
-}
\ No newline at end of file
+
+ protected static class YamlFoldingSettingsBuilder {
+ private boolean useAbbreviation = true;
+ private int abbreviationLengthLimit = 20;
+
+ public YamlFoldingSettingsBuilder withUseAbbreviation(boolean value) {
+ this.useAbbreviation = value;
+ return this;
+ }
+
+ public YamlFoldingSettingsBuilder withAbbreviationLengthLimit(int value) {
+ this.abbreviationLengthLimit = value;
+ return this;
+ }
+
+ public void execute(ThrowableRunnable extends RuntimeException> runnable) {
+ YAMLFoldingSettings settings = YAMLFoldingSettings.getInstance();
+ boolean originalUseAbbreviation = settings.useAbbreviation;
+ int originalAbbreviationLengthLimit = settings.abbreviationLengthLimit;
+ try {
+ settings.useAbbreviation = useAbbreviation;
+ settings.abbreviationLengthLimit = abbreviationLengthLimit;
+ runnable.run();
+ }
+ finally {
+ settings.useAbbreviation = originalUseAbbreviation;
+ settings.abbreviationLengthLimit = originalAbbreviationLengthLimit;
+ }
+ }
+ }
+
+ protected YamlFoldingSettingsBuilder withFoldingSettings() {
+ return new YamlFoldingSettingsBuilder();
+ }
+
+ @FunctionalInterface
+ public interface ThrowableRunnable {
+ void run() throws E;
+ }
+}
diff --git a/plugins/yaml/resources/intellij.yaml.xml b/plugins/yaml/resources/intellij.yaml.xml
index 4e11a09add27..3c242cdc2694 100644
--- a/plugins/yaml/resources/intellij.yaml.xml
+++ b/plugins/yaml/resources/intellij.yaml.xml
@@ -32,6 +32,8 @@
+
+
-
\ No newline at end of file
+
diff --git a/plugins/yaml/resources/messages/YAMLBundle.properties b/plugins/yaml/resources/messages/YAMLBundle.properties
index 65760eb8d3f6..6aa95d2e45cf 100644
--- a/plugins/yaml/resources/messages/YAMLBundle.properties
+++ b/plugins/yaml/resources/messages/YAMLBundle.properties
@@ -120,4 +120,8 @@ yaml.intention.name.inline.collection=Inline collection
yaml.intention.name.expand.collection=Expand collection
yaml.intention.name.expand.all.collections.inside=Expand all collections inside
yaml.progress.title.inlining.collection=Inlining collection\u2026
-yaml.progress.title.expanding.yaml.collection=Expanding the yaml collection\u2026
\ No newline at end of file
+yaml.progress.title.expanding.yaml.collection=Expanding the yaml collection\u2026
+
+YAMLFoldingSettings.title=YAML
+YAMLFoldingSettings.use.abbreviation=Use abbreviation for folded names and values with limit of
+YAMLFoldingSettings.abbreviation.units.of.measurement={0,choice,1#character|2#characters}
\ No newline at end of file
diff --git a/plugins/yaml/src/folding/YAMLFoldingBuilder.java b/plugins/yaml/src/folding/YAMLFoldingBuilder.java
index 8d9d90449d64..bcde1a15c5fe 100644
--- a/plugins/yaml/src/folding/YAMLFoldingBuilder.java
+++ b/plugins/yaml/src/folding/YAMLFoldingBuilder.java
@@ -18,15 +18,13 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.yaml.YAMLElementTypes;
import org.jetbrains.yaml.psi.*;
import org.jetbrains.yaml.psi.impl.YAMLArrayImpl;
-import org.jetbrains.yaml.psi.impl.YAMLBlockMappingImpl;
import org.jetbrains.yaml.psi.impl.YAMLBlockSequenceImpl;
-import org.jetbrains.yaml.psi.impl.YAMLHashImpl;
import java.util.List;
public class YAMLFoldingBuilder extends CustomFoldingBuilder {
- private static final int PLACEHOLDER_LEN = 20;
+ private static final int LIMIT_FOR_ELLIPSIS_IN_THE_END = 2;
@Override
protected void buildLanguageFoldRegions(@NotNull List descriptors,
@@ -148,14 +146,18 @@ public class YAMLFoldingBuilder extends CustomFoldingBuilder {
return false;
}
- private static String normalizePlaceHolderText(@Nullable String text) {
+ protected static String normalizePlaceHolderText(@Nullable String text) {
if (text == null) {
return null;
}
- if (text.length() <= PLACEHOLDER_LEN) {
+ var settings = YAMLFoldingSettings.getInstance();
+ if (!settings.useAbbreviation || text.length() <= settings.abbreviationLengthLimit) {
return text;
}
- return StringUtil.trimMiddle(text, PLACEHOLDER_LEN);
+ if (settings.abbreviationLengthLimit <= LIMIT_FOR_ELLIPSIS_IN_THE_END) {
+ return text.substring(0, settings.abbreviationLengthLimit) + "…";
+ }
+ return StringUtil.trimMiddle(text, settings.abbreviationLengthLimit);
}
}
diff --git a/plugins/yaml/src/folding/YAMLFoldingSettings.kt b/plugins/yaml/src/folding/YAMLFoldingSettings.kt
new file mode 100644
index 000000000000..882e77549359
--- /dev/null
+++ b/plugins/yaml/src/folding/YAMLFoldingSettings.kt
@@ -0,0 +1,62 @@
+// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
+package org.jetbrains.yaml.folding
+
+import com.intellij.application.options.editor.CodeFoldingOptionsProvider
+import com.intellij.openapi.application.ApplicationManager
+import com.intellij.openapi.components.PersistentStateComponent
+import com.intellij.openapi.components.SettingsCategory
+import com.intellij.openapi.components.State
+import com.intellij.openapi.components.Storage
+import com.intellij.openapi.options.BeanConfigurable
+import com.intellij.ui.dsl.builder.Panel
+import com.intellij.ui.dsl.builder.bindIntText
+import com.intellij.ui.dsl.builder.bindSelected
+import com.intellij.ui.dsl.builder.selected
+import com.intellij.util.xmlb.XmlSerializerUtil
+import org.jetbrains.yaml.YAMLBundle
+
+@State(name = "YAMLFoldingSettings", storages = [Storage("editor.xml")], category = SettingsCategory.CODE)
+class YAMLFoldingSettings : PersistentStateComponent {
+ @JvmField
+ var useAbbreviation: Boolean = true
+
+ @JvmField
+ var abbreviationLengthLimit: Int = 20
+
+
+ override fun getState(): YAMLFoldingSettings? {
+ return this
+ }
+
+ override fun loadState(state: YAMLFoldingSettings) {
+ XmlSerializerUtil.copyBean(state, this)
+ }
+
+ companion object {
+ @JvmStatic
+ fun getInstance(): YAMLFoldingSettings = requireNotNull(ApplicationManager.getApplication().getService(YAMLFoldingSettings::class.java)) {
+ "JsonFoldingSettings service is not available"
+ }
+ }
+}
+
+internal class YAMLFoldingOptionsProvider :
+ BeanConfigurable(YAMLFoldingSettings.getInstance(), YAMLBundle.message("YAMLFoldingSettings.title")),
+ CodeFoldingOptionsProvider {
+
+ override fun Panel.createContent() {
+ group(YAMLBundle.message("YAMLFoldingSettings.title")) {
+ row {
+ val s = checkBox(YAMLBundle.message("YAMLFoldingSettings.use.abbreviation"))
+ .bindSelected(instance::useAbbreviation)
+
+ intTextField(1..Int.MAX_VALUE)
+ .bindIntText(instance::abbreviationLengthLimit)
+ .enabledIf(s.selected)
+
+ label(YAMLBundle.message("YAMLFoldingSettings.abbreviation.units.of.measurement", instance.abbreviationLengthLimit))
+
+ }
+ }
+ }
+}