This Engineering Notebook post discusses how to support Leonine syntax coloring in vs-code. This post will focus only on the biggest picture. Details must wait until various experiments are complete.
*Present status* At present, leoInteg defines Leo-specific syntax in syntaxes/leoBody.tmLanguage.json. This is a start, but it doesn't color non-Leonine syntax. *What must be done* 1. Make Leonine syntax available in every node, regardless of what @language directive is in effect, while retaining the normal syntax coloring that should be done for each language. 2. Handle multiple @language directives in a single body text. *Two strategies* There seem to be two possible ways forward: Strategy 1: Use vs-code's syntax-coloring services, enhanced with Leonine features. Strategy 2: Use Leo's existing syntax-coloring code, and communicate the results back to vs-code. Happily, leoInteg can probably combine the best features of both strategies! *The Language Server Protocol* The Programmatic Language Features <https://code.visualstudio.com/api/language-extensions/programmatic-language-features> page suggests implementing a language server that implements the Language Server Protocol <https://microsoft.github.io/language-server-protocol/> (LSP). The Language Sever Extension Guide <https://code.visualstudio.com/api/language-extensions/language-server-extension-guide> page indicates that LSP was designed to handle the resource-intensive nature of the problem. This means that Leo should be able to use the LSP without serious performance issues. Using an LSP is more complicated than implementing a vscode.language hook, but LSP has important advantages: 1. The Language Server can be written in any language. 2. The Language Server can be reused to provide smart editing [or coloring] features for multiple editors. Bingo! We can repackage (parts of?) Leo's existing syntax coloring code as a language server! The details are fuzzy. It might be possible to use "leo" as the language, and have the server handle *all *aspects of coloring. Or it might be more convenient to have the server modify only Leonine constructs such as Leo directives and section references. *Summary* We want to support multiple @language directives in body panes, as well as all Leonine syntax. Aside from that, we want to default to vs-code's syntax coloring. That is, we want to "interweave" Leonine coloring with vs-code's standard coloring. We don't want to write a new json colorizer description for each language that vs-code supports. Nor do we want to create a bespoke vscode.language hook for every language that vs-code supports. Instead, leoInteg's colorizing code will likely use an LSP. The LSP can be written in python, which means a repackaging of Leo's existing colorizing code may be possible. Significant new invention will be required. However, the LSP was designed for just such task. I am fairly confident that leoInteg will be able to do Leonine syntax coloring quickly enough. Edward -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/f2842011-643e-4d7b-b591-4d4082182fc2o%40googlegroups.com.
