Implement "Language Service"
Implement a "Language Service", which is a server exposing a JSON based API that accepts user cursor movement and each character changes. It brings back, e.g., a list of members for the editor to show.
How it works:
- Each source file gets compiled to AST.
- If a source file does not change, the AST does not change. AST is immutable. Type annotations are kept in a separate hash table.
- If a source file changes at a place, only that node at the given place and all parent nodes must change (in the direct line to the root), but all other nodes in the file can be reused and hooked in. This saves time to reconstruct the AST
- The AST is thus always available and ready.
- Type annotations must be redone, since some base type can change in a file, and all modules that depend on it can change their type annotations too. The AST however does not change. In Fortran, a given module can be fully compiled if just the symbol table is known. So given a symbol table, one must redo type annotations for all AST trees of all modules.
- The type annotations are slow in general, so they work on the "pull" basis --- for a given symbol, one can figure out a type by going over the parents, and the rest of types are not computed.
- For a source file change, the mentality is to "start over". The type annotations are erased (but perhaps can be reused in some fashion to build the new annotations). The AST is only changed in one file at a time, and one can greatly reuse the AST tree in there too, as described above.
Typescript does it:
https://github.com/Microsoft/TypeScript/wiki/Architectural-Overview
C# also has it:
https://github.com/dotnet/roslyn https://msdn.microsoft.com/en-us/magazine/dn879356 https://github.com/dotnet/roslyn/wiki/Syntax%20Visualizer
Clang has it: https://github.com/llvm-mirror/clang-tools-extra/tree/master/clangd
There seems to be a standard now: https://en.wikipedia.org/wiki/Language_Server_Protocol, and it is supported, e.g., by https://en.wikipedia.org/wiki/Visual_Studio_Code.
Edited by Ondřej Čertík