I was originally thinking to design the compilier upfront as a compiler and LSP server as well, but the answers there dissuaded me from making them share all code. But, I would still like them to share some code to make my life easier. So, what are some parts of the code that they can share?
The information required by LSP is more detailed, and many of them can be reused by the compiler.
Various syntax errors and compile-time errors in LSP can be reported using this endpoint.
In the compiler, when you execute through the command line, you also need to display this information again.
When you do static type checking, record the type of each variable and display it using this endpoint.
Before using this capability, it is necessary to implement the ability to query token objects in the language according to offset or
This is also part of type checking, you need to know the actual type of each call.
When you check whether the call is legal, cache the result of the check in the call symbol, and then reverse the query in the same way as before.
This can implement interfaces such as definition jumps, as well as record where functions or interfaces are called.
After you verify the references of all symbols, you should know the attributes of each symbol, and you can update the semantic highlighting through this endpoint.