One can add support for other programming languages to Apache NetBeans using its Rich Client Platform API.
Support to a programming language can be considered complete when it provides support for:
- File type recognition
- Project type
- Semantic syntax highlighting and braces matching
- Code completion
- Navigation (jump to definition, peek definition, find all references, symbol search)
- Types and documentation on hover
- Code formatting
- Configuration
- Refactoring (e.g. rename, move)
- Error squiggles and apply suggestions from errors
- Debugging
- Snippets
- Build tasks
There are a number of ways to add support for a programming language, each one of them having its pros and cons. Most of the above are commonly supported by Apache NetBeans' Rich Client Platform APIs, but for some of them, different APIs have been developed that support one of the following technologies:
How to add support in NetBeans to a programming language?
First, you will need Apache NetBeans source code. Please download or clone it from here and build it.
1. File Type Recognition
The first thing to do is for NetBeans to be able to recognize the file type. E.g. if you are adding support for the kotlin programming language you would like NetBeans editor to be able to recognize .kt
source files.
Use the 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. A DataObject
file will be created with a number of annotations.
Important Note! Make sure to create your module inside your cloned Apache NetBeans source code. Your module will need some files from nbbuild
folder.
Take a look at java/kotlin.editor/src/org/netbeans/modules/kotlin/editor/KtDataObject.java
and rust/rust.sources/src/org/netbeans/modules/rust/sources/rs/RustFileDataObject.java
as examples of DataObject
s.
Hint! To open a source file easily, click on Window → Favorites and navigate to the source file (e.g. a .kt
file if you are adding support for kotlin, or a .rs
source file for Rust)
2. Custom project types
You may want to create a new "Project Type" for your specific language. More explicitly, when you click on File → New Project, you can customize the New Project wizard dialog to create a new project for your language. For instance, "Rust" projects usually have a folder structure defined by the "cargo" tool. rust/rust.project.api
module allows the user to create a new cargo project.
The NetBeans Project Type Tutorial is a good starting point.
3. Semantic Syntax highlighting and brace matching
Without syntax highlighting, NetBeans opens the source file as a text file. Each technology uses different ways to support syntax highlighting:
4. Code Completion
5. Navigation
Navigation includes: jump to definition, peek definition, find all references, symbol search etc.
6. Types and documentation on hover
7. Code formatting
8. Configuration
NetBeans IDE provides the Options window (menu Tools →
Options or NetBeans →
Preferences on MacOS) that allows the user to customize it. You can provide any customizations for your language support in the Options window, too. E.g. you could allow the user to provide the path to the Kotlin compiler. See e.g. rust/rust.cargo
module that allows the user to provide the path to cargo
for Rust projects.
The NetBeans Options Window Module Tutorial explains how you could do that.
9. Refactoring
Refactorings like e.g. rename, move are supported by all major IDEs.
10. Error squiggles and apply suggestions from errors
11. Debugging
12. Snippets
13. Build tasks
Resources
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".
Other resources
- 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.
17 Comments
Eric Bresie
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.
Eric Bresie
What top level Netbeans packages/classes are involved in developing a LSP language?
Eric Bresie
Mailing List References
Eric Bresie
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,
<https://blogs.apache.org/netbeans/entry/lsp-client-demo-ba-sh>.
Eric Bresie
Eric Bresie
Eric Bresie
From a Netbeans project creation perspectives details defined here https://dzone.com/articles/quickstart-guide-language-supp is a good starting point
Eric Bresie
LSP Spec: https://microsoft.github.io/language-server-protocol/specification
Eric Bresie
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 )
Eric Bresie
Eric Bresie
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
o Hints
o Occurencies
o Formatting
Eric Bresie
Examples of Implementations:
Eric Bresie
Eric Bresie
LSP Server Implementors
https://microsoft.github.io/language-server-protocol/implementors/servers/
Eric Bresie
Eric Bresie
Christian Lenz
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