mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[yaml + k8s] IJPL-64482: Add setting for yaml files to set abbreviation limit or disable reducing
GitOrigin-RevId: 6dd9da9bd34f2187c154153fcad5c554cf50a5af
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bc98836a0c
commit
e6b7e1bb7d
@@ -0,0 +1,21 @@
|
||||
<fold text='---'>---
|
||||
<fold text='v…: <2 items>'>veryLongKeyName:
|
||||
- one
|
||||
- two</fold>
|
||||
|
||||
key: <fold text='v…'>|
|
||||
very
|
||||
very
|
||||
very
|
||||
long
|
||||
value
|
||||
</fold></fold>
|
||||
<fold text='---'>---
|
||||
- <fold text='j…'>|
|
||||
just
|
||||
long
|
||||
scalar
|
||||
value
|
||||
without
|
||||
key</fold>
|
||||
...</fold>
|
||||
@@ -0,0 +1,21 @@
|
||||
<fold text='---'>---
|
||||
<fold text='ve…: <2 items>'>veryLongKeyName:
|
||||
- one
|
||||
- two</fold>
|
||||
|
||||
key: <fold text='ve…'>|
|
||||
very
|
||||
very
|
||||
very
|
||||
long
|
||||
value
|
||||
</fold></fold>
|
||||
<fold text='---'>---
|
||||
- <fold text='ju…'>|
|
||||
just
|
||||
long
|
||||
scalar
|
||||
value
|
||||
without
|
||||
key</fold>
|
||||
...</fold>
|
||||
@@ -0,0 +1,23 @@
|
||||
<fold text='---'>---
|
||||
<fold text='ver…Name: <2 items>'>veryLongKeyName:
|
||||
- one
|
||||
- two</fold>
|
||||
|
||||
key: <fold text='ver…lue
|
||||
'>|
|
||||
very
|
||||
very
|
||||
very
|
||||
long
|
||||
value
|
||||
</fold></fold>
|
||||
<fold text='---'>---
|
||||
- <fold text='jus…
|
||||
key'>|
|
||||
just
|
||||
long
|
||||
scalar
|
||||
value
|
||||
without
|
||||
key</fold>
|
||||
...</fold>
|
||||
@@ -0,0 +1,31 @@
|
||||
<fold text='---'>---
|
||||
<fold text='veryLongKeyName: <2 items>'>veryLongKeyName:
|
||||
- one
|
||||
- two</fold>
|
||||
|
||||
key: <fold text='very
|
||||
very
|
||||
very
|
||||
long
|
||||
value
|
||||
'>|
|
||||
very
|
||||
very
|
||||
very
|
||||
long
|
||||
value
|
||||
</fold></fold>
|
||||
<fold text='---'>---
|
||||
- <fold text='just
|
||||
long
|
||||
scalar
|
||||
value
|
||||
without
|
||||
key'>|
|
||||
just
|
||||
long
|
||||
scalar
|
||||
value
|
||||
without
|
||||
key</fold>
|
||||
...</fold>
|
||||
@@ -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/";
|
||||
}
|
||||
}
|
||||
|
||||
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<E extends Exception> {
|
||||
void run() throws E;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
<renameInputValidator implementation="org.jetbrains.yaml.refactoring.rename.YamlKeyValueRenameInputValidator" order="first"/>
|
||||
<applicationService serviceImplementation="org.jetbrains.yaml.smart.YAMLEditorOptions"/>
|
||||
<applicationSettings service="org.jetbrains.yaml.smart.YAMLEditorOptions"/>
|
||||
<applicationService serviceImplementation="org.jetbrains.yaml.folding.YAMLFoldingSettings"/>
|
||||
<codeFoldingOptionsProvider instance="org.jetbrains.yaml.folding.YAMLFoldingOptionsProvider"/>
|
||||
<rdct.remoteSettingProvider implementation="org.jetbrains.yaml.smart.YAMLRemoteSettingInfoProvider"/>
|
||||
<editorSmartKeysConfigurable instance="org.jetbrains.yaml.smart.YAMLSmartOptionsProvider"
|
||||
id="editor.preferences.yamlOptions"
|
||||
@@ -39,4 +41,4 @@
|
||||
key="yaml.smartkeys.option.title"/>
|
||||
<copyPastePreProcessor implementation="org.jetbrains.yaml.smart.YAMLCopyPasteProcessor"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
</idea-plugin>
|
||||
|
||||
@@ -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
|
||||
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}
|
||||
@@ -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<FoldingDescriptor> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<YAMLFoldingSettings?> {
|
||||
@JvmField
|
||||
var useAbbreviation: Boolean = true
|
||||
|
||||
@JvmField
|
||||
var abbreviationLengthLimit: Int = 20
|
||||
|
||||
|
||||
override fun getState(): YAMLFoldingSettings? {
|
||||
return this
|
||||
}
|
||||
|
||||
override fun loadState(state: YAMLFoldingSettings) {
|
||||
XmlSerializerUtil.copyBean<YAMLFoldingSettings>(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>(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))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user