Added KotlinCodeInsightWorkspaceSettings in place of sharing kotlin settings with java CodeInsightSettings

This commit is contained in:
Vladimir Dolzhenko
2019-09-23 16:05:11 +02:00
parent 6b5a73ffa9
commit 027c60080b
6 changed files with 149 additions and 4 deletions
@@ -22,7 +22,8 @@ enum class FUSEventGroups(groupIdSuffix: String, val events: Set<String> = setOf
NPWizards("ide.npwizards", NPWizardsEvents),
Debug("ide.debugger"),
J2K("ide.j2k"),
Editor("ide.editor");
Editor("ide.editor"),
Settings("ide.settings");
val GROUP_ID: String = "kotlin.$groupIdSuffix"
}
@@ -778,6 +778,7 @@
<applicationService serviceInterface="org.jetbrains.kotlin.idea.editor.KotlinEditorOptions"
serviceImplementation="org.jetbrains.kotlin.idea.editor.KotlinEditorOptions"/>
<editorSmartKeysConfigurable instance="org.jetbrains.kotlin.idea.editor.KotlinEditorOptionsConfigurable"/>
<applicationService serviceInterface="org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringSettings"
@@ -3447,7 +3448,10 @@
language="kotlin"
/>
<applicationService serviceInterface="org.jetbrains.kotlin.idea.codeInsight.KotlinCodeInsightWorkspaceSettings"
serviceImplementation="org.jetbrains.kotlin.idea.codeInsight.KotlinCodeInsightWorkspaceSettings"/>
<referenceImporter implementation="org.jetbrains.kotlin.idea.quickfix.KotlinReferenceImporter"/>
<autoImportOptionsProvider instance="org.jetbrains.kotlin.idea.codeInsight.KotlinCodeInsightWorkspaceSettingsProvider"/>
<fileType.fileViewProviderFactory filetype="KJSM" implementationClass="com.intellij.psi.ClassFileViewProviderFactory"/>
<filetype.stubBuilder filetype="KJSM" implementationClass="com.intellij.psi.impl.compiled.ClassFileStubBuilder"/>
@@ -0,0 +1,33 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.codeInsight
import com.intellij.openapi.components.*
import com.intellij.openapi.project.Project
import com.intellij.util.xmlb.XmlSerializerUtil
@State(name = "KotlinCodeInsightWorkspaceSettings", storages = [Storage("kotlinCodeInsightSettings.xml")])
class KotlinCodeInsightWorkspaceSettings : PersistentStateComponent<KotlinCodeInsightWorkspaceSettings> {
@JvmField
var addUnambiguousImportsOnTheFly = false
@JvmField
var optimizeImportsOnTheFly = false
override fun getState() = this
override fun loadState(state: KotlinCodeInsightWorkspaceSettings) = XmlSerializerUtil.copyBean(state, this)
companion object {
fun getInstance(project: Project): KotlinCodeInsightWorkspaceSettings {
return ServiceManager.getService(project, KotlinCodeInsightWorkspaceSettings::class.java)
}
}
}
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<form bind-to-class="org.jetbrains.kotlin.idea.codeInsight.KotlinCodeInsightWorkspaceSettingsProvider" version="1" xmlns="http://www.intellij.com/uidesigner/form/">
<grid column-count="1" hgap="-1" id="ccd61" layout-manager="GridLayoutManager" row-count="1" same-size-horizontally="false" same-size-vertically="false" vgap="-1">
<margin bottom="0" left="0" right="0" top="0"/>
<constraints/>
<properties/>
<border type="none"/>
<children>
<grid binding="myPanel" column-count="1" hgap="-1" id="ccd62" layout-manager="GridLayoutManager" row-count="2" same-size-horizontally="false" same-size-vertically="false" vgap="-1">
<margin bottom="0" left="0" right="0" top="0"/>
<constraints>
<grid anchor="9" col-span="1" column="0" fill="0" hsize-policy="0" indent="0" row="0" row-span="1" use-parent-layout="false" vsize-policy="3"/>
</constraints>
<properties/>
<clientProperties>
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
</clientProperties>
<border title="Kotlin" type="etched"/>
<children>
<component binding="myAddUnambiguousImportsOnTheFly" class="javax.swing.JCheckBox" default-binding="true" id="ccd64">
<constraints>
<grid anchor="8" col-span="1" column="0" fill="0" hsize-policy="3" indent="0" row="0" row-span="1" use-parent-layout="false" vsize-policy="0"/>
</constraints>
<properties>
<text key="checkbox.add.unambiguous.imports.on.the.fly" resource-bundle="messages/ApplicationBundle"/>
</properties>
</component>
<component binding="myOptimizeImportsOnTheFly" class="javax.swing.JCheckBox" default-binding="true" id="ccd63">
<constraints>
<grid anchor="8" col-span="1" column="0" fill="0" hsize-policy="3" indent="0" row="1" row-span="1" use-parent-layout="false" vsize-policy="0"/>
</constraints>
<properties>
<text key="checkbox.optimize.imports.on.the.fly" resource-bundle="messages/ApplicationBundle"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>
@@ -0,0 +1,67 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.codeInsight;
import com.intellij.application.options.editor.AutoImportOptionsProvider;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.idea.statistics.FUSEventGroups;
import org.jetbrains.kotlin.idea.statistics.KotlinFUSLogger;
import javax.swing.*;
import java.util.HashMap;
import java.util.Map;
public class KotlinCodeInsightWorkspaceSettingsProvider implements AutoImportOptionsProvider {
private final Project project;
private JPanel myPanel;
private JCheckBox myOptimizeImportsOnTheFly;
private JCheckBox myAddUnambiguousImportsOnTheFly;
public KotlinCodeInsightWorkspaceSettingsProvider(Project project) {
this.project = project;
}
@Nullable
@Override
public JComponent createComponent() {
return myPanel;
}
private KotlinCodeInsightWorkspaceSettings settings() {
return KotlinCodeInsightWorkspaceSettings.Companion.getInstance(project);
}
@Override
public boolean isModified() {
KotlinCodeInsightWorkspaceSettings settings = settings();
return settings.optimizeImportsOnTheFly != myOptimizeImportsOnTheFly.isSelected()
|| settings.addUnambiguousImportsOnTheFly != myAddUnambiguousImportsOnTheFly.isSelected();
}
@Override
public void apply() throws ConfigurationException {
KotlinCodeInsightWorkspaceSettings settings = settings();
settings.optimizeImportsOnTheFly = myOptimizeImportsOnTheFly.isSelected();
settings.addUnambiguousImportsOnTheFly = myAddUnambiguousImportsOnTheFly.isSelected();
final Map<String, String> data = new HashMap<>();
data.put("optimizeImportsOnTheFly", Boolean.toString(settings.optimizeImportsOnTheFly));
data.put("addUnambiguousImportsOnTheFly", Boolean.toString(settings.addUnambiguousImportsOnTheFly));
KotlinFUSLogger.Companion.log(FUSEventGroups.Settings, "KotlinCodeInsightWorkspaceSettings", data);
}
@Override
public void reset() {
KotlinCodeInsightWorkspaceSettings settings = settings();
myOptimizeImportsOnTheFly.setSelected(settings.optimizeImportsOnTheFly);
myAddUnambiguousImportsOnTheFly.setSelected(settings.addUnambiguousImportsOnTheFly);
}
}
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.idea.quickfix
import com.intellij.codeInsight.CodeInsightSettings
import com.intellij.codeInsight.daemon.ReferenceImporter
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerEx
import com.intellij.codeInsight.daemon.impl.DaemonListeners
@@ -28,6 +27,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.idea.actions.createSingleImportAction
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
import org.jetbrains.kotlin.idea.codeInsight.KotlinCodeInsightWorkspaceSettings
import org.jetbrains.kotlin.idea.core.targetDescriptors
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.psi.KtExpression
@@ -47,7 +47,7 @@ class KotlinReferenceImporter : ReferenceImporter {
val nameExpression = file.findElementAt(offset)?.parent as? KtSimpleNameExpression ?: return false
if (!CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY) return false
if (!KotlinCodeInsightWorkspaceSettings.getInstance(file.project).addUnambiguousImportsOnTheFly) return false
val importFix: ImportFixBase<out KtExpression>? = findImportFixAt(editor, file, offset)
if (importFix != null && !importFix.isOutdated()) {
@@ -107,7 +107,7 @@ class KotlinReferenceImporter : ReferenceImporter {
}
private fun KtSimpleNameExpression.autoImport(editor: Editor, file: KtFile): Boolean {
if (!CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY) return false
if (!KotlinCodeInsightWorkspaceSettings.getInstance(project).addUnambiguousImportsOnTheFly) return false
if (!DaemonListeners.canChangeFileSilently(file)) return false
if (hasUnresolvedImportWhichCanImport(file, getReferencedName())) return false