Set scratch file extension using API for IDEA 182 or higher

This commit is contained in:
Natalia Selezneva
2018-12-24 13:28:42 +03:00
parent 6eff314b9d
commit 404c3ea57b
4 changed files with 24 additions and 1 deletions
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.scratch
import com.intellij.ide.scratch.ScratchFileCreationHelper
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.parsing.KotlinParserDefinition
class KtScratchFileCreationHelper: ScratchFileCreationHelper() {
override fun prepareText(project: Project, context: Context, dataContext: DataContext): Boolean {
context.fileExtension = KotlinParserDefinition.STD_SCRIPT_SUFFIX
return super.prepareText(project, context, dataContext)
}
}
@@ -48,7 +48,7 @@ class ScratchFileModuleInfoProvider(val project: Project) : ProjectComponent {
val ktFile = PsiManager.getInstance(project).findFile(file) as? KtFile ?: return
// Hack before api in IDEA will be introduced
// BUNCH: 181 scratch files are created with .kt extension
if (file.extension == KotlinFileType.EXTENSION) {
runWriteAction {
var newName = file.nameWithoutExtension + STD_SCRIPT_EXT
+3
View File
@@ -122,6 +122,9 @@
<editorNotificationProvider implementation="org.jetbrains.kotlin.idea.versions.UnsupportedAbiVersionNotificationPanelProvider"/>
<scratch.creationHelper language="kotlin"
implementationClass="org.jetbrains.kotlin.idea.scratch.KtScratchFileCreationHelper"/>
<localInspection
groupName="Plugin DevKit"
shortName="IncompatibleAPI"