• Stars
    star
    413
  • Rank 104,801 (Top 3 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 6 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This language client library provides language server protocol support for IntelliJ IDEA and other Jetbrains IDEs.

LSP4IntelliJ - Language Server Protocol Support for the Jetbrains Plugins

Build Status GitHub last commit Gitter

Lsp4IntelliJ is a client library, which provides language server support for IntelliJ IDEA and other Jetbrains IDEs.

It is designed to be used with any IntelliJ plugin as its language server client to get the features that are based on the language server.

Also, it allows the plugin developers to use language-specific language server protocol extensions via the JSON-RPC protocol.

Table of Contents

How to use

Follow the steps below to use Lsp4IntelliJ in your custom language plugin.

1. Add the lsp4intellij dependency in the build file of the project.

For instructions on adding Lsp4IntelliJ as a dependency when using the below build tools, go to jitpack/lsp4intellij.

  • gradle
  • maven
  • sbt

Info: - The Maven publishing process is currently WIP. Thus, the possibility to add LSP4IntelliJ as a dependency will be available soon in the Maven central.

2. Add a plugin.xml file

deprecated "components"-based setup 1. Add `IntellijLanguageClient` as an application component. ```xml org.wso2.lsp4intellij.IntellijLanguageClient ```
  1. Add the following extensions to get the relevant features as listed below.

    • Code completion (You can replace the language attribute if you already have your own custom language implementations)
      <extensions defaultExtensionNs="com.intellij">
          <completion.contributor implementationClass="org.wso2.lsp4intellij.contributors.LSPCompletionContributor"
                                  id="LSPCompletionContributor" language="any"/>
      </extensions>
    • Code Formatting
      <actions>
         <action class="org.wso2.lsp4intellij.actions.LSPReformatAction" id="ReformatCode" use-shortcut-of="ReformatCode"
                 overrides="true" text="Reformat Code"/>
         <action class="org.wso2.lsp4intellij.actions.LSPShowReformatDialogAction" id="ShowReformatFileDialog"
                 use-shortcut-of="ShowReformatFileDialog" overrides="true" text="Show Reformat File Dialog"/>
      </actions>
    • Diagnostics and code actions (You can replace the language attribute if you already have your own custom language implementations)
      <extensions defaultExtensionNs="com.intellij">
         <externalAnnotator id="LSPAnnotator" language="TEXT" implementationClass="org.wso2.lsp4intellij.contributors.annotator.LSPAnnotator"/>
      </extensions>
    • Find Usages
      <actions>
          <action class="org.wso2.lsp4intellij.actions.LSPReferencesAction" id="LSPFindUsages">
               <keyboard-shortcut first-keystroke="shift alt F7" keymap="$default"/>
          </action>
      </actions>
    • Workspace symbols
      <extensions defaultExtensionNs="com.intellij">
          <gotoSymbolContributor implementation="org.wso2.lsp4intellij.contributors.symbol.LSPSymbolContributor"
                                        id="LSPSymbolContributor"/>
      </extensions>
    • Renaming Support
      <extensions defaultExtensionNs="com.intellij">
          <renameHandler implementation="org.wso2.lsp4intellij.contributors.rename.LSPRenameHandler" 
          id="LSPRenameHandler" order="first"/>
          <renamePsiElementProcessor implementation="org.wso2.lsp4intellij.contributors.rename
           .LSPRenameProcessor" id="LSPRenameProcessor" order="first"/>
      </extensions>
    • Signature Help
      <extensions defaultExtensionNs="com.intellij">
          <typedHandler implementation="org.wso2.lsp4intellij.listeners.LSPTypedHandler"
                        id="LSPTypedHandler"/>
      </extensions>

Note: You do not need any additional configurations for the other features.

Copy the example plugin.xml here and place it under src/resources/META-INF in your plugin and adjust it to your needs.

3. Add a preloading activity to configure LSP

Implement a preloading activity in your plugin as shown below.

Tip: For other options you can use instead of implementing a preloading activity, go to InteliJ Plugin initialization on startup to)

Example:

