kotlin-analysis-server icon indicating copy to clipboard operation
kotlin-analysis-server copied to clipboard

Add proper text synchronization

Open fwcd opened this issue 2 years ago • 2 comments

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 and VirtualFile (with LightVirtualFile being an in-memory implementation, see e101c13ece40ac3d31f7f36ad33685be6ba16709 for some experimentation with this)
  • Document (apparently for mediating between virtual files and PSI?)
    • FileDocumentManager and PsiDocumentManager 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 PsiFiles every time the user changes a document, ideally, however, we would like to use whatever IntelliJ offers to perform incremental compilation/parsing.

Some resources:

fwcd avatar Jul 08 '22 02:07 fwcd

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

rami3l avatar Jul 16 '22 06:07 rami3l

The analysis API now contains a platform interface, KaSourceModificationService might be what we are looking for.

fwcd avatar Sep 15 '24 13:09 fwcd