kotlin-analysis-server
kotlin-analysis-server copied to clipboard
Add proper text synchronization
The language server should synchronize its virtual file system via LSP's text synchronization methods (mainly KotlinTextDocumentService.didChange
). To do so, we should investigate how much the IntelliJ APIs take care of for us. Essentially, there are a few abstraction levels in the IntelliJ API, that are partly accessible to us:
-
VirtualFileSystem
andVirtualFile
(withLightVirtualFile
being an in-memory implementation, see e101c13ece40ac3d31f7f36ad33685be6ba16709 for some experimentation with this) -
Document
(apparently for mediating between virtual files and PSI?)-
FileDocumentManager
andPsiDocumentManager
are interesting here - We cannot really change them though, since we apparently miss some extension points from IntelliJ (write access guards)
-
-
PsiFile
(the parsed AST)
Of course, we could recreate PsiFile
s every time the user changes a document, ideally, however, we would like to use whatever IntelliJ offers to perform incremental compilation/parsing.
Some resources:
-
intellij-lsp-server
(interesting since it uses the same APIs for roughly the same purpose, however in a plugin context) -
kotlin-language-server
(using an expression-level tiny fake file mechanism) - The IntelliJ Platform docs on virtual files, VFSes, documents and PSI
Are you looking for something like this?
public static void reparseFiles(Project project, Collection<? extends VirtualFile> files, boolean includeOpenFiles);
An example to use the underlying method in FileContentUtilCore
:
https://github.com/vsch/idea-multimarkdown/blob/f18cec21960d7f508b5e27ad47e8e3fdd8d3475a/src/main/java/com/vladsch/md/nav/MdProjectComponent.kt#L321
The analysis API now contains a platform interface, KaSourceModificationService
might be what we are looking for.