| title | Adding LSP servers for {% data variables.copilot.copilot_cli %} | ||
|---|---|---|---|
| shortTitle | Add LSP servers | ||
| intro | You can add LSP servers to give {% data variables.copilot.copilot_cli_short %} precise code intelligence, improving its ability to navigate definitions, find references, and rename symbols. | ||
| versions |
|
||
| contentType | how-tos | ||
| docsTeamMetrics |
|
||
| category |
|
This article explains how to add LSP servers for {% data variables.copilot.copilot_cli_short %}. For conceptual information about LSP servers, see AUTOTITLE.
Adding an LSP server for {% data variables.copilot.copilot_cli_short %} is a two-step process:
- Install the LSP server software on your local machine.
- Configure the server in a configuration file.
These steps are described in detail in this article.
You can add an LSP server for a specific language by either:
- Using the
lsp-setupskill, which automates the process. - Manually installing the server software and then configuring {% data variables.copilot.copilot_cli_short %} to use the server.
These two approaches are described in the sections below.
The lsp-setup skill from the "Awesome {% data variables.product.prodname_copilot %}" repository automates the installation and configuration of a selection of popular languages.
-
Go to the "Awesome {% data variables.product.prodname_copilot %}" download site and search for "lsp":
-
Download the
lsp-setupskill. -
Unzip the downloaded
.zipfile to create a directory calledlsp-setup. -
Move the
lsp-setupdirectory into either:- Your personal skills directory:
~/.copilot/skills/. - A project skills directory:
.github/skills/in a Git repository.
- Your personal skills directory:
-
Start {% data variables.copilot.copilot_cli_short %}, or if you are currently in a CLI session enter
/skills reload. -
Enter the prompt:
setup lsp -
Follow the on-screen instructions to select the language for the server you want to set up, then complete the additional steps.
-
When the process is complete, enter
/lsp reloadto load the new LSP server. -
Check that the server has been added and is working correctly. See Confirming that an LSP server is available later in this article.
Installing an LSP server for a specific language typically involves installing a package via a package manager such as npm, gem, or pip.
To manually install an LSP server, refer to the documentation for the specific language server you want to install. Listed below are some example commands for installing popular LSP servers.
Note
Useful resources for finding LSP servers for different languages include:
- Implementations on Microsoft's Language Server Protocol website.
- Language Server Protocol on the Arch Linux website.
Caution
Only install LSP servers from sources you trust.
If you have Node.js installed, you can install the typescript-language-server LSP server with the following command:
npm install -g typescript typescript-language-serverThe typescript-language-server LSP server supports both TypeScript and JavaScript.
If you have gem installed, you can install the ruby-lsp LSP server with the following command:
gem install ruby-lspAlternatively, you can install the solargraph LSP server for Ruby with:
gem install solargraphIf you have Node.js installed, you can install the pyright LSP server with the following command:
npm install -g pyrightAlternatively, if you have pip installed, you can install the python-lsp-server LSP server with:
pip install python-lsp-server-
To configure the LSP server, add a server definition to either of the two configuration files:
- User configuration:
~/.copilot/lsp-config.jsonapplies to all your projects. - Project configuration:
.github/lsp.json, in your repository, applies to everyone working on that project.
Both files use the same JSON syntax:
{ "lspServers": { "SERVER-NAME": { "command": "COMMAND", "args": ["ARG1", "ARG2"], "fileExtensions": { ".EXT": "LANGUAGE-ID" } }, "ANOTHER-SERVER": { ... } } }Some examples of server definitions for specific LSP servers are provided later in this article.
- User configuration:
-
After installing and configuring the server, confirm that {% data variables.copilot.copilot_cli_short %} can use it. See Confirming that an LSP server is available below.
Each server definition in the configuration file must have a unique name and contain only alphanumeric characters, underscores, and hyphens.
Within each server definition, the following fields are available/required:
| Field | Required | Description |
|---|---|---|
command |
Yes | The command used to start the LSP server. |
args |
No | Arguments to pass to the command. |
fileExtensions |
Yes | A JSON map of file extensions and their corresponding language ID (for example, { ".rs": "rust" }). |
env |
No | Environment variables to set when starting the server. Supports ${VAR} and ${VAR:-default} expansion syntax. |
rootUri |
No | The root directory for the LSP server, relative to the Git root. Defaults to ".". Useful for monorepos. If your project lives in a subdirectory of the Git repository rather than the repository root, set rootUri to that subdirectory path. |
initializationOptions |
No | Custom options sent to the server during startup. |
requestTimeoutMs |
No | The timeout for server requests in milliseconds (default: 90 seconds). |
{
"lspServers": {
"typescript": {
"command": "typescript-language-server",
"args": ["--stdio"],
"fileExtensions": {
".ts": "typescript",
".tsx": "typescriptreact",
".js": "javascript",
".jsx": "javascriptreact",
".mjs": "javascript",
".cjs": "javascript",
".mts": "typescript",
".cts": "typescript"
}
}
}
}{
"lspServers": {
"ruby": {
"command": "ruby-lsp",
"args": [],
"fileExtensions": {
".rb": "ruby",
".rbw": "ruby",
".rake": "ruby",
".gemspec": "ruby"
}
}
}
}{
"lspServers": {
"python": {
"command": "pyright-langserver",
"args": ["--stdio"],
"fileExtensions": {
".py": "python",
".pyw": "python",
".pyi": "python"
}
}
}
}You can list and manage your LSP servers in an interactive CLI session using the /lsp slash command:
| Slash command | Description |
|---|---|
/lsp or /lsp show |
Show the status of all configured LSP servers. |
/lsp test SERVER-NAME |
Test whether a server starts correctly. |
/lsp reload |
Reload LSP configurations from disk. |
/lsp help |
Show /lsp command information. |
-
In {% data variables.copilot.copilot_cli_short %}, confirm that the LSP server you chose is available by using the
/lspslash command. You will see output such as:● LSP Server Status: User-configured servers: • ruby: ruby-lsp (.rb, .rbw, .rake, .gemspec) • omnisharp: omnisharp (.cs) User config: /Users/username/.copilot/lsp-config.json
-
After adding and configuring an LSP server, start (or restart) {% data variables.copilot.copilot_cli_short %}.
-
Use the slash command:
/lsp test SERVER-NAMEto check that the LSP server is working correctly.{% data variables.copilot.copilot_cli_short %} attempts to start a temporary, standalone instance of the server and reports whether it was successful or if there were any errors. It then kills the temporary server process.