diff --git a/README.md b/README.md index 038cb87..12b3aa3 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,47 @@ If using the `language-server.js` distribution, it is necessary to retain the en Communication with the language server typically happens over stdio with `--stdio`. The `language-server.js` distribution additionally supports Node IPC with `--node-ipc`. +## Agent Client Protocol (ACP) (Preview) + +The Copilot Language Server also supports the [Agent Client Protocol (ACP)](https://agentclientprotocol.com/), +enabling integration with ACP-compatible editors like [JetBrains AI Assistant](https://www.jetbrains.com/help/ai-assistant/acp.html), [Zed](https://zed.dev/), and more. + +### Running in ACP Mode + +To start the language server in ACP mode: + +```sh +npx -y @github/copilot-language-server --acp +``` + +Or if installed locally: + +```sh +node ./node_modules/@github/copilot-language-server/dist/language-server.js --acp +``` + +Communication happens over stdin/stdout. + +### JetBrains AI Assistant + +To use Copilot as an ACP agent in JetBrains AI Assistant, add the following to your `~/.jetbrains/acp.json`: + +```json +{ + "agent_servers": { + "GitHub Copilot": { + "command": "npx", + "args": [ + "@github/copilot-language-server@latest", + "--acp" + ] + } + } +} +``` + +See the [ACP specification](https://agentclientprotocol.com/) for full protocol details. + ## Communication Protocol The [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) (LSP) is used to communicate with @@ -154,12 +195,14 @@ status bar icon or other UI affordance. Notification includes the following fields: +- `busy` - boolean indicating whether a task is in progress - `message` - a string describing the status (can be empty) - `kind` - status of the language server: - `'Normal'` - When everything is working normally. - `'Error'` - When not authorized and authenticated. - `'Warning'` - When there is a temporary issue, such as a failed HTTP request. - `'Inactive'` - When the current file is ignored due to file size or content exclusions. +- `command` - an optional LSP `Command` object providing an actionable command for the client to offer the user (e.g., sign in, learn more about quota limits) ## Authentication @@ -279,6 +322,73 @@ item, plus the length (in UTF-16 codepoints) of the completion that was accepted Note that the `acceptedLength` includes everything from the start of `insertText` to the end of the accepted text. It is *not* the length of the accepted text itself. +## Next Edit Suggestions + +`textDocument/copilotInlineEdit` is a custom method used to retrieve "next edit" +suggestions which are inline completions that may include deletions or +modifications to existing text and may not be positioned at the cursor. These +are similar to inline completions and the API shape is similar as well. But it +is a separate method to allow opting into the feature and distinguishing between +the two kinds of suggestions. + +The request parameters are similar to +[`TextDocumentPositionParams`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocumentPositionParams) +but with a `textDocument.version` field required as in as +[`VersionedTextDocumentIdentifier`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#versionedTextDocumentIdentifier): + +```json +{ + "textDocument": { + "uri": "file:///path/to/file", + "version": 0 + }, + "position": {"line": 1, "character": 2} +} +``` + +The result is an object containing an `edits` array: + +```json +{ + "edits": [ + { + "text": "an edit suggestion", + "textDocument": { + "uri": "file:///path/to/file", + "version": 0 + }, + "range": { + "start": {"line": 1, "character": 0}, + "end": {"line": 1, "character": 5} + }, + "command": { + "title": "Accept inline edit", + "command": "github.copilot.didAcceptCompletionItem", + "arguments": ["some-id"] + } + } + ] +} +``` + +The `command` field, per the LSP spec, is called via +[`workspace/executeCommand`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_executeCommand) +*after* the user accepts the edit. Copilot uses this for acceptance telemetry. + +The LSP spec does not provide an event for showing the edit, so a custom +`textDocument/didShowInlineEdit` is used. Call it with an `item` parameter +containing the item shown from the `edits` array (note only the first argument is required): + +```json +{ + "item": { + "command": { + "arguments": ["some-id"] + } + } +} +``` + ## Panel Completions Panel completions are used for "Open Copilot" style completions. They are similar to inline completions, but are shown