A plugin can be considered complete when it provides support for:
- code completion
- jump to definition, peek definition, find all references, symbol search
- types and documentation on hover
- code formatting
- refactoring (e.g. rename, move)
- error squiggles and apply suggestions from errors
- build tasks
To get started, reuse an existing Textmate grammar. This tutorial is an LSP Client demo to provide support for the (ba)sh language.
Adding more advanced support for a new language may consist of several parts, and may be time consuming.
The following parts of a new language support should be considered:
- File type recognition (so that NetBeans knows they belong to the new language)
- Project type, if needed, so that the files can be built, run and debugged
- Add editing features, including:
- Sematic syntax highlighting
- Braces matching, automatic closing of braces
- Error Hints/Fixes/Suggestions
- Code completion
- Code templates
- Refactoring (e.g. renaming, find usages, go to, etc.)
There are a number of ways to add support for a programming language, each one of them having its pros and cons. Historically, these are:
- JavaCC is the old way
- ANTLR is the modern way, but it is not easy to keep the many languages up-to-date; there are a number of tutorials on how to create a NB plugin using ANTLR, many outdated, with the best one in the Apache NetBeans book to add a plugin for blockchain support.
- LSP seems to be gaining ground and seems to become the new way. This tutorial is an LSP Client demo to provide support for the (ba)sh language.
File Type Recognition
New File → Module Development → File Type wizard. A MIME type must be specified. This MIME type will be the key under which other services will be looked up.
See the File Type Integration Tutorial for more details on how to add File Type recognition support.
Custom project types
You may want to create a new "Project Type" for your specific language. For instance, "Rust" projects usually have a folder structure defined by the "cargo" tool.
The "NetBeans Project Type Tutorial" available at https://netbeans.apache.org/tutorials/nbm-projecttype.html is probably a good starting point.
Adding editor features
You can also add language-specific features (folding, syntax highlighting, formatting, etc.) to the NetBeans editor to make it easier for users to program in your language.
You can use either
- The NetBeans specific APIs. See "NetBeans APIs for Developing Code Editors" at https://netbeans.apache.org/kb/docs/platform/#_netbeans_apis_for_developing_code_editors ) for a list.
- Or use an external Language Server Provider.
Adding Syntax Highlighting
Syntax highlighting can be implemented either by writing a
lexer module for NetBeans, or by re-using TextMate grammars.
Please see the use cases and an example grammar registration for the latter.
Adding Code Completion and Other Editor Features
These can be done either by:
- writing them against NetBeans APIs (see the NetBeans Code Completion tutorial at https://netbeans.apache.org/tutorials/nbm-code-completion.html)
- or by delegating to an LSP Server. Please see Typescript LSP server integration .
NetBeans Specific Resources
Rich Client Programming: Plugging into the NetBeans Platform https://www.amazon.com/Rich-Client-Programming-Plugging-NetBeans/dp/0132354802
Apache NetBeans Platform for Beginners https://leanpub.com/nbp4beginners
- Lahoda J. (2019), "LSP Client demo - (ba)sh language server", ASF.
- Cardona J.R. (2018), "Quick Start: Creating Language Tools In NetBeans IDE", DZone.
- NetBeans Platform Learning Trail https://netbeans.apache.org/kb/docs/platform/index.html
- Kostaras I. et al. (2020), Pro Apache NetBeans, APress, Chapter 11, "Writing a Plugin for NetBeans".
- Clinton J.L. (2021), Build Your Own Programming Language, Packt.
- Nadeeshaan G. & Nipuna M. (2022), Language Server Protocol and Implementation: Supporting Language-Smart Editing and Programming Tools, APress.
- Parr T. (2010), Language Implementation Patterns, The Pragmatic Programmer.
- Stalla A. (2021a), "Converting from JavaCC to ANTLR", Strumenta.
- Stalla A. (2021b), "Go to Definition in the Language Server Protocol", Strumenta.
- Singh V., Basics of Compiler Design, Anniversary Edition.
- Tomassetti G., "The ANTLR Mega Tutorial", Strumenta.
- Watt D.A. & Brown D. F. (2000), Programming Language Processors in Java, Prentice Hall.
I am putting comments based on email threads in hopes they can make it into the main context above after which the specific comments can be removed.
What top level Netbeans packages/classes are involved in developing a LSP language?
Mailing List References
There are different ways to implement new languages which includes:
- JavaCC <https://javacc.github.io/javacc/> is the old way
- ANTLR <https://www.antlr.org/> is the modern way, but it is not easy to keep the many languages up-to-date; there are a number of tutorials on how to create a NB plugin using ANTLR, many outdated, with the best one in the Apache NetBeans book
- LSP <https://langserver.org/> seems to be gaining ground,
From a Netbeans project creation perspectives details defined here https://dzone.com/articles/quickstart-guide-language-supp is a good starting point
LSP Spec: https://microsoft.github.io/language-server-protocol/specification
Old wiki site provided legacy details on how to create a new language https://web.archive.org/web/20210118012355/http://wiki.netbeans.org/How_to_create_support_for_a_new_language
This in turn indicates
The replacement tutorials for all the text that follows below are:
* NetBeans JavaCC Lexer Tutorial http://platform.netbeans.org/tutorials/nbm-javacc-lexer.html (Web Archive https://web.archive.org/web/20210117160954/https://platform.netbeans.org/tutorials/nbm-javacc-lexer.html )
* NetBeans JavaCC Parser Tutorial http://platform.netbeans.org/tutorials/nbm-javacc-parser.html (Web Archivew https://web.archive.org/web/20210117160955/https://platform.netbeans.org/tutorials/nbm-javacc-parser.html )
From Chris Lentz (https://lists.apache.org/x/thread.html/r4e0767b237d64cbb1a15f19b88550c94ec0b2e246371dcd0e321ec8e@%3Cdev.netbeans.apache.org%3E)
- Textmate is used for
o Syntax highlighting
o Syntax errors
o Braces matching and automatically closing after type open brace
o Indentation and auto indentation on enter
o Folding code blocks
- LSP is used for
o Code completion
Examples of Implementations:
LSP Server Implementors
A third party plugin only make sense if all needed APIs inside NetBeans are public and can be used from the 3rd-party-plugin which is not often the case. See this ticket for the nbts plugin: https://github.com/Everlaw/nbts/issues/81#issuecomment-272748787