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
  • snippets
  • 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
    • Formatting
    • Braces matching, automatic closing of braces
    • Error Hints/Fixes/Suggestions
    • Code completion
    • Code templates
  • Refactoring (e.g. renaming, find usages, go to, etc.) 
  • Debugging

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:

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.

You can use either

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:


NetBeans Specific Resources

Other resources

  1. Clinton J.L. (2021), Build Your Own Programming Language, Packt.
  2. Nadeeshaan G. & Nipuna M. (2022), Language Server Protocol and Implementation: Supporting Language-Smart Editing and Programming Tools, APress.
  3. Parr T. (2010), Language Implementation Patterns, The Pragmatic Programmer.
  4. Stalla A. (2021a), "Converting from JavaCC to ANTLR", Strumenta.
  5. Stalla A. (2021b), "Go to Definition in the Language Server Protocol", Strumenta.
  6. Singh V., Basics of Compiler Design, Anniversary Edition.
  7. Tomassetti G., "The ANTLR Mega Tutorial", Strumenta.
  8. Watt D.A. & Brown D. F. (2000), Programming Language Processors in Java, Prentice Hall.


  1. 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.

  2. What top level Netbeans packages/classes are involved in developing a LSP language?

    • LSP SPI project found in this project/context
      • Netbeans\ide\api.lsp\src\org\netbeans\spi\lsp\

  3. 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, 

  4. I was hoping for some guidance and/or pointers to documentation or tutorials on how to add new Language support to Netbeans.
    I understand there being movement towards using LSP rather than full language support within a give language module without LSP. Is the preferred route to use LSP or native support? And what is the pros/con of each approach?
    For native support...
    I found some older articles (1) which provides some details but wasn’t sure if this is still the “best practice” in current Netbeans or if there is another preferred way or even new tutorials. There are also some older documents on the old Netbeans site (4)(5)(6) (not sure where on the new site so providing archived versions) but now sure how up to date these are.
    For LSP support...
    I find a discussion on similar implementation on a new language here (2) which provides some guidance as well as another’s related to the VS Code LSP activities (3)
    It seems for LSP the general consensus is to look at the cpplite and Typescript implementations as good examples of LSP based.
    So what other newer guidance is available and/or recommended?
    (1) https://dzone.com/articles/quickstart-guide-language-supp
    (2) https://lists.apache.org/x/list.html?dev@netbeans.apache.org:lte=1y:Textmate%20or%20LSP%20for%20Cucumber
    (3) https://lists.apache.org/x/thread.html/rf84a830a545d0f3bfb39a07d3f7fcf33ca7ab28deb82bf6551f54e44@%3Cdev.netbeans.apache.org%3E
    (4) https://web.archive.org/web/20210118012355/http://wiki.netbeans.org/How_to_create_support_for_a_new_language
    (5) https://web.archive.org/web/20210117160954/https://platform.netbeans.org/tutorials/nbm-javacc-lexer.html
    (6) https://web.archive.org/web/20210117160955/https://platform.netbeans.org/tutorials/nbm-javacc-parser.html

  5. if you build it you're under control. If someone else builds the LSP server for you then you're not under control, but you 
    don't have to build it.
    Note also that "implementing a new language" (adding support for it in NetBeans, if I understand your question correctly) is much more than lexing and parsing the language.
    You may want to add a specific project type, interact with language specific tools (Makefiles, pom.xml or whatever), add wizards, editor 
    folding, editor hints, etc.

  6. From a Netbeans project creation perspectives details defined here https://dzone.com/articles/quickstart-guide-language-supp is a good starting point

  7. From Antonio:

    Maintaining an ANTLR grammar over the years is difficult and time consuming (see for instance all the changes to the NetBeans C++ grammar in NetBeans [1]). LSP servers, when mantained by knowledgeable teams, may give better results with less effort. Apple, for instance, decided to move to clangd (from libclang) a few years back ([2]). For simpler languages/DSLs I think Eclipse's XText https://www.eclipse.org/Xtext/ outperforms JetBrain's MPS https://www.jetbrains.com/mps/ (the generated parsers could then be reused in NetBeans). [1] https://github.com/emilianbold/netbeans-releases/commits/master/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/parser/cppparser.g [2] https://lists.llvm.org/pipermail/cfe-dev/2018-April/057668.html
  8. From Chris L:

    What is needed here for every language is: - Semantic syntax highlighting (more than with textmate I think) - Formatting (custom implementation or LSP?) - Refactoring (renaming, find usages, go to, etc. – LSP needed) - Hints/Fixes/Suggestions, etc – LSP needed + custom implementation if LSP doesn’t have that much - Braces matching, automatic closing of braces (custom implementation?) - Code completion – LSP needed - Code templates – custom implementation - Showing errors of the Syntax or Control flow – LSP needed So as an alternative to ANTLR which of course is good, we Need those stuff for textmate too. Where we can all implement the stuff based on textmate files and not only on g and g4 lexer and parser. If possible.

    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

  9. Examples of Implementations:

  10. ANTLR Based:

    the best 'tutorial' is chapter 11 of Pro Apache NetBeans <https://www.amazon.com/Pro-Apache-NetBeans-Building-Applications/dp/1484253698> book,
    even though it doesn't use the modern trend of TextMate and LSP, but it is based on ANTLR.

  11. And leverage the tm grammars from some place like here
    From Chris L:

    So use a Textmate language from wherever you want. I just made a little repo as you already mentioned to collect all of them to use.

    And then the LSP for that language, if it exists.

    I would prefer to have it inside NetBeans, because we are more flexible with the APIs making friends if needed or taking whatever is needed. On the other hand I like 3rd Party pllugins more because of different release cycles. If we encounter a bug today, I can fix it today and
    release it today. Not possible with NetBeans if it is not a real blocker bug. Problem is again the problem that not all APIs are public
    to use them within your 3rd party plugin.
  12. When adding a new language, should this generally be done as a separate plugin or be integrated within the netbeans codebase itself? 

    I guess this could go either way but assume making an external plugin allows more flexibility to management of it,
    avoids growing the netbeans codebase significantly, but has a little less visibility up front (and not part of “Netbeans” proper) with the need to manage things separately from the netbeans master repository

  13. 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