Is there a VSCode equivalent to Notepad++'s user defined language configuration? - visual-studio-code

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

Related

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.

Language server with semantic highlight in VSCode

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

Is it possible in Eclipse to define syntax highlighting for a language without resorting to Java programming?

I am looking for a way to define some syntax coloring for a language in Eclipse. I only need to highlight certain sets of keywords, so the logic is trivial. So I would like to be able to define these in a plain definition file. Is there perhaps some Eclipse plugin which allows this, or is it possible out of the box?
XText is a more generic and complex solution, which will generate for you the code for a custom Editor able to offer the usual IDE features, that are derived from a grammar (your "plain definition file"), including.
syntax coloring, but also
model navigation (F3, etc.),
code completion,
outline view, and
code templates.
The EclipseColorer plugin may fit the bill!
It's a bit fiddly, but try http://gstaff.org/colorEditor/.
It uses the jEdit syntax highlighting files. So you need to create your highlighting file and add it to the jar in the plugin, as well as editing the catalog file in there to include it.
I used jEdit itself to test and debug my custom highlighting, rather than having to exit Eclipse, make the change and reload it each time.

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.