Just one question, because I am obviously doing so...
# scripting
d
Just one question, because I am obviously doing something wrong. Is it possible to reuse the same autocompleter instance for modified versions of the same snippet? To give a lil bit more of context, I have a spring app that gets a "in-progress" snippet in order to get autocompletions suggestions. So, it might get "d" and returns an array containing [d-atasets, d-o, ...]. So far, so good. However, if the user keeps digiting the word, so we get "da" (for datasets), the autocompleter crashes badly.
ERROR Front-end Internal error: Failed to analyze declaration Script
File being compiled: (1,1) in script.kts
The root cause org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException was thrown at: org.jetbrains.kotlin.resolve.lazy.BasicAbsentDescriptorHandler.diagnoseDescriptorNotFound(AbsentDescriptorHandler.kt:18)])
If I add a call to dispose of the the state of the autocompleter, then it works fine (but it is slow as hell...) The object that is in charge of the autocompletion looks like:
private val autocompleter = KJvmReplCompilerWithIdeServices(defaultJvmScriptingHostConfiguration)
suspend fun autocomplete(script: String, position: SourceCode.Position): Outcome {
val injectedLines = injectedScript.lines().size - 1
val adjustedPosition = position.copy(line = position.line + injectedLines)
val sourceCode = withTiming("Creating script") { getSourceCode(script, injectedScript) }
//autocompleter.state.dispose()    <-- uncommenting this one works, but is really slow>, commenting it make it crash badly
val result = withTimingNonBlocking("Autocomplete Duration") {
autocompleter.complete(
sourceCode,
adjustedPosition,
compileConfig
)
}
Does anyone have any idea on why it crashes without the dispose() call?
i
Hi! Maybe you could provide the full stacktrace for this
org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException
?
It would be also helpful to have some minimal example of the application. We use
KJvmReplCompilerWithIdeServices
in Jupyter kernel, completion works there. I suspect the problem in using compileConfiguration. Try to initialize service with the same config that you use for completion
d
Thanks a lot for the interest 🙂 Ok, I managed to remove the dispose problem, it seems that the originating problem was due to asking double autocomplete with a different script with the same name... I created a small example of the app here: https://github.com/davidepaolotua/kotlin-complete-example You can see that changing slightly the script and keeping the same name fails with that error. What I didn't expect was to see it failing with the same error also when using the importScript conf 😕
i
I will take a look, thank you for composing the example!