You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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

  1. Create a new NetBeans module. There are two kinds of NetBeans modules, ant-based and maven-based.
    1. To add a new ant-based NetBeans module, click on File → New Project → Java with Ant → NetBeans modules category and select the Module project.
      1. Give a name to your module, e.g. Kotlin-editor and provide a location to it. Select Standalone Module. Click Next.
      2. Provide a Code Name Base; this is the package name, e.g. org.netbeans.modules.kotlin.editor. Click Finish.
    2. To add a new maven-based NetBeans module, click on File → New Project → Java with Maven category and select the NetBeans Module project.
      1. Provide a Project Name, e.g. kotlin-editor as well as the maven coordinates, e.g. org.netbeans.modules as the Group Id.
      2. Select the NetBeans version (usually the same as the one of the NetBeans IDE you are developing in) and click on Finish.

Next you need to provide support for:

  • syntax highlighting
  • 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
  • snippets
  • build tasks


Download the LSP implementation for the language you wish to add support for. Some useful links:

For example, to add support for Kotlin programming language, download and build kotlin-language-server. Once built, you will need to provide the path to kotlin-language-server/server/build/install/server/bin/kotlin-language-server to a class that implements LanguageServerProvider as will be described later.

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

Other resources

  1. Nadeeshaan G. & Nipuna M. (2022), Language Server Protocol and Implementation: Supporting Language-Smart Editing and Programming Tools, APress.
  2. Stalla A. (2021), "Go to Definition in the Language Server Protocol", Strumenta.
  3. Watt D.A. & Brown D. F. (2000), Programming Language Processors in Java, Prentice Hall.
  • No labels