Intellij插件: 无法初始化组件状态异常

huangapple go评论167阅读模式
英文:

Intellij Plugin: Cannot init component state exception

问题

我正在尝试创建一个Intellij Idea插件,并在“Settings->Tools”中进行一些配置。

我有一个ApplicationService来保存和保存这些配置,但在调用ServiceManager.getService(MyService.class)时会出现异常,并且在重新打开Intellij Idea时配置不会持续保存。

以下是异常的堆栈跟踪:

com.intellij.diagnostic.PluginException: 无法初始化组件状态 [Plugin: org.mycompany.mycompany-plugin]
	at com.intellij.configurationStore.ComponentStoreImpl.initComponent(ComponentStoreImpl.kt:116)
	at com.intellij.configurationStore.ComponentStoreWithExtraComponents.initComponent(ComponentStoreWithExtraComponents.kt:50)
	at com.intellij.serviceContainer.ComponentManagerImpl.initializeComponent$intellij_platform_serviceContainer(ComponentManagerImpl.kt:358)
	at com.intellij.serviceContainer.ServiceComponentAdapter.createAndInitialize(ServiceComponentAdapter.kt:58)
	...
Caused by: java.lang.UnsupportedOperationException: 必须为com.mycompany.config.SettingsService指定configurationSchemaKey
	at com.intellij.configurationStore.ComponentStoreImpl.initComponent(ComponentStoreImpl.kt:369)
	at com.intellij.configurationStore.ComponentStoreImpl.initComponent(ComponentStoreImpl.kt:100)
	... 113 more

我找不到关于“configurationSchemaKey”的任何文档,除了它是一个ApplicationService XML参数之外 - 但我无法找出应该放什么值。

以下是我如何定义该服务的方式:

<applicationService
    serviceImplementation="com.testmycode.config.SettingsService"
    id="com.testmycode.config.SettingsService"/>

我漏掉了什么?

英文:

I am trying to create an Intellij Idea Plugin with some configurations in Settings-&gt;Tools.

I have an ApplicationService to hold and save those configurations, but an exception occurs when calling ServiceManager.getService(MyService.class), and the configuration don't persist upon reopening Intellij Idea.

Here is the stack trace for the exception:

com.intellij.diagnostic.PluginException: Cannot init  component state [Plugin: org.mycompany.mycompany-plugin]
	at com.intellij.configurationStore.ComponentStoreImpl.initComponent(ComponentStoreImpl.kt:116)
	at com.intellij.configurationStore.ComponentStoreWithExtraComponents.initComponent(ComponentStoreWithExtraComponents.kt:50)
	at com.intellij.serviceContainer.ComponentManagerImpl.initializeComponent$intellij_platform_serviceContainer(ComponentManagerImpl.kt:358)
	at com.intellij.serviceContainer.ServiceComponentAdapter.createAndInitialize(ServiceComponentAdapter.kt:58)
	at com.intellij.serviceContainer.ServiceComponentAdapter.doCreateInstance(ServiceComponentAdapter.kt:41)
	at com.intellij.serviceContainer.BaseComponentAdapter.getInstanceUncached(BaseComponentAdapter.kt:115)
	at com.intellij.serviceContainer.BaseComponentAdapter.getInstance(BaseComponentAdapter.kt:69)
	at com.intellij.serviceContainer.ComponentManagerImpl.doGetService(ComponentManagerImpl.kt:411)
	at com.intellij.serviceContainer.ComponentManagerImpl.getService(ComponentManagerImpl.kt:394)
	at com.intellij.openapi.components.ServiceManager.getService(ServiceManager.java:20)
	at com.mycompany.config.SettingsService.getInstance(SettingsService.java:14)
	at com.mycompany.config.SettingsConfigurable.reset(SettingsConfigurable.java:46)
	at com.intellij.openapi.options.ex.ConfigurableWrapper.reset(ConfigurableWrapper.java:177)
	at com.intellij.openapi.options.ex.ConfigurableCardPanel.reset(ConfigurableCardPanel.java:166)
	at com.intellij.openapi.options.ex.ConfigurableCardPanel.lambda$createConfigurableComponent$4(ConfigurableCardPanel.java:118)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:894)
	(a lot more lines here)
Caused by: java.lang.UnsupportedOperationException: configurationSchemaKey must be specified for com.mycompany.config.SettingsService
	at com.intellij.configurationStore.ComponentStoreImpl.initComponent(ComponentStoreImpl.kt:369)
	at com.intellij.configurationStore.ComponentStoreImpl.initComponent(ComponentStoreImpl.kt:100)
	... 113 more

I found no documentation about that "configurationSchemaKey", except for the fact that it's an ApplicationService XML paramter - but I could not find out what value I should put in it. I.

Here's how I defined the service:

&lt;applicationService
                serviceImplementation=&quot;com.testmycode.config.SettingsService&quot;
                id=&quot;com.testmycode.config.SettingsService&quot;/&gt;

What am I missing?

答案1

得分: 1

configurationSchemaKey属性是ServiceDescriptor的一部分,并被描述为:

> 由于为了获取注释,必须加载类,但出于性能原因,不能将其作为{@link State}的一部分来指定。

然而,通常不会创建这样的服务来处理设置。

请审查您当前的实现,并遵循IntelliJ Platform SDK开发指南中的设置入门指南

英文:

configurationSchemaKey property is a part of the ServiceDescriptor and is described as:

> Cannot be specified as part of {@link State} because to get annotation, class must be loaded, but it cannot be done for performance reasons.

However, it's not common to create such a service for handling settings.

Please review your current implementation and follow the Introduction to Settings guide in the IntelliJ Platform SDK DevGuide.

huangapple
  • 本文由 发表于 2020年9月27日 05:29:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/64082680.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定