Skip to content

Commit ff9359d

Browse files
committed
Merge branch 'beta'
2 parents f7e800b + bb77143 commit ff9359d

40 files changed

+2184
-1401
lines changed

.github/workflows/update-copilot-dist.yaml

Lines changed: 0 additions & 37 deletions
This file was deleted.
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: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ require('copilot').setup({
110110
trace_lsp_progress = false,
111111
log_lsp_messages = false,
112112
},
113-
copilot_node_command = 'node', -- Node.js version must be > 18.x
113+
copilot_node_command = 'node', -- Node.js version must be > 20
114114
workspace_folders = {},
115115
copilot_model = "", -- Current LSP default is gpt-35-turbo, supports gpt-4o-copilot
116116
root_dir = function()
@@ -129,6 +129,10 @@ require('copilot').setup({
129129

130130
return true
131131
end,
132+
server = {
133+
type = "nodejs", -- "nodejs" | "binary"
134+
custom_server_filepath = nil,
135+
},
132136
server_opts_overrides = {},
133137
})
134138
```
@@ -281,12 +285,12 @@ Careful turning on all logging features as the log files may get very large over
281285

282286
### copilot_node_command
283287

284-
Use this field to provide the path to a specific node version such as one installed by nvm. Node.js version must be 18.x or newer.
288+
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.
285289

286290
Example:
287291

288292
```lua
289-
copilot_node_command = vim.fn.expand("$HOME") .. "/.config/nvm/versions/node/v18.18.2/bin/node", -- Node.js version must be > 18.x
293+
copilot_node_command = vim.fn.expand("$HOME") .. "/.config/nvm/versions/node/v20.0.1/bin/node", -- Node.js version must be > 20
290294
```
291295

292296
### server_opts_overrides
@@ -353,6 +357,25 @@ require("copilot").setup {
353357
}
354358
```
355359

360+
### server
361+
362+
> [!CAUTION] > `"binary"` mode is still very much experimental, please report any issues you encounter.
363+
364+
`type` can be either `"nodejs"` or `"binary"`. The binary version will be downloaded if used.
365+
366+
`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"`.
367+
When using `"binary"`, the download process will be disabled and the binary will be used directly.
368+
example:
369+
370+
```lua
371+
require("copilot").setup {
372+
server = {
373+
type = "nodejs",
374+
custom_server_filepath = "/home/user/copilot-lsp/language-server.js",,
375+
},
376+
}
377+
```
378+
356379
## Commands
357380

358381
`copilot.lua` defines the `:Copilot` command that can perform various actions. It has completion support, so try it out.

copilot/.gitignore

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

copilot/dist/language-server.js

Lines changed: 0 additions & 1128 deletions
This file was deleted.

copilot/dist/language-server.js.map

Lines changed: 0 additions & 6 deletions
This file was deleted.

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';
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)