{"id":15134346,"url":"https://github.com/ballerina-platform/lsp4intellij","last_synced_at":"2025-05-15T12:04:14.538Z","repository":{"id":45571846,"uuid":"165000016","full_name":"ballerina-platform/lsp4intellij","owner":"ballerina-platform","description":"This language client library provides language server protocol support for IntelliJ IDEA and other Jetbrains IDEs.","archived":false,"fork":false,"pushed_at":"2025-04-02T05:59:49.000Z","size":3680,"stargazers_count":463,"open_issues_count":38,"forks_count":108,"subscribers_count":83,"default_branch":"master","last_synced_at":"2025-04-14T19:59:37.449Z","etag":null,"topics":["ballerina","intellij-idea","language-server","language-server-client","language-server-protocol","languageserver"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ballerina-platform.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-01-10T06:03:09.000Z","updated_at":"2025-04-11T02:21:55.000Z","dependencies_parsed_at":"2024-04-01T10:23:57.218Z","dependency_job_id":"b090d3da-ecab-4cbb-a132-a10f233cc50e","html_url":"https://github.com/ballerina-platform/lsp4intellij","commit_stats":{"total_commits":527,"total_committers":36,"mean_commits":14.63888888888889,"dds":0.5199240986717267,"last_synced_commit":"b521dc8e6920df4ec05191e9c5302bbd0e479cff"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ballerina-platform%2Flsp4intellij","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ballerina-platform%2Flsp4intellij/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ballerina-platform%2Flsp4intellij/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ballerina-platform%2Flsp4intellij/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ballerina-platform","download_url":"https://codeload.github.com/ballerina-platform/lsp4intellij/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254337612,"owners_count":22054253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ballerina","intellij-idea","language-server","language-server-client","language-server-protocol","languageserver"],"created_at":"2024-09-26T05:04:38.665Z","updated_at":"2025-05-15T12:04:09.514Z","avatar_url":"https://github.com/ballerina-platform.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [LSP4IntelliJ](#lsp4intellij) - Language Server Protocol Support for JetBrains Plugins\n\n[![Build status](https://github.com/ballerina-platform/lsp4intellij/actions/workflows/build.yml/badge.svg)](https://github.com/ballerina-platform/lsp4intellij/actions/workflows/build.yml)\n[![](https://jitpack.io/v/ballerina-platform/lsp4intellij.svg)](https://jitpack.io/#ballerina-platform/lsp4intellij)\n[![GitHub last commit](https://img.shields.io/github/last-commit/ballerina-platform/lsp4intellij.svg)](https://github.com/ballerina-platform/lsp4intellij/commits/master)\n[![Gitter](https://badges.gitter.im/ballerina-platform-lsp4intellij/community.svg)](https://gitter.im/ballerina-platform-lsp4intellij/community?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\n\n**LSP4IntelliJ** is a client library that enables Language Server Protocol (LSP) support for IntelliJ IDEA and other JetBrains IDEs.\n\nDesigned for plugin developers, it facilitates integration with LSP-based features and supports language-specific extensions via the [JSON-RPC](https://en.wikipedia.org/wiki/JSON-RPC) protocol.\n\n---\n\n## Table of Contents\n\n- [How to Use](#how-to-use)\n- [Features](#features)\n    - [Code Completion](#code-completion-with-code-snippet-support)\n    - [Code Formatting](#code-formatting)\n    - [Diagnostics](#diagnostics)\n    - [Code Actions](#code-actions)\n    - [Goto Definition](#go-to-definition)\n    - [Goto References / Find Usages](#goto-references--find-usages)\n    - [Hover Support](#hover-support)\n    - [Workspace Symbols](#workspace-symbols)\n    - [Renaming Support](#renaming-support)\n- [User API](#user-api)\n    - [Timeouts](#timeouts)\n- [License](#license)\n- [Inspiration](#inspiration)\n- [Useful Links](#useful-links)\n\n---\n\n## How to use\n\nFollow the below steps to integrate `LSP4IntelliJ` into your custom language plugin.\n\n### 1. Add the `lsp4intellij` dependency\nInclude `lsp4intellij` in your project's build file. Instructions for popular build tools are available at [jitpack/lsp4intellij](https://jitpack.io/#ballerina-platform/lsp4intellij).\n\nSupported build tools:\n- Gradle\n- Maven\n- SBT\n\n\u003e **Info:** Maven Central publishing is a work in progress. Support for Maven Central will be available soon.\n\n### 2. Add a `plugin.xml` file\nDefine the required configurations in your `plugin.xml` file.\n\n\u003cdetails\u003e\n\u003csummary\u003edeprecated \"components\"-based setup\u003c/summary\u003e\n  1. Add `IntellijLanguageClient` as an application component. \n       ```xml\n       \u003capplication-components\u003e\n           \u003ccomponent\u003e\n               \u003cimplementation-class\u003eorg.wso2.lsp4intellij.IntellijLanguageClient\u003c/implementation-class\u003e\n           \u003c/component\u003e\n       \u003c/application-components\u003e\n       ```\n       \n  2. Add the following extensions to get the relevant features as listed below.\n  \n        - Code completion (You can replace the `language` attribute if you already have your own\n            [custom language implementations](https://www.jetbrains.org/intellij/sdk/docs/tutorials/custom_language_support/language_and_filetype.html#define-a-language))\n            ```xml\n            \u003cextensions defaultExtensionNs=\"com.intellij\"\u003e\n                \u003ccompletion.contributor implementationClass=\"org.wso2.lsp4intellij.contributors.LSPCompletionContributor\"\n                                        id=\"LSPCompletionContributor\" language=\"any\"/\u003e\n            \u003c/extensions\u003e\n            ```\n        - Code Formatting\n            ```xml\n            \u003cactions\u003e\n               \u003caction class=\"org.wso2.lsp4intellij.actions.LSPReformatAction\" id=\"ReformatCode\" use-shortcut-of=\"ReformatCode\"\n                       overrides=\"true\" text=\"Reformat Code\"/\u003e\n               \u003caction class=\"org.wso2.lsp4intellij.actions.LSPShowReformatDialogAction\" id=\"ShowReformatFileDialog\"\n                       use-shortcut-of=\"ShowReformatFileDialog\" overrides=\"true\" text=\"Show Reformat File Dialog\"/\u003e\n            \u003c/actions\u003e\n            ```\n        - Diagnostics and code actions (You can replace the `language` attribute if you already have your own\n          [custom language implementations](https://www.jetbrains.org/intellij/sdk/docs/tutorials/custom_language_support/language_and_filetype.html#define-a-language))\n            ```xml\n            \u003cextensions defaultExtensionNs=\"com.intellij\"\u003e\n               \u003cexternalAnnotator id=\"LSPAnnotator\" language=\"TEXT\" implementationClass=\"org.wso2.lsp4intellij.contributors.annotator.LSPAnnotator\"/\u003e\n            \u003c/extensions\u003e\n            ```\n        - Find Usages \n            ```xml\n            \u003cactions\u003e\n                \u003caction class=\"org.wso2.lsp4intellij.actions.LSPReferencesAction\" id=\"LSPFindUsages\"\u003e\n                     \u003ckeyboard-shortcut first-keystroke=\"shift alt F7\" keymap=\"$default\"/\u003e\n                \u003c/action\u003e\n            \u003c/actions\u003e\n            ```\n        - Workspace symbols\n            ```xml\n            \u003cextensions defaultExtensionNs=\"com.intellij\"\u003e\n                \u003cgotoSymbolContributor implementation=\"org.wso2.lsp4intellij.contributors.symbol.LSPSymbolContributor\"\n                                              id=\"LSPSymbolContributor\"/\u003e\n            \u003c/extensions\u003e\n            ```\n        - Renaming Support \n            ```xml\n            \u003cextensions defaultExtensionNs=\"com.intellij\"\u003e\n                \u003crenameHandler implementation=\"org.wso2.lsp4intellij.contributors.rename.LSPRenameHandler\" \n                id=\"LSPRenameHandler\" order=\"first\"/\u003e\n                \u003crenamePsiElementProcessor implementation=\"org.wso2.lsp4intellij.contributors.rename\n                 .LSPRenameProcessor\" id=\"LSPRenameProcessor\" order=\"first\"/\u003e\n            \u003c/extensions\u003e\n            ```\n        - Signature Help\n            ```xml\n            \u003cextensions defaultExtensionNs=\"com.intellij\"\u003e\n                \u003ctypedHandler implementation=\"org.wso2.lsp4intellij.listeners.LSPTypedHandler\"\n                              id=\"LSPTypedHandler\"/\u003e\n            \u003c/extensions\u003e\n            ```\n        \n   \u003e **Note:** You do not need any additional configurations for the other features.\n\u003c/details\u003e\n\nCopy the example `plugin.xml` file from [resources/plugin.xml.example](resources/plugin.xml.example), place it under `src/resources/META-INF`, and adjust it as needed.\n\n### 3. Configure preloading activity\n\nAdd a preloading activity to initialize and configure LSP support:\n\n```java\npublic class BallerinaPreloadingActivity extends PreloadingActivity {\n    @Override\n    public void preload(ProgressIndicator indicator) {\n        IntellijLanguageClient.addServerDefinition(new RawCommandServerDefinition(\"bal\", new String[]{\"path/to/launcher-script.sh\"}));\n    }\n}\n```\n\nUpdate your `plugin.xml` to include the preloading activity:\n\n```xml\n\u003cextensions defaultExtensionNs=\"com.intellij\"\u003e\n    \u003cpreloadingActivity implementation=\"io.ballerina.plugins.idea.preloading.BallerinaPreloadingActivity\" \n                        id=\"io.ballerina.plugins.idea.preloading.BallerinaPreloadingActivity\" /\u003e\n\u003c/extensions\u003e\n```\n\n\u003e**Tip:** For other options you can use instead of implementing a preloading activity, go to [InteliJ Plugin initialization on startup](https://www.plugin-dev.com/intellij/general/plugin-initial-load/)\n\n### 4. Confirm language server connection\n\nAfter successfully connecting to the language server, a green icon will appear in the bottom-right corner of your IDE. Clicking on the icon will display connection details and timeouts.\n\n#### Alternative ways to connect to a language server\n\nIn addition to `RawCommandServerDefinition`, several classes implement [LanguageServerDefinition](src/main/java/org/wso2/lsp4intellij/client/languageserver/serverdefinition/LanguageServerDefinition.java), allowing you to connect to a language server in different ways. Below are the available options:\n\n##### 1. RawCommandServerDefinition\n\nYou can specify multiple extensions for a server by separating them with a comma (e.g., \"ts,js\").\n\nIf you want to bind your language server definition only with a specific set of files, you can use that\nspecific file pattern as a regex expression instead of binding with the file extension (e.g., \"application*.properties\").\n\n**Example Usage:**\n\n```java\nnew RawCommandServerDefinition(\"bal\", new String[]{\"path/to/launcher-script.sh\"});\n```\n\n```java\nString[] command = new String[]{\"java\", \"-jar\", \"path/to/language-server.jar\"};\nnew RawCommandServerDefinition(\"bsl,os\", command);\n```\n\n##### 2. ProcessBuilderServerDefinition\n\nThis definition is an extended form of the **RawCommandServerDefinition**, which accepts\n`java.lang.ProcessBuilder` instances so that the users will have more controllability over the language\nserver\nprocess to be created.\n\nYou can specify multiple extensions for a server by separating them with a comma (e.g., \"ts,js\").\n\nIf you want to bind your language server definition only with a specific set of files, you can use that\n      specific file pattern as a regex expression instead of binding with the file extension (e.g., \"application*.properties\").\n\n**Example Usage:**\n\n```java\nProcessBuilder process = new ProcessBuilder(\"path/to/launcher-script.sh\");\nnew ProcessBuilderServerDefinition(\"bal\", process);\n```\n\n```java\nProcessBuilder process = new ProcessBuilder(\"java\", \"-jar\", \"path/to/language-server.jar\");\nnew ProcessBuilderServerDefinition(\"bsl,os\", process);\n```\n\n#### Custom initialization parameters\n\nIf your language server requires custom initialization options, you can extend `ProcessBuilderServerDefinition` or `RawCommandServerDefinition` and override the `customizeInitializeParams` method to modify the initialization parameters.\n\n```java\npublic class MyServerDefinition extends ProcessBuilderServerDefinition {\n    public MyServerDefinition(String ext, ProcessBuilder process) {\n        super(ext, process);\n    }\n\n    @Override\n    public void customizeInitializeParams(InitializeParams params) {\n        params.clientInfo = new ClientInfo(\"MyName\", \"MyVersion\");\n    }\n}\n```\n\nFinally, assign your class as a ServerDefinition:\n\n```java\nProcessBuilder process = new ProcessBuilder(\"path/to/launcher-script.sh\");\nIntellijLanguageClient.addServerDefinition(new MyServerDefinition(\"xxx\", processBuilder));\n```\n\n  You can refer to [#311](https://github.com/ballerina-platform/lsp4intellij/pull/311) for more details.\n\n\n\u003e **Note:** All implementations use stdin/stdout for server communication.\n\n![](resources/images/lang-server-connect.gif)\n   \n\u003e**Tip:** A green icon in the IDE's bottom-right corner indicates successful connection to the language server. Clicking on the icon will display connection details and timeouts.\n\n![](resources/images/connected-and-timeouts.gif)\n   \n--- \n\n## Features\n\n#### Code Completion (with code snippet support)\nPress the `CTRL+SPACE` keys to see the completion items list, which depends on your cursor position.(Code completion items \nwill also pop-up automatically based on your language-server-specific trigger characters.)\n\n![](resources/images/lsp4intellij-completion.gif)\n\n\nFor Code Snippets, you can use TAB/ENTER to navigate to the next place holder position or ESC to apply the code\nsnippets with the default values.\n \n![](resources/images/lsp4intellij-snippets.gif)\n\n#### Code Formatting\nNavigate to **Code-\u003eReformat Code** and you will get a dialog to choose whether to format the whole file or the \nselected range.\n\n![](resources/images/lsp4intellij-formatting.gif)\n\n#### Diagnostics\nTo see diagnostics (errors, warnings etc.), hover over them to view the message.\n\n![](resources/images/lsp4intellij-dignostics.gif)\n\n#### Code Actions\nHover over any diagnostic highlight to view and apply related code actions using the light bulb that pops up as \nshown below.\n![](resources/images/lsp4intellij-codeactions.gif)  \n\n#### Go to Definition\nYou can use `CTRL+CLICK`(`COMMAND+CLICK` in MacOS) to navigate to its definition.\n \n![](resources/images/lsp4intellij-gotodef.gif)\n\n#### Goto References / Find Usages\nYou can use `CTRL+CLICK`(`COMMAND+CLICK` in MacOS) or `SHIFT+ALT+F7` for a symbol to view the list of its references/usages.\n \n![](resources/images/lsp4intellij-gotoref.gif)\n\n#### Hover Support\nYou can hover over an element while pressing the `CTRL`(`COMMAND` in MacOS) key to view its documentation if available.\n\n![](resources/images/lsp4intellij-hover.gif)\n\n#### Workspace Symbols\nClick **Navigate** in the top menu, then click **Symbol...**,  and enter the name of the symbol you want to search in the search box that \npops up.\n\n![](resources/images/lsp4intellij-workspacesymbols.gif)\n\n#### Renaming Support\nSet the courser to the element which needs to renamed and press `SHIFT+F6` to trigger the in-place renaming as shown\nbelow.\n\n![](resources/images/lsp4intellij-renaming.gif)\n\n\u003e **Note** - Above features are currently tested only with IntelliJ IDEA and\n\u003e the [Ballerina Language Server](https://github.com/ballerina-platform/ballerina-lang/tree/master/language-server).\n\n**WIP Features**\n- Signature Help\n \n---\n\n## User API\n\n### Timeouts\nThe Lsp4IntelliJ language client has default timeout values for LSP-based requests as shown below.\n\n| Type            | Default timeout value(in milliseconds) |\n|-----------------|:--------------------------------------:|\n| Code Actions    |                  2000                  |\n| Completion      |                  1000                  |\n| Goto Definition |                  2000                  |\n| Execute Command |                  2000                  |\n| Formatting      |                  2000                  |\n| Hover Support   |                  2000                  | \n| Initialization  |                 10000                  |\n| References      |                  2000                  |\n| Shutdown        |                  5000                  |\n| WillSave        |                  2000                  |\n\nThe LspIntelliJ language client provides following methods related to timeout configurations.\n\n- **getTimeouts()** - Returns the current timeout values (in milliseconds).\n\n    Example:\n    ```java\n    Map\u003cTimeouts, Integer\u003e timeouts = IntelliJLnaguageClient.getTimeouts();\n    ```\n\n- **getTimeout(Timeouts timeoutType)** - Returns the current timeout value of a given timeout type (in milliseconds).\n\n    Example\n    ```java\n    int timeout = IntellijLanguageClient.getTimeout(Timeouts.INIT);\n    ```\n\n- **setTimeouts(Map\u003cTimeouts, Integer\u003e newTimeouts))** - Overrides the default timeout values with a given set\n of timeout values.\n \n    Example\n    ```java\n    Map\u003cTimeouts,Integer\u003e newTimeouts = new HashMap\u003c\u003e();\n    newTimeouts.put(Timeouts.INIT,15000);\n    newTimeouts.put(Timeouts.COMPLETION,1000);\n    IntellijLanguageClient.setTimeouts(newTimeouts);\n    ```\n    \n- **setTimeout(Timeouts timeout, int value)** - Overrides a specific timeout value with a new one.\n \n    Example\n    ```java\n    IntellijLanguageClient.setTimeout(Timeouts.INIT, 15000);\n    ```\n\n---\n\n## License\n\nThe LSP4Intellij code is distributed under the [Apache license 2.0](LICENSE).\n\n\n## Inspiration\n\n`Lsp4IntelliJ` is heavily inspired by the [intellij-lsp](https://github.com/gtache/intellij-lsp) plugin community.\nCredits should go to the original author for his astounding work.\n\n\n## Contributors\n\nA huge thanks to all the amazing contributors! 🚀\n\n\u003ca href=\"https://github.com/ballerina-platform/lsp4intellij/pulse\"\u003e \u003cimg align=\"center\" src=\"https://contrib.rocks/image?max=100\u0026repo=ballerina-platform/lsp4intellij\" /\u003e \u003c/a\u003e \n\n\n## Useful links\n\n- [langserver.org](https://langserver.org/)\n- [Language Server Protocol Specification](https://microsoft.github.io/language-server-protocol/specification)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fballerina-platform%2Flsp4intellij","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fballerina-platform%2Flsp4intellij","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fballerina-platform%2Flsp4intellij/lists"}