Skip to content

Commit 4000fee

Browse files
committed
Merge branch 'master' into various_cleanups
2 parents c921e36 + 0d56d43 commit 4000fee

35 files changed

+302130
-53
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Update Copilot LSP
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *"
6+
push:
7+
branches: [master]
8+
9+
jobs:
10+
update_copilot_lsp:
11+
runs-on: ubuntu-latest
12+
name: Update Copilot LSP
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v3
16+
17+
- name: Create directory
18+
run: |
19+
mkdir -p copilot/js
20+
21+
- name: Download latest LSP
22+
run: |
23+
curl -s https://api.github.com/repos/github/copilot-language-server-release/releases/latest | grep "browser_download_url.*copilot-language-server-js-.*zip" | cut -d : -f 2,3 | tr -d \" | wget -vi -
24+
25+
- name: Unzip LSP
26+
run: |
27+
unzip -o copilot-language-server-js-*.zip -d copilot/js
28+
rm copilot-language-server-js-*.zip
29+
30+
- name: Create Pull Request
31+
uses: peter-evans/create-pull-request@v4
32+
with:
33+
add-paths: "copilot/js/*"
34+
author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
35+
base: master
36+
branch: create-pull-request/update-copilot-lsp
37+
commit-message: "feat: update to latest Copilot LSP"
38+
reviewers: MunifTanjim,zbirenbaum,AntoineGS
39+
title: "Update Copilot LSP"

README.md

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Note that if you have the variable set, even empty, the LSP will attempt to use
4949
You have to run the `require("copilot").setup(options)` function in order to start Copilot.
5050
If no options are provided, the defaults are used.
5151

52-
Because the copilot server takes some time to start up, it is recommend that you lazy load copilot.
52+
Because the copilot server takes some time to start up, it is recommended that you lazy load copilot.
5353
For example:
5454

5555
```lua
@@ -115,7 +115,7 @@ require('copilot').setup({
115115
trace_lsp_progress = false,
116116
log_lsp_messages = false,
117117
},
118-
copilot_node_command = 'node', -- Node.js version must be > 18.x
118+
copilot_node_command = 'node', -- Node.js version must be > 20
119119
workspace_folders = {},
120120
copilot_model = "", -- Current LSP default is gpt-35-turbo, supports gpt-4o-copilot
121121
root_dir = function()
@@ -134,6 +134,10 @@ require('copilot').setup({
134134

135135
return true
136136
end,
137+
server = {
138+
type = "nodejs", -- "nodejs" | "binary"
139+
custom_server_filepath = nil,
140+
},
137141
server_opts_overrides = {},
138142
})
139143
```
@@ -284,10 +288,20 @@ When `log_lsp_messages` is true, LSP log messages (`window/logMessage`) events w
284288

285289
Careful turning on all logging features as the log files may get very large over time, and are not pruned by the application.
286290

291+
### copilot_node_command
292+
293+
Use this field to provide the path to a specific node version such as one installed by nvm. Node.js version must be 20 or newer.
294+
295+
Example:
296+
297+
```lua
298+
copilot_node_command = vim.fn.expand("$HOME") .. "/.config/nvm/versions/node/v20.0.1/bin/node", -- Node.js version must be > 20
299+
```
300+
287301
### server_opts_overrides
288302

289303
Override copilot lsp client settings. The `settings` field is where you can set the values of the options defined in [SettingsOpts.md](./SettingsOpts.md).
290-
These options are specific to the copilot lsp and can be used to customize its behavior. Ensure that the name field is not overriden as is is used for
304+
These options are specific to the copilot lsp and can be used to customize its behavior. Ensure that the name field is not overridden as is is used for
291305
efficiency reasons in numerous checks to verify copilot is actually running. See `:h vim.lsp.start_client` for list of options.
292306

293307
Example:
@@ -331,7 +345,7 @@ If none is found, it will use the current working directory.
331345

332346
This function is called to determine if copilot should attach to the buffer or not.
333347
It is useful if you would like to go beyond the filetypes and have more control over when copilot should attach.
334-
You can also use it to attach to buflisted buffers by simply omiting that portion from the function.
348+
You can also use it to attach to buflisted buffers by simply omitting that portion from the function.
335349
Since this happens before attaching to the buffer, it is good to prevent Copilot from reading sensitive files.
336350

