Initial support for scratch files
This commit is contained in:
@@ -16,6 +16,11 @@
|
||||
|
||||
<extensionPoint qualifiedName="org.jetbrains.kotlin.highlighterExtension"
|
||||
interface="org.jetbrains.kotlin.idea.highlighter.HighlighterExtension"/>
|
||||
|
||||
<extensionPoint name="scratchFileLanguageProvider" beanClass="com.intellij.lang.LanguageExtensionPoint">
|
||||
<with attribute="implementationClass" implements="org.jetbrains.kotlin.idea.scratch.ScratchFileLanguageProvider"/>
|
||||
</extensionPoint>
|
||||
|
||||
<extensionPoint qualifiedName="org.jetbrains.kotlin.binaryExtension"
|
||||
interface="org.jetbrains.kotlin.idea.util.KotlinBinaryExtension"/>
|
||||
<extensionPoint qualifiedName="org.jetbrains.kotlin.facetValidatorCreator"
|
||||
@@ -48,5 +53,7 @@
|
||||
<idePlatformSupport implementation="org.jetbrains.kotlin.caches.resolve.JvmPlatformSupport"/>
|
||||
<idePlatformSupport implementation="org.jetbrains.kotlin.caches.resolve.JsPlatformSupport"/>
|
||||
<idePlatformSupport implementation="org.jetbrains.kotlin.caches.resolve.CommonPlatformSupport"/>
|
||||
|
||||
<scratchFileLanguageProvider language="kotlin" implementationClass="org.jetbrains.kotlin.idea.scratch.KtScratchFileLanguageProvider"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
|
||||
@@ -52,6 +52,12 @@
|
||||
<interface-class>org.jetbrains.kotlin.idea.completion.CompletionBindingContextProvider</interface-class>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.completion.CompletionBindingContextProvider</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.scratch.ui.ScratchFileHook</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.scratch.ScratchFileModuleInfoProvider</implementation-class>
|
||||
</component>
|
||||
</project-components>
|
||||
|
||||
<application-components>
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
import kotlin.collections.ArraysKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind;
|
||||
@@ -361,9 +362,9 @@ public class CodeInsightUtils {
|
||||
|
||||
|
||||
@Nullable
|
||||
public static <T> T getTopmostElementAtOffset(@NotNull PsiElement element, int offset, @NotNull Class<T> klass) {
|
||||
public static <T> T getTopmostElementAtOffset(@NotNull PsiElement element, int offset, @NotNull Class<? extends T>... classes) {
|
||||
T lastElementOfType = null;
|
||||
if (klass.isInstance(element)) {
|
||||
if (anyIsInstance(element, classes)) {
|
||||
lastElementOfType = (T) element;
|
||||
}
|
||||
do {
|
||||
@@ -371,7 +372,7 @@ public class CodeInsightUtils {
|
||||
if (parent == null || (parent.getTextOffset() < offset) || parent instanceof KtBlockExpression) {
|
||||
break;
|
||||
}
|
||||
if (klass.isInstance(parent)) {
|
||||
if (anyIsInstance(parent, classes)) {
|
||||
lastElementOfType = (T) parent;
|
||||
}
|
||||
element = parent;
|
||||
@@ -380,4 +381,8 @@ public class CodeInsightUtils {
|
||||
|
||||
return lastElementOfType;
|
||||
}
|
||||
|
||||
private static <T> boolean anyIsInstance(PsiElement finalElement, @NotNull Class<? extends T>[] klass) {
|
||||
return ArraysKt.any(klass, aClass -> aClass.isInstance(finalElement));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,7 +321,10 @@ fun PsiFile.getLineStartOffset(line: Int): Int? {
|
||||
val startOffset = doc.getLineStartOffset(line)
|
||||
val element = findElementAt(startOffset) ?: return startOffset
|
||||
|
||||
return PsiTreeUtil.skipSiblingsForward(element, PsiWhiteSpace::class.java, PsiComment::class.java)?.startOffset ?: startOffset
|
||||
if (element is PsiWhiteSpace || element is PsiComment) {
|
||||
return PsiTreeUtil.skipSiblingsForward(element, PsiWhiteSpace::class.java, PsiComment::class.java)?.startOffset ?: startOffset
|
||||
}
|
||||
return startOffset
|
||||
}
|
||||
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user