Skip to content

Commit 1dc680f

Browse files
update chat lib extraction with new path and add context setup for lib
1 parent a1c5d28 commit 1dc680f

File tree

9 files changed

+357
-14
lines changed

9 files changed

+357
-14
lines changed

chat-lib/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"outdent": "^0.8.0",
3434
"rimraf": "^6.0.1",
3535
"typescript": "^5.8.3",
36-
"vite-tsconfig-paths": "^5.1.4",
3736
"vitest": "^3.0.5"
3837
},
3938
"keywords": [
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
// Load env
7+
import * as dotenv from 'dotenv';
8+
dotenv.config({ path: '../.env' });
9+
10+
import { createTextDocument } from '#lib/test/textDocument';
11+
import { assert, describe, it } from 'vitest';
12+
import { createInlineCompletionsProvider } from '../src/main';
13+
14+
describe('getInlineCompletions', () => {
15+
it('should return completions for a document and position', async () => {
16+
const provider = createInlineCompletionsProvider({
17+
fetcher: undefined as any,
18+
authService: undefined as any,
19+
telemetrySender: undefined as any,
20+
isRunningInTest: true,
21+
contextProviderMatch: undefined as any,
22+
statusHandler: undefined as any,
23+
documentManager: undefined as any,
24+
workspace: undefined as any,
25+
urlOpener: undefined as any,
26+
editorInfo: undefined as any,
27+
editorPluginInfo: undefined as any,
28+
relatedPluginInfo: undefined as any,
29+
editorSession: undefined as any,
30+
notificationSender: undefined as any,
31+
endpointProvider: undefined as any,
32+
capiClientService: undefined as any,
33+
});
34+
const doc = createTextDocument('file:///test.txt', 'javascript', 1, 'function main() {\n\n\n}\n');
35+
36+
const result = await provider.getInlineCompletions(doc, { line: 1, character: 0 });
37+
38+
assert(result);
39+
});
40+
});

chat-lib/tsconfig.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
],
1414
"paths": {
1515
"#lib/*": [
16-
"./src/_internal/extension/completions-core/lib/src/*"
16+
"./src/_internal/extension/completions-core/vscode-node/lib/src/*"
1717
],
1818
"#prompt/*": [
19-
"./src/_internal/extension/completions-core/prompt/src/*"
19+
"./src/_internal/extension/completions-core/vscode-node/prompt/src/*"
2020
],
2121
"#bridge/*": [
22-
"./src/_internal/extension/completions-core/bridge/src/*"
22+
"./src/_internal/extension/completions-core/vscode-node/bridge/src/*"
2323
],
2424
"#types": [
25-
"./src/_internal/extension/completions-core/types/src"
25+
"./src/_internal/extension/completions-core/vscode-node/types/src"
2626
]
2727
}
2828
},

eslint.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,5 +366,11 @@ export default tseslint.config(
366366
'local/no-unlayered-files': 'off',
367367
'no-restricted-imports': 'off'
368368
}
369+
},
370+
{
371+
files: ['./src/lib/node/chatLibMain.ts'],
372+
rules: {
373+
'import/no-restricted-paths': 'off'
374+
}
369375
}
370376
);

script/build/extractChatLib.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const entryPoints = [
2727
'src/platform/tokenizer/node/tikTokenizerWorker.ts',
2828
// For tests:
2929
'src/platform/authentication/test/node/simulationTestCopilotTokenManager.ts',
30+
'src/extension/completions-core/vscode-node/lib/src/test/textDocument.ts',
3031
];
3132

3233
interface FileInfo {

src/extension/completions-core/vscode-node/completionsServiceBridges.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export function createContext(serviceAccessor: ServicesAccessor): Context {
143143
}
144144
});
145145

146-
ctx.set(NotificationSender, new ExtensionNotificationSender());
146+
ctx.set(NotificationSender, instaService.createInstance(ExtensionNotificationSender));
147147
ctx.set(EditorAndPluginInfo, new VSCodeEditorInfo());
148148
ctx.set(EditorSession, new EditorSession(env.sessionId, env.machineId, env.remoteName, uiKindToString(env.uiKind)));
149149
ctx.set(CopilotExtensionStatus, new CopilotExtensionStatus());

src/extension/completions-core/vscode-node/lib/src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,14 +373,14 @@ type NameAndVersion = {
373373
version: string;
374374
};
375375

376-
type EditorInfo = NameAndVersion & {
376+
export type EditorInfo = NameAndVersion & {
377377
// The root directory of the installation, currently only used to simplify stack traces.
378378
root?: string;
379379
// A programmatic name, used for error reporting.
380380
devName?: string;
381381
};
382382

383-
type EditorPluginInfo = NameAndVersion;
383+
export type EditorPluginInfo = NameAndVersion;
384384

385385
export type EditorPluginFilter = { filter: Filter; value: string; isVersion?: boolean };
386386

src/extension/completions-core/vscode-node/lib/src/notificationSender.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
5-
import { window } from 'vscode';
5+
import { INotificationService } from '../../../../../platform/notification/common/notificationService';
66

77
export interface ActionItem {
88
title: string;
@@ -13,8 +13,12 @@ export abstract class NotificationSender {
1313
}
1414

1515
export class ExtensionNotificationSender extends NotificationSender {
16+
constructor(@INotificationService private readonly notificationService: INotificationService) {
17+
super();
18+
}
19+
1620
async showWarningMessage(message: string, ...actions: ActionItem[]): Promise<ActionItem | undefined> {
17-
const response = await window.showWarningMessage(message, ...actions.map(action => action.title));
21+
const response = await this.notificationService.showWarningMessage(message, ...actions.map(action => action.title));
1822
if (response === undefined) { return; }
1923
return { title: response };
2024
}

0 commit comments

Comments
 (0)