337351
An example of this would be:
@@ -348,6 +362,25 @@ require("copilot").setup {
348362
}
349363
```
350364

365+
### server
366+
367+
> [!CAUTION] > `"binary"` mode is still very much experimental, please report any issues you encounter.
368+
369+
`type` can be either `"nodejs"` or `"binary"`. The binary version will be downloaded if used.
370+
371+
`custom_server_filepath` is used to specify the path of either the path (filename included) of the `js` file if using `"nodejs"` or the path to the binary if using `"binary"`.
372+
When using `"binary"`, the download process will be disabled and the binary will be used directly.
373+
example:
374+
375+
```lua
376+
require("copilot").setup {
377+
server = {
378+
type = "nodejs",
379+
custom_server_filepath = "/home/user/copilot-lsp/language-server.js",,
380+
},
381+
}
382+
```
383+
351384
## Commands
352385

353386
`copilot.lua` defines the `:Copilot` command that can perform various actions. It has completion support, so try it out.
@@ -357,4 +390,6 @@ require("copilot").setup {
357390
The `copilot.api` module can be used to build integrations on top of `copilot.lua`.
358391

359392
- [zbirenbaum/copilot-cmp](https://github.com/zbirenbaum/copilot-cmp): Integration with [`nvim-cmp`](https://github.com/hrsh7th/nvim-cmp).
393+
- [giuxtaposition/blink-cmp-copilot](https://github.com/giuxtaposition/blink-cmp-copilot): Integration with [`blink.cmp`](https://github.com/Saghen/blink.cmp).
394+
- [fang2hou/blink-copilot](https://github.com/fang2hou/blink-copilot): Integration with [`blink.cmp`](https://github.com/Saghen/blink.cmp), with some differences.
360395
- [AndreM222/copilot-lualine](https://github.com/AndreM222/copilot-lualine): Integration with [`lualine.nvim`](https://github.com/nvim-lualine/lualine.nvim).

copilot/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
*
1+
copilot-language-server-*
22
!.gitignore
33
!package.json
4+

copilot/js/api/types.d.ts

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
import {
2+
CancellationToken,
3+
Disposable,
4+
DocumentSelector,
5+
DocumentUri,
6+
Position,
7+
TextEdit,
8+
} from 'vscode-languageserver-protocol';
9+
10+
/**
11+
* The ContextProvider API allows extensions to provide additional context items that
12+
* Copilot can use in its prompt. This file contains type definitions for the methods
13+
* and the data structures used by the API.
14+
*
15+
* Note: providing context is not enough to ensure that the context will be used in the prompt.
16+
*
17+
* The API is exposed as an export of the Copilot extension. To use it, you can cast the
18+
* exported object to the ContextProviderApiV1 interface.
19+
*
20+
* Example:
21+
* ```
22+
* const copilot = vscode.extensions.getExtension("github.copilot");
23+
* const contextProviderAPI = copilot.exports.getContextProviderAPI("v1") as ContextProviderApiV1;
24+
* ```
25+
*/
26+
export interface ContextProviderApiV1 {
27+
registerContextProvider<T extends SupportedContextItem>(provider: ContextProvider<T>): Disposable;
28+
}
29+
30+
/**
31+
* Each extension can register a number of context providers, uniquely identified by their ID.
32+
* In addition, each provider has to provide:
33+
* - a DocumentSelector, to specify the file types for which the provider is active
34+
* - a ContextResolver, a function that returns the context items for a given request
35+
*
36+
* Example:
37+
* ```
38+
* contextProviderAPI.registerContextProvider<Trait>({
39+
* id: "pythonProvider",
40+
* selector: [{ language: "python" }],
41+
* resolver: {
42+
* resolve: async (request, token) => {
43+
* return [{name: 'traitName', value: 'traitValue'}];
44+
* }
45+
* }
46+
* });
47+
* ```
48+
*/
49+
export interface ContextProvider<T extends SupportedContextItem> {
50+
id: string;
51+
selector: DocumentSelector;
52+
resolver: ContextResolver<T>;
53+
}
54+
export interface ContextResolver<T extends SupportedContextItem> {
55+
resolve(request: ResolveRequest, token: CancellationToken): Promise<T> | Promise<T[]> | AsyncIterable<T>;
56+
}
57+
58+
/**
59+
* The first argument of the resolve method is a ResolveRequest object, which informs
60+
* the provider about:
61+
* - the completionId, a unique identifier for the completion request
62+
* - the documentContext, which contains information about the document for which the context is requested
63+
* - the activeExperiments, a map of active experiments and their values
64+
* - the timeBudget the provider has to provide context items
65+
* - the previousUsageStatistics, which contains information about the last request to the provider
66+
*/
67+
export type ResolutionStatus = 'full' | 'partial' | 'none' | 'error';
68+
export type UsageStatus = ResolutionStatus | 'partial_content_excluded' | 'none_content_excluded';
69+
70+
export type ContextItemUsageDetails = {
71+
id: string;
72+
type: SupportedContextItemType;
73+
origin?: ContextItemOrigin;
74+
} & (
75+
| {
76+
usage: Extract<UsageStatus, 'full' | 'partial' | 'partial_content_excluded'>;
77+
expectedTokens: number;
78+
actualTokens: number;
79+
}
80+
| {usage: Extract<UsageStatus, 'none' | 'none_content_excluded' | 'error'>}
81+
);
82+
83+
export type ContextUsageStatistics = {
84+
usage: UsageStatus;
85+
resolution: ResolutionStatus;
86+
usageDetails?: ContextItemUsageDetails[];
87+
};
88+
89+
export interface DocumentContext {
90+
uri: DocumentUri;
91+
languageId: string;
92+
version: number;
93+
/**
94+
* @deprecated Use `position` instead.
95+
*/
96+
offset: number;
97+
position: Position;
98+
proposedEdits?: TextEdit[];
99+
}
100+
export interface ResolveRequest {
101+
// A unique ID to correlate the request with the completion request.
102+
completionId: string;
103+
documentContext: DocumentContext;
104+
105+
activeExperiments: Map<string, string | number | boolean | string[]>;
106+
107+
/**
108+
* The number of milliseconds for the context provider to provide context items.
109+
* After the time budget runs out, the request will be cancelled via the CancellationToken.
110+
* Providers can use this value as a hint when computing context. Providers should expect the
111+
* request to be cancelled once the time budget runs out.
112+
*/
113+
timeBudget: number;
114+
115+
/**
116+
* Various statistics about the last completion request. This can be used by the context provider
117+
* to make decisions about what context to provide for the current call.
118+
*/
119+
previousUsageStatistics?: ContextUsageStatistics;
120+
121+
/**
122+
* Data from completionItem
123+
*
124+
* See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItem
125+
*/
126+
data?: unknown;
127+
}
128+
129+
/**
130+
* These are the data types that can be provided by a context provider. Any non-conforming
131+
* context items will be filtered out.
132+
*/
133+
interface ContextItem {
134+
/**
135+
* Specifies the relative importance with respect to items of the same type.
136+
* Cross-type comparisons is currently handled by the wishlist.
137+
* Accepted values are integers in the range [0, 100], where 100 is the highest importance.
138+
* Items with non-conforming importance values will be filtered out.
139+
* Default value is 0.
140+
*/
141+
importance?: number;
142+
143+
/**
144+
* A unique ID for the context item, used to provide detailed statistics about
145+
* the item's usage. If an ID is not provided, it will be generated randomly.
146+
*/
147+
id?: string;
148+
149+
/**
150+
* Specifies where the context item comes from, mostly relevant for LSP providers.
151+
* - request: context is provided in the completion request
152+
* - update: context is provided via context/update
153+
*/
154+
origin?: ContextItemOrigin;
155+
}
156+
157+
// A key-value pair used for short string snippets.
158+
export interface Trait extends ContextItem {
159+
name: string;
160+
value: string;
161+
}
162+
163+
// Code snippet extracted from a file. The URI is used for content exclusion.
164+
export interface CodeSnippet extends ContextItem {
165+
uri: string;
166+
value: string;
167+
// Additional URIs that contribute the same code snippet.
168+
additionalUris?: string[];
169+
}
170+
171+
export type SupportedContextItem = Trait | CodeSnippet;
172+
export type SupportedContextItemType = 'Trait' | 'CodeSnippet';
173+
export type ContextItemOrigin = 'request' | 'update';
318 KB
Binary file not shown.
1.96 MB
Binary file not shown.
318 KB
Binary file not shown.
2.13 MB
Binary file not shown.
191 KB
Binary file not shown.
1.96 MB
Binary file not shown.

0 commit comments

Comments
 (0)