public class BallerinaPreloadingActivity extends PreloadingActivity {
    public void preload(ProgressIndicator indicator) {
        IntellijLanguageClient.addServerDefinition(new RawCommandServerDefinition("bal", new String[]{"path/to/launcher-script.sh"}));
    }
}

With plugin.xml containing;

<extensions defaultExtensionNs="com.intellij">
    <preloadingActivity implementation="io.ballerina.plugins.idea.preloading.BallerinaPreloadingActivity" 
                        id="io.ballerina.plugins.idea.preloading.BallerinaPreloadingActivity" />
</extensions>

If you have connected to your language server successfully, you will see a green icon at the bottom-right side of your IDE when opening a file that has a registered file extension as shown below.

Alternative ways to connect to a language server

Aside RawCommandServerDefinition there are several classes implementing LanguageServerDefinition.

You can use the following concrete class:

  • RawCommandServerDefinition(string fileExtension, string[] command)

    This definition can be used to start a language server using a command.

    • You can specify multiple extensions for a server by separating them with a comma (e.g., "ts,js").

    • If you want to bind your language server definition only with a specific set of files, you can use that specific file pattern as a regex expression instead of binding with the file extension (e.g., "application*.properties").

    Examples:

    Ballerina Language Server

    new RawCommandServerDefinition("bal", new String[]{"path/to/launcher-script.sh"});

    BSL Language Server

    String[] command = new String[]{"java","-jar","path/to/language-server.jar"};
    new RawCommandServerDefinition("bsl,os",command);
  • ProcessBuilderServerDefinition(string fileExtension, string[] command)

    This definition is an extended form of the RawCommandServerDefinition, which accepts java.lang.ProcessBuilder instances so that the users will have more controllability over the language server process to be created.

    • You can specify multiple extensions for a server by separating them with a comma (e.g., "ts,js").

    • If you want to bind your language server definition only with a specific set of files, you can use that specific file pattern as a regex expression instead of binding with the file extension (e.g., "application*.properties").

    Examples:

    Ballerina Language Server

    ProcessBuilder process = new ProcessBuilder("path/to/launcher-script.sh");
    new ProcessBuilderServerDefinition("bal", process);

    BSL Language Server

    ProcessBuilder process = new ProcessBuilder("java","-jar","path/to/language-server.jar");
    new ProcessBuilderServerDefinition("bsl,os", process);
  • Custom Initialization Params

    If your LSP server needs some custom initialization options when connecting, you can define a class that extends ProcessBuilderServerDefinition or RawCommandServerDefinition, and then override the customizeInitializeParams method to modify any property of the InitializeParams.

    Here's an example:

    public class MyServerDefinition extends ProcessBuilderServerDefinition {
        public MyServerDefinition(String ext, ProcessBuilder process) {
            super(ext, process);
        }
    
        @Override
        public void customizeInitializeParams(InitializeParams params) {
            params.clientInfo = new ClientInfo("MyName", "MyVersion");
        }
    }

    Finally, assign your class as a ServerDefinition:

    ProcessBuilder process = new ProcessBuilder("path/to/launcher-script.sh");
    IntellijLanguageClient.addServerDefinition(new MyServerDefinition("xxx", processBuilder));

    You can refer to #311 for more details.

Note: All of the above implementations will use server stdin/stdout to communicate.

Tip: You can also click on the icon to see the connected files and the timeouts.

Features

Code Completion (with code snippet support)

Press the CTRL+SPACE keys to see the completion items list, which depends on your cursor position.(Code completion items will also pop-up auytomatically based on your language-server-specific trigger characters.)

For Code Snippets, you can use TAB/ENTER to navigate to the next place holder position or ESC to apply the code snippets with the default values.

Code Formatting

Navigate to Code->Reformat Code and you will get a dialog to choose whether to format the whole file or the selected range.

Diagnostics

To see diagnostics (errors, warnings etc.), hover over them to view the message.

Code Actions

Hover over any diagnostic highlight to view and apply related code actions using the light bulb that pops up as shown below.

Go to Definition

You can use CTRL+CLICK(COMMAND+CLICK in MacOS) to navigate to its definition.

Goto References / Find Usages

You can use CTRL+CLICK(COMMAND+CLICK in MacOS) or SHIFT+ALT+F7 for a symbol to view the list of its references/usages.

Hover Support

You can hover over an element while pressing the CTRL(COMMAND in MacOS) key to view its documentation if available.

Workspace Symbols

Click Navigate in the top menu, then click Symbol..., and enter the name of the symbol you want to search in the search box that pops up.

Renaming Support

Set the courser to the element which needs to renamed and press SHIFT+F6 to trigger the in-place renaming as shown below.

Note - Above features are currently tested only with IntelliJ IDEA and the Ballerina Language Server.

WIP Features

  • Signature Help

User API

Timeouts

The Lsp4IntelliJ language client has default timeout values for LSP-based requests as shown below.

Type Default timeout value(in milliseconds)
Code Actions 2000
Completion 1000
Goto Definition 2000
Execute Command 2000
Formatting 2000
Hover Support 2000
Initialization 10000
References 2000
Shutdown 5000
WillSave 2000

The LspIntelliJ language client provides following methods related to timeout configurations.

  • getTimeouts() - Returns the current timeout values (in milliseconds).

    Example:

    Map<Timeouts, Integer> timeouts = IntelliJLnaguageClient.getTimeouts();
  • getTimeout(Timeouts timeoutType) - Returns the current timeout value of a given timeout type (in milliseconds).

    Example

    int timeout = IntellijLanguageClient.getTimeout(Timeouts.INIT);
  • setTimeouts(Map<Timeouts, Integer> newTimeouts)) - Overrides the default timeout values with a given set of timeout values.

    Example

    Map<Timeouts,Integer> newTimeouts = new HashMap<>();
    newTimeouts.put(Timeouts.INIT,15000);
    newTimeouts.put(Timeouts.COMPLETION,1000);
    IntellijLanguageClient.setTimeouts(newTimeouts);
  • setTimeout(Timeouts timeout, int value) - Overrides a specific timeout value with a new one.

    Example

    IntellijLanguageClient.setTimeout(Timeouts.INIT, 15000);

License

The LSP4Intellij code is distributed under the Apache license 2.0.

Inspiration

Lsp4IntelliJ is heavily inspired by the intellij-lsp plugin community. Credits should go to the original author for his astounding work.

Useful Links

More Repositories

1

ballerina-lang

The Ballerina Programming Language
Ballerina
3,286
star
2

ballerina-spec

Ballerina Language and Platform Specifications
HTML
171
star
3

ballerina-dev-website

Dev version of the ballerina.io website
HTML
163
star
4

module-ballerina-graphql

The Ballerina GraphQL module is part of the Ballerina Standard Library. It is a spec-compliant, production-ready GraphQL implementation for writing GraphQL APIs in Ballerina.
Ballerina
144
star
5

nballerina

Ballerina compiler that generates native executables.
Ballerina
142
star
6

ballerina-library

The Ballerina Library
Ballerina
137
star
7

module-ballerina-jwt

Ballerina JWT module.
Ballerina
130
star
8

openapi-tools

Ballerina OpenApi-Tool
Java
129
star
9

module-ballerina-grpc

Ballerina gRPC Module
Ballerina
128
star
10

ballerina-release

Ballerina release scripts
Python
126
star
11

openapi-connectors

Generate Ballerina connector with OpenAPI definition
Ballerina
126
star
12

module-ballerina-http

Ballerina HTTP Module
Java
124
star
13

module-ballerinax-nats

Ballerina NATS Module.
Ballerina
124
star
14

ballerina-platform.github.io

ballerina-platform.github.io - Github pages based ballerina.io website
HTML
124
star
15

ballerina-action

Dockerfile
124
star
16

module-ballerina-io

Ballerina io Module
Ballerina
123
star
17

module-ballerina-tcp

Ballerina socket module
Java
122
star
18

module-ballerina-oauth2

Ballerina OAuth2 Module
Ballerina
122
star
19

module-ballerina-websocket

Ballerina WebSocket Module
Java
121
star
20

module-ballerina-websub

Ballerina Websub module.
Ballerina
120
star
21

module-ballerina-mime

Ballerina MIME Module
Java
119
star
22

plugin-intellij

Ballerina extension for IntelliJ IDEA.
Java
119
star
23

module-ballerinax-mysql

Ballerina mysql Module
Ballerina
119
star
24

module-ballerina-auth

Ballerina Auth Module
Java
119
star
25

module-ballerina-sql

Ballerina SQL Module
Java
119
star
26

module-ballerina-email

Ballerina module to send and receive emails
Java
119
star
27

module-ballerinax-kafka

Ballerina Kafka Module.
Ballerina
119
star
28

module-ballerina-udp

Ballerina UDP module enables transport layer communication over UDP protocol.
Java
118
star
29

module-ballerinax-java.jdbc

Ballerina JDBC Module
Ballerina
118
star
30

module-ballerina-cache

Ballerina cache Module
Ballerina
118
star
31

module-ballerina-log

Ballerina log Module
Ballerina
118
star
32

module-ballerina-c2c

Ballerina Code2Cloud implementation
Java
118
star
33

module-ballerinax-slack

Ballerina slack module
Ballerina
118
star
34

module-ballerinax-azure-cosmosdb

Ballerina
118
star
35

plugin-vscode-compiler-toolkit

Compiler tools for Ballerina developers
TypeScript
118
star
36

ballerina-dev-tools

Ballerina Developer Tooling
Java
118
star
37

module-ballerinax-stan

Ballerina NATS Streaming Module.
Java
117
star
38

module-ballerina-crypto

Ballerina crypto Module
Ballerina
117
star
39

module-ballerina-websubhub

This modules includes a bunch of APIs to facilitate writing different WebSub Hub implementations
Ballerina
116
star
40

module-ballerinax-googleapis.calendar

Connector repository for Google Calendar API.
Ballerina
116
star
41

module-ballerina-xmldata

Ballerina xml utils Module
Ballerina
116
star
42

module-ballerinax-postgresql

Ballerina PostgreSQL DB module
Ballerina
116
star
43

module-ballerinax-java.jms

Ballerina
116
star
44

module-ballerina-file

Ballerina File Module
Ballerina
116
star
45

module-ballerinax-azure-service-bus

Ballerina
116
star
46

module-ballerinax-aws.dynamodb

This is to keep the Amazon DynamoDB connector for Ballerina.
Ballerina
116
star
47

module-ballerinax-aws.s3

Ballerina
116
star
48

module-ballerina-task

Ballerina task Module
Java
116
star
49

module-ballerina-time

Ballerina time Module
Ballerina
116
star
50

module-ballerinax-azure.functions

The implementation of Azure Functions compiler extension for Ballerina.
Java
116
star
51

module-ballerinax-datamapper

A compiler extension to extract abstract representation of Ballerina connector actions and their associated types
Java
116
star
52

module-ballerina-uuid

Ballerina UUID Module
Ballerina
116
star
53

module-ballerinax-netsuite

The Ballerina connector to perform operations on Netsuite integrate cloud system.
Ballerina
116
star
54

module-ballerinax-twitter

This repo is to keep Ballerina Twitter connector implementation for Ballerina
Ballerina
116
star
55

ballerina-update-tool

Ballerina Update Tool implementation to manage Ballerina versions
Java
116
star
56

module-ballerinax-ai.agent

Ballerina ReAct type Agent module using Large language models (LLMs)
Ballerina
115
star
57

module-ballerina-os

Ballerina system Module
Java
115
star
58

module-ballerinax-jaeger

Ballerina Jaeger Observability Extension Module
Java
115
star
59

module-ballerinax-aws.sqs

Ballerina
115
star
60

module-ballerinax-mssql

Ballerina MSSQL DB module
Ballerina
115
star
61

module-ballerinax-aws.lambda

Java
115
star
62

module-ballerina-serdes

This is the Ballerina SerDes package, which is a part of the Ballerina Language Standard Library
Java
115
star
63

module-ballerinax-oracledb

Oracle Database Connector for Ballerina
Ballerina
115
star
64

module-ballerina-xslt

Ballerina xslt module
Java
115
star
65

module-ballerina-url

Ballerina encoding module.
Ballerina
115
star
66

module-ballerinax-rabbitmq

Ballerina RabbitMQ Module.
Ballerina
115
star
67

module-ballerinax-prometheus

Ballerina Prometheus Observability Extension Module
Java
115
star
68

module-ballerinai-transaction

Ballerina internal module of transaction implementation
Ballerina
115
star
69

module-ballerinax-mysql.driver

Ballerina Azure MySQL Module
Ballerina
115
star
70

module-ballerinax-azure-storage-service

Ballerina
115
star
71

graphql-tools

Maintain the source code for GraphQL related tools.
Java
115
star
72

module-ballerina-jballerina.java.arrays

Ballerina Java Array Module
Ballerina
114
star
73

module-ballerina-constraint

Ballerina Constraint Module
Ballerina
114
star
74

module-ballerinax-choreo

Ballerina Choreo Observability Extension Module
Java
114
star
75

ballerina-performance-cloud

Ballerina Performance Tests in Cloud
Shell
114
star
76

module-ballerinax-azure.eventhub

Azure Eventhub connector
Ballerina
114
star
77

module-ballerina-regex

Ballerina Regex Module
Ballerina
114
star
78

plugin-gradle

Ballerina Gradle plugin
Groovy
114
star
79

module-ballerinax-mssql.driver

Ballerina MSSQL DB Driver
Ballerina
114
star
80

module-ballerina-random

Ballerina Random Library
Ballerina
114
star
81

module-ballerinax-health.fhir.templates

FHIR Ballerina templates
Ballerina
114
star
82

module-ballerinax-persist.sql

SQL database support of Ballerina Persist
Ballerina
114
star
83

module-ballerinax-microsoft.onedrive

The Ballerina connector to perform operations on the files, which is stored on OneDrive
Ballerina
114
star
84

ballerina-custom-jre

Generates platform-specific custom Java runtime images to be bundled with Ballerina platform distributions, which contains only the required modules for Ballerina runtime.
114
star
85

asyncapi-tools

This repository is the code base for the ballerina async-api tool
Java
114
star
86

persist-tools

Ballerina persist tools
Ballerina
113
star
87

module-ballerinax-cdata.connect

Manage Ballerina CData connector modules centrally.
Java
113
star
88

module-ballerina-persist

Ballerina Persist module
Java
113
star
89

module-ballerinax-peoplehr

Ballerina connector for People HR
Ballerina
113
star
90

module-ballerinax-aws.ses

The Ballerina connector to perform operations on Amazon Simple Email Service(Amazon SES).
Ballerina
113
star
91

module-ballerinax-googleapis.people

Repository for Google People API Connector
Ballerina
113
star
92

module-ballerinax-microsoft.teams

The Ballerina Microsoft Teams Connector for teamwork and intelligent communications.
Ballerina
113
star
93

module-ballerinax-googleapis.drive

Repository for Google Drive module.
Ballerina
113
star
94

module-ballerinax-microsoft.excel

The Ballerina connector to perform operations on Excel workbooks stored in Microsoft OneDrive.
Ballerina
113
star
95

asyncapi-triggers

This repo will contain the trigger source code generated through ballerina async api tool
Ballerina
113
star
96

module-ballerinax-aws.simpledb

This is to keep the Amazon SimpleDB connector for Ballerina.
Ballerina
112
star
97

module-ballerinax-aws.sns

This repo is to keep the newly written Amazon SNS connector for Ballerina.
Ballerina
112
star
98

module-ballerina-toml

Ballerina TOML Parser
Ballerina
112
star
99

edi-tools

This library provides the functionality required to process EDI files and implement EDI integrations.
Ballerina
112
star
100

module-ballerinax-health.fhir.r4

FHIR R4 Ballerina modules
Ballerina
112
star