Language server with semantic highlight in VSCode - visual-studio-code

I'd like to write a language server to VSCode with semantic highlight support. The language I'm using has very complex rules, so I'd like not to rely on a tokenizer to distinguish between identifiers and keywords.
I already have a language service in VS Community, where I've written my own Classifier. It's possible to write own classifier in VSCode, or the only way to colorize a document is add TextMate language specification file to a VScode package?

Semantic coloring is not supported by the LSP as of VS Code 1.29.
There are two main issues currently tracking this feature:
LSP issue
VS Code issue which tracks adding semantic coloring to the VS Code api

Related

What are types of extensions in VSCode?

Hi i am creating my first extension for VSCode following the official tutorial
After running the command yo code to create a boilerplate the program asks which type of extension to create.
I couldn't find any docs for these types of extensions that would help me determine how they differ from each other except for
Language Extensions.
It would be helpful if there were some documentation explaining these.
From top to bottom:
An extension that adds any of the possible contribution points (theme, keybindings, language support, icons, snippets etc.). Initial language is Typescript, but you can use other languages at any time, as long as they can be transpiled to Javascript.
Like 1), but with JS as initial language. Still, you can use other languages too.
A color theme for syntax highlighting, which is a collection of colors for predefined token types (these types are determined by a language extension, either provided by another extension or yours).
Language support, which means handling of a programming or markup language. That includes parsing of such code and providing the tokens for syntax highlighting, code completion, code lenses, parameter info, formatting, linting etc. This could include a language server (which is just a separate process for all that mentioned here), but that has an own entry in this list.
Code snippets, to provide small code parts for use during programming.
Keymap, to provide specific keybindings (e.g. vim is a very popular keybinding).
Extension pack, not 100% sure about that, but I believe this packs multiple extensions into one (e.g. if you have separate keybindings and color theme extensions, you can pack them into a combine extension).
The previously mentioned language server. Language processing can be time consuming and you don't want to block the main (UI) thread. So, any such processing can be moved out to a language server, which can even be written in faster languages like C++ for highest performance.
Given this list it should be clear that you either want 1), 2) or 4).

How do TextMate grammars and themes work with VSCode?

VSCode is built on top of MonacoEditor which doesn't support Textmate grammars and themes. But somehow VSCode made it possible. I am curious how VSCode is able to do this.
I am asking because I am making a code editor (based on Monaco) with TextMate grammar and theme support. But I am unable to understand how I can achieve it.
Though there are packages like monaco-textmate to make TextMate grammars work with Monaco, syntax highlighting is still not working properly.
TextMate grammars depend on a particular regex implementation / library called Oniguruma, which is implemented in C. Monaco however is designed to run in the browser, and the JavaScript regex engine available there is not compatible with Oniguruma. All of this is explained in detail in the "Why doesn't the editor support TextMate grammars?" section of Monaco's FAQ. It also mentions the possibiliy of perhaps eventually compiling Oniguruma to WebAssembly to work around this.
VSCode itself uses vscode-textmate for its TMLanguage handling, which has the Oniguruma library as a native dependency. VSCode can have native dependencies because it doesn't run in a browser environment.
According to monaco-textmate's readme, it is actually heavily based on vscode-textmate:
99% of the code in this repository is extracted straight from vscode-textmate
And it does use the WASM approach mentioned earlier:
monaco-textmate relies on onigasm package to provide oniguruma regex engine in browsers. onigasm itself relies on WebAssembly.
As to why syntax highlighting doesn't always work as expected with monaco-textmate... I have no idea, I expect this is simply a bug in the implementation. Perhaps wait for a response from the maintainer, the issue you linked is fairly new.
At least conceptually there shouldn't be a reason why it couldn't achieve the same syntax highlighting VSCode does, since it uses the same regex flavour.

Dynamic Syntax Highlighting in VSCode

I'm writing an extension for Visual Studio Code which features syntax highlighting for a scripting language. I was able to color many important elements via a TextMate grammar file. There are many lines where I would not know if a captured string refers to a user defined class (for a static call, for instance), or an instance of a class/variable until I perform analysis in code.
Is there a way I can dynamically highlight syntax via code in Visual Studio Code or any alternatives for achieving this?
What you are asking for is semantic coloring. It is not supported as of VS Code 1.35. You could try to emulate it using decorators, but the decorators can easily get out of sync with the rest of the highlighting during editing
This VS Code issue tracks adding semantic coloring to VS Code.

Customizability of the IDEs

I am thinking of modifying an existing IDE (Ex : By developing a plugin) to provide support for a proprietary scripting language. I just need to implement few features like syntax highlighting, Autocompleting etc. (i.e the requirements are really simple). What would be the best IDE or Text editor to integrate the feature. As an example if I think to develop an eclipse plugin for that it would be a pain.
What do you think about Notepad ++?
You might want to give the NetBeans Generic Language Framework a try.
NetBeans project called Generic Languages Framework allows you to define a programming language and integrate it to NetBeans IDE. In the first step you should describe the language - lexical part (define tokens using regular expressions) and syntax (grammar rules). In the second step you can define how to visualize this language in NetBeans. You can define colors for tokens (syntax coloring) or folding (based on grammar rules). You can define what parts of this language should be displayed in the navigator, and how to indent this language plus many other features.
This tutorial should guide you through the process of creating new NetBeans module, adding languages support into it, describing lexical and syntax structure of your language and adding support for all standard editor # features for your language.
Notepad++ allows you to define custom syntax highlight files in a very easy way, but it's not a very good solution for auto-completion (look at this SO question).
If you want a real IDE to extend, I suggest you to use Eclipse.
Update: Tutorial on how to develop an Eclipse plugin.
In vim you can easily add your custom syntax highlighting rules by adding another file in the syntax folder; for the details it is best to look at the help.
If I remember correctly notepad++ also allows defining custom syntax files.

Is there a VSCode equivalent to Notepad++'s user defined language configuration?

I really enjoyed defining syntax highlighting rules in Notepad++ for the various build logs and artifacts I've worked on in the past to make certain text markers pop out. I was wondering if VSCode has any capabilities to do likewise.
For reference to the unfamiliar here's the Notepad++ documentation and a live demonstration:
https://npp-user-manual.org/docs/user-defined-language-system/
How to Create Custom Language Definitions in Notepad++
Looks like there is support for something in this direction. The terminology is slightly different though and there may not be a GUI interface like Notedpad++
Declarative Language Feature
Syntax Highlight Guide: VS Code uses TextMate grammar for syntax highlighting. This guide will walk you through writing a simple TextMate grammar and converting it into a VS Code extension.
Create Custom Language in Visual Studio Code
https://code.visualstudio.com/api/language-extensions/overview#declarative-language-features
https://code.visualstudio.com/api/language-extensions/language-configuration-guide