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

Compare with Current View Page History

« Previous Version 10 Current »

Kotlin programming language is supported in a number of ways:

  • Kotlin plugin donated by JetBrains
  • Kotlin Language Server

JetBrains Kotlin plugin

Donated by JetBreains.

Original URL: https://github.com/JetBrains/kotlin-netbeans

It can be found inside contrib folder of Apache NetBeans source code:

https://github.com/JetBrains/kotlin-netbeans/issues/137

https://github.com/apache/netbeans/pull/1398

Steps to build it:

  1. The pom.xml requires some dependencies that are not in the central maven repository. These are: asm-all.jar, idea-formatter.jar, intellij-core.jar, kotlin-converter.jar, kotlin-formatter.jar, kotlin-ide-common.jar, openapi-formatter.jar.  intellij-core.jar artifact can be directly taken from: https://www.jetbrains.com/intellij-repository/releases. The other artifacts can be found at https://github.com/JetBrains/kotlin-eclipse project inside the kotlin-bundled-compiler folder. Once you have collected all these libraries, create a lib folder inside kotlin-netbeans project and paste them inside there.
  2. In NetBeans, click on Tools → Plugins → Settings tab and add a new plugin Portal: Name: NetBeans 8.2 Plugin Portal, URL: http://updates.netbeans.org/netbeans/updates/8.2/uc/final/distribution/catalog.xml.gz. Make it active.

Once you build the project, all Java and NetBeans dependencies should be resolved. However, the project also contains a lot of Kotlin code which throws a lot of compilation errors. The plugin contains Kotlin code that needs to be built/migrated to the latest Kotlin compiler version and all the compilation errors need to be fixed.


Language Feature SupportStatus
File type recognition
Project type
Semantic syntax highlighting
Formatting
Braces matching
Error Hints/Fixes/Suggestions
Code completion
Code templates
Refactoring
Debugging

Sidenote: There are also contrib/groovy.grails and contrib/groovy.grailsproject.

Kotlin LSP

NetBeans 12.x and later already provide some basic support in the java/kotlin.editor module. With this plugin one can open a .kt file via the Windows→Favourites tab.

Syntax highlighting of .kt source files are provided using the Kotlin.tmLanguage.json TextMate syntax. This JavaDoc explains how to integrate a TextMate lexer with NetBeans.

Code completion, navigation etc. are provided by the Kotlin Language Server project. To use the Kotlin Language server:

  1. Download and build Kotlin Language Server with JDK 11 using the command: ./gradlew :server:installDist (how can we add kotlin-language-server/server/build/install/server/bin/kotlin-language-server)
  2. Open netbeans/java/kotlin.editor module in NetBeans IDE
  3. Add a new class:


package org.netbeans.modules.kotlin.editor.lsp;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.api.editor.mimelookup.MimeRegistration;
import org.netbeans.modules.lsp.client.spi.LanguageServerProvider;
import org.openide.util.Lookup;
@MimeRegistration(mimeType="text/x-kotlin", service=LanguageServerProvider.class)
public class KotlinLSPServer implements LanguageServerProvider {

    private static final Logger LOG = Logger.getLogger(KotlinLSPServer.class.getName());

    @Override
    public LanguageServerDescription startServer(Lookup lookup) {
      File server = new File("<path_to_>/kotlin-language-server/server/build/install/server/bin/kotlin-language-server");
//InstalledFileLocator.getDefault().locate("typescript-lsp/node_modules/typescript-language-server/lib/cli.js", null, false);
        try {
            Process p = new ProcessBuilder(new String[] {server.getAbsolutePath()}).directory(server.getParentFile().getParentFile()).redirectError(ProcessBuilder.Redirect.INHERIT).start();
            return LanguageServerDescription.create(p.getInputStream(), p.getOutputStream(), p);
        } catch (IOException ex) {
            LOG.log(Level.FINE, null, ex);
            return null;
        }
    }
}


Language Feature SupportStatus
File type recognition
Project type
Semantic syntax highlighting
Formatting
Braces matching
Error Hints/Fixes/Suggestions
Code completion
Code templates
Refactoring
Debugging
  • No labels