This How-To tutorial explains how to add support for a programming language to Apache NetBeans using the LSP protocol.
What is the Language Server Protocol (LSP)?
How to add support to another programming language using LSP in NetBeans
- Create a new NetBeans module. There are two kinds of NetBeans modules, ant-based and maven-based.
- To add a new ant-based NetBeans module, click on File → New Project → Java with Ant → NetBeans modules category and select the Module project.
- Give a name to your module, e.g. Kotlin-editor and provide a location to it. Select Standalone Module. Click Next.
- Provide a Code Name Base; this is the package name, e.g.
org.netbeans.modules.kotlin.editor
. Click Finish.
- To add a new maven-based NetBeans module, click on File → New Project → Java with Maven category and select the NetBeans Module project.
- Provide a Project Name, e.g. kotlin-editor as well as the maven coordinates, e.g.
org.netbeans.modules
as the Group Id. - Select the NetBeans version (usually the same as the one of the NetBeans IDE you are developing in) and click on Finish.
- Provide a Project Name, e.g. kotlin-editor as well as the maven coordinates, e.g.
- To add a new ant-based NetBeans module, click on File → New Project → Java with Ant → NetBeans modules category and select the Module project.
...
This tutorial is an LSP Client demo to provide support for the (ba)sh language.
File Type Recognition
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.
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.
Language Feature Support |
File type recognition |
Project type |
Semantic syntax highlighting |
Formatting |
Braces matching |
Error Hints/Fixes/Suggestions |
Code completion |
Code templates |
Refactoring |
Debugging |
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
- Nadeeshaan G. & Nipuna M. (2022), Language Server Protocol and Implementation: Supporting Language-Smart Editing and Programming Tools, APress.
- Stalla A. (2021), "Go to Definition in the Language Server Protocol", Strumenta.
- Watt D.A. & Brown D. F. (2000), Programming Language Processors in Java, Prentice Hall.