github-copilot-cli: add lsp server support

This commit is contained in:
Austin Horstman 2026-05-01 12:17:18 -05:00
parent feda41500e
commit edf3f59954
5 changed files with 140 additions and 1 deletions

View file

@ -0,0 +1,12 @@
{ config, ... }:
{
time = "2026-05-01T17:00:00+00:00";
condition = config.programs.github-copilot-cli.enable;
message = ''
The `programs.github-copilot-cli.lspServers` option has been added.
This option manages the `lsp-config.json` file under `COPILOT_HOME`,
allowing GitHub Copilot CLI to start configured language servers for code
intelligence features.
'';
}

View file

@ -74,7 +74,8 @@ in
example = literalExpression ''"''${config.xdg.configHome}/copilot"'';
description = ''
Directory holding Copilot CLI configuration files such as
{file}`config.json`, {file}`mcp-config.json`, and
{file}`config.json`, {file}`mcp-config.json`,
{file}`lsp-config.json`, and
{file}`copilot-instructions.md`.
Defaults to `''${config.xdg.configHome}/copilot` when
@ -201,6 +202,55 @@ in
'';
};
lspServers = mkOption {
type = lib.types.attrsOf jsonFormat.type;
default = { };
example = literalExpression ''
{
typescript = {
command = "typescript-language-server";
args = [ "--stdio" ];
fileExtensions = {
".ts" = "typescript";
".tsx" = "typescriptreact";
".js" = "javascript";
".jsx" = "javascriptreact";
};
};
python = {
command = lib.getExe' pkgs.pyright "pyright-langserver";
args = [ "--stdio" ];
fileExtensions = {
".py" = "python";
".pyw" = "python";
".pyi" = "python";
};
};
}
'';
description = ''
LSP (Language Server Protocol) server configurations written to
{file}`lsp-config.json` inside
{option}`programs.github-copilot-cli.configDir`.
Each attribute defines a server entry under `lspServers` in the config
file. Supported fields include:
- `command` command used to start the LSP server
- `args` arguments passed to the command
- `fileExtensions` map of file extensions to language IDs
- `env` environment variables for the server process
- `rootUri` server root directory relative to the Git root
- `initializationOptions` custom startup options
- `requestTimeoutMs` request timeout in milliseconds
Language server packages are not installed automatically. Add them to
{option}`home.packages` when needed.
See <https://docs.github.com/en/copilot/how-tos/copilot-cli/customize-copilot/add-lsp-servers>
for the documentation.
'';
};
agents = mkOption {
type = lib.types.either (lib.types.attrsOf (
lib.types.oneOf [
@ -324,6 +374,12 @@ in
};
};
"${cfg.configDir}/lsp-config.json" = mkIf (cfg.lspServers != { }) {
source = jsonFormat.generate "github-copilot-cli-lsp-config.json" {
inherit (cfg) lspServers;
};
};
"${cfg.configDir}/copilot-instructions.md" =
if isPathLikeContent cfg.context then
{ source = cfg.context; }

View file

@ -1,6 +1,7 @@
{
github-copilot-cli-config = ./config.nix;
github-copilot-cli-directories = ./directories.nix;
github-copilot-cli-lsp = ./lsp.nix;
github-copilot-cli-mcp = ./mcp.nix;
github-copilot-cli-mcp-integration = ./mcp-integration.nix;
github-copilot-cli-path-not-directory = ./path-not-directory.nix;

View file

@ -0,0 +1,32 @@
{
"lspServers": {
"python": {
"args": [
"--stdio"
],
"command": "pyright-langserver",
"env": {
"PYTHONPATH": "${PYTHONPATH:-}"
},
"fileExtensions": {
".py": "python",
".pyi": "python",
".pyw": "python"
},
"requestTimeoutMs": 120000,
"rootUri": "backend"
},
"typescript": {
"args": [
"--stdio"
],
"command": "typescript-language-server",
"fileExtensions": {
".js": "javascript",
".jsx": "javascriptreact",
".ts": "typescript",
".tsx": "typescriptreact"
}
}
}
}

View file

@ -0,0 +1,38 @@
{
programs.github-copilot-cli = {
enable = true;
lspServers = {
typescript = {
command = "typescript-language-server";
args = [ "--stdio" ];
fileExtensions = {
".ts" = "typescript";
".tsx" = "typescriptreact";
".js" = "javascript";
".jsx" = "javascriptreact";
};
};
python = {
command = "pyright-langserver";
args = [ "--stdio" ];
fileExtensions = {
".py" = "python";
".pyw" = "python";
".pyi" = "python";
};
env = {
PYTHONPATH = "\${PYTHONPATH:-}";
};
rootUri = "backend";
requestTimeoutMs = 120000;
};
};
};
nmt.script = ''
assertFileExists home-files/.copilot/lsp-config.json
assertFileContent home-files/.copilot/lsp-config.json ${./expected-lsp-config.json}
assertPathNotExists home-files/.copilot/config.json
assertPathNotExists home-files/.copilot/mcp-config.json
'';
}