mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 11:53:49 +07:00
[kotlin] prohibit kotlin scratches creation
^KTIJ-32088 Fixed (cherry picked from commit eafbbe789be89b4787ab284e11c5011064dd3fae) KT-MR-18854 GitOrigin-RevId: a04d8c5f0bb3b4d9e4b2317e2ecb804cad355eba
This commit is contained in:
committed by
intellij-monorepo-bot
parent
30236d0cf3
commit
087bbdc0bd
@@ -11364,6 +11364,7 @@ a:com.intellij.ide.scratch.LRUPopupBuilder
|
|||||||
- withExtraMiddleValue(java.lang.Object,java.lang.String,javax.swing.Icon):com.intellij.ide.scratch.LRUPopupBuilder
|
- withExtraMiddleValue(java.lang.Object,java.lang.String,javax.swing.Icon):com.intellij.ide.scratch.LRUPopupBuilder
|
||||||
- withExtraSpeedSearchNamer(java.util.function.Function):com.intellij.ide.scratch.LRUPopupBuilder
|
- withExtraSpeedSearchNamer(java.util.function.Function):com.intellij.ide.scratch.LRUPopupBuilder
|
||||||
- withExtraTopValue(java.lang.Object,java.lang.String,javax.swing.Icon):com.intellij.ide.scratch.LRUPopupBuilder
|
- withExtraTopValue(java.lang.Object,java.lang.String,javax.swing.Icon):com.intellij.ide.scratch.LRUPopupBuilder
|
||||||
|
- withFilter(java.util.function.Predicate):com.intellij.ide.scratch.LRUPopupBuilder
|
||||||
- withSelection(java.lang.Object):com.intellij.ide.scratch.LRUPopupBuilder
|
- withSelection(java.lang.Object):com.intellij.ide.scratch.LRUPopupBuilder
|
||||||
f:com.intellij.ide.scratch.ScratchFileActions
|
f:com.intellij.ide.scratch.ScratchFileActions
|
||||||
- <init>():V
|
- <init>():V
|
||||||
@@ -11383,6 +11384,7 @@ a:com.intellij.ide.scratch.ScratchFileCreationHelper
|
|||||||
- sf:EXTENSION:com.intellij.lang.LanguageExtension
|
- sf:EXTENSION:com.intellij.lang.LanguageExtension
|
||||||
- <init>():V
|
- <init>():V
|
||||||
- beforeCreate(com.intellij.openapi.project.Project,com.intellij.ide.scratch.ScratchFileCreationHelper$Context):V
|
- beforeCreate(com.intellij.openapi.project.Project,com.intellij.ide.scratch.ScratchFileCreationHelper$Context):V
|
||||||
|
- newScratchAllowed():Z
|
||||||
- s:parseHeader(com.intellij.openapi.project.Project,com.intellij.lang.Language,java.lang.String):com.intellij.psi.PsiFile
|
- s:parseHeader(com.intellij.openapi.project.Project,com.intellij.lang.Language,java.lang.String):com.intellij.psi.PsiFile
|
||||||
- prepareText(com.intellij.openapi.project.Project,com.intellij.ide.scratch.ScratchFileCreationHelper$Context,com.intellij.openapi.actionSystem.DataContext):Z
|
- prepareText(com.intellij.openapi.project.Project,com.intellij.ide.scratch.ScratchFileCreationHelper$Context,com.intellij.openapi.actionSystem.DataContext):Z
|
||||||
- s:reformat(com.intellij.openapi.project.Project,com.intellij.lang.Language,java.lang.String):java.lang.String
|
- s:reformat(com.intellij.openapi.project.Project,com.intellij.lang.Language,java.lang.String):java.lang.String
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.awt.*;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author gregsh
|
* @author gregsh
|
||||||
@@ -41,6 +42,7 @@ public abstract class LRUPopupBuilder<T> {
|
|||||||
private T mySelection;
|
private T mySelection;
|
||||||
private Consumer<? super T> myOnChosen;
|
private Consumer<? super T> myOnChosen;
|
||||||
private Comparator<? super T> myComparator;
|
private Comparator<? super T> myComparator;
|
||||||
|
private Predicate<? super T> myFilter = it -> true;
|
||||||
private Iterable<? extends T> myValues;
|
private Iterable<? extends T> myValues;
|
||||||
private JBIterable<T> myTopValues = JBIterable.empty();
|
private JBIterable<T> myTopValues = JBIterable.empty();
|
||||||
private JBIterable<T> myMiddleValues = JBIterable.empty();
|
private JBIterable<T> myMiddleValues = JBIterable.empty();
|
||||||
@@ -129,6 +131,11 @@ public abstract class LRUPopupBuilder<T> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull LRUPopupBuilder<T> withFilter(@Nullable Predicate<? super T> filter) {
|
||||||
|
myFilter = filter;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public @NotNull LRUPopupBuilder<T> withExtraSpeedSearchNamer(@Nullable Function<? super T, String> function) {
|
public @NotNull LRUPopupBuilder<T> withExtraSpeedSearchNamer(@Nullable Function<? super T, String> function) {
|
||||||
myExtraSpeedSearchNamer = function;
|
myExtraSpeedSearchNamer = function;
|
||||||
return this;
|
return this;
|
||||||
@@ -153,7 +160,7 @@ public abstract class LRUPopupBuilder<T> {
|
|||||||
if (!lru.isEmpty()) {
|
if (!lru.isEmpty()) {
|
||||||
lru.sort(Comparator.comparingInt(o -> ids.indexOf(getStorageId(o))));
|
lru.sort(Comparator.comparingInt(o -> ids.indexOf(getStorageId(o))));
|
||||||
}
|
}
|
||||||
List<T> combinedItems = ContainerUtil.concat(topItems, lru, middleItems, items, bottomItems);
|
List<T> combinedItems = ContainerUtil.concat(topItems, lru, middleItems, items, bottomItems).stream().filter(myFilter).toList();
|
||||||
T sep1 = ContainerUtil.getOrElse(combinedItems, topItems.size() + lru.size() + middleItems.size(), null);
|
T sep1 = ContainerUtil.getOrElse(combinedItems, topItems.size() + lru.size() + middleItems.size(), null);
|
||||||
T sep2 = ContainerUtil.getOrElse(combinedItems, topItems.size() + lru.size() + middleItems.size() + items.size(), null);
|
T sep2 = ContainerUtil.getOrElse(combinedItems, topItems.size() + lru.size() + middleItems.size() + items.size(), null);
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,13 @@ public abstract class ScratchFileCreationHelper {
|
|||||||
public boolean prepareText(@NotNull Project project, @NotNull Context context, @NotNull DataContext dataContext) {
|
public boolean prepareText(@NotNull Project project, @NotNull Context context, @NotNull DataContext dataContext) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return false if it's prohibited to create new scratch file for particular {@link Context#language}
|
||||||
|
*/
|
||||||
|
public boolean newScratchAllowed() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public void beforeCreate(@NotNull Project project, @NotNull Context context) {
|
public void beforeCreate(@NotNull Project project, @NotNull Context context) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -256,6 +256,7 @@ final class ScratchImplUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.forValues(items)
|
.forValues(items)
|
||||||
|
.withFilter(it -> it.language == null || ScratchFileCreationHelper.EXTENSION.forLanguage(it.language).newScratchAllowed())
|
||||||
.withComparator(comparator)
|
.withComparator(comparator)
|
||||||
.withExtraSpeedSearchNamer(o -> o.fileExtension)
|
.withExtraSpeedSearchNamer(o -> o.fileExtension)
|
||||||
.withSelection(null);
|
.withSelection(null);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package org.jetbrains.kotlin.idea.scratch
|
|||||||
import com.intellij.ide.scratch.ScratchFileCreationHelper
|
import com.intellij.ide.scratch.ScratchFileCreationHelper
|
||||||
import com.intellij.openapi.actionSystem.DataContext
|
import com.intellij.openapi.actionSystem.DataContext
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginModeProvider
|
||||||
import org.jetbrains.kotlin.idea.statistics.KotlinCreateFileFUSCollector
|
import org.jetbrains.kotlin.idea.statistics.KotlinCreateFileFUSCollector
|
||||||
import org.jetbrains.kotlin.parsing.KotlinParserDefinition
|
import org.jetbrains.kotlin.parsing.KotlinParserDefinition
|
||||||
|
|
||||||
@@ -16,4 +17,11 @@ class KtScratchFileCreationHelper : ScratchFileCreationHelper() {
|
|||||||
|
|
||||||
return super.prepareText(project, context, dataContext)
|
return super.prepareText(project, context, dataContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun newScratchAllowed(): Boolean =
|
||||||
|
if (KotlinPluginModeProvider.isK2Mode()) {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
super.newScratchAllowed()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -61,6 +61,8 @@
|
|||||||
<projectService serviceInterface="org.jetbrains.kotlin.analysis.api.platform.projectStructure.KotlinCompilerPluginsProvider"
|
<projectService serviceInterface="org.jetbrains.kotlin.analysis.api.platform.projectStructure.KotlinCompilerPluginsProvider"
|
||||||
serviceImplementation="org.jetbrains.kotlin.idea.fir.extensions.KtCompilerPluginsProviderIdeImpl"/>
|
serviceImplementation="org.jetbrains.kotlin.idea.fir.extensions.KtCompilerPluginsProviderIdeImpl"/>
|
||||||
<compilableFileTypesProvider implementation="org.jetbrains.kotlin.idea.compiler.KotlinCompilableFileTypesProvider" />
|
<compilableFileTypesProvider implementation="org.jetbrains.kotlin.idea.compiler.KotlinCompilableFileTypesProvider" />
|
||||||
|
<scratch.creationHelper language="kotlin"
|
||||||
|
implementationClass="org.jetbrains.kotlin.idea.scratch.KtScratchFileCreationHelper"/>
|
||||||
<!-- fir-specific -->
|
<!-- fir-specific -->
|
||||||
<applicationService serviceInterface="org.jetbrains.kotlin.idea.base.plugin.KotlinPluginModeProvider"
|
<applicationService serviceInterface="org.jetbrains.kotlin.idea.base.plugin.KotlinPluginModeProvider"
|
||||||
serviceImplementation="org.jetbrains.kotlin.idea.fir.plugin.K2KotlinPluginModeProvider"/>
|
serviceImplementation="org.jetbrains.kotlin.idea.fir.plugin.K2KotlinPluginModeProvider"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user