getService return null
Answered
I register the service when the project (Activity) is launched:
class MyTestStarupActivity : StartupActivity, StartupActivity.DumbAware {
override fun runActivity(project: Project) {
project.registerServiceInstance(MyTestService::class.java, MyTestService())
}
}
Then I try to get this service in CompletionContributor and get null:
class MyTestCompletionContributor : CompletionContributor() {
override fun fillCompletionVariants(parameters: CompletionParameters, result: CompletionResultSet) {
val service = parameters.editor.project?.getService(MyTestService::class.java)
Notifications.Bus.notify(
Notification(
Notifications.SYSTEM_MESSAGES_GROUP_ID,
"DEBUGGER",
"service: $service",
NotificationType.WARNING)
)
super.fillCompletionVariants(parameters, result)
}
}
Why is this happening, what am I doing wrong?
Please sign in to leave a comment.
Please use regular ways of registering Service as described here https://plugins.jetbrains.com/docs/intellij/plugin-services.html
I deleted my service from plugin.xml and added the @Service annotation to it. I also deleted the service registration using "registerServiceInstance". But I still get null when I want to get a service.
What could be the problem?
Please share full project
Thanks for the reply!
There was a mistake on my side.