Skip to content

Commit 638faf0

Browse files
yatarkanapaniukov
andauthoredOct 16, 2023
[VSCode Extension] Add missing files & Configure CI (#748)
* Add missed media directory * Disable azure pipelines for openvino code module * Specify ci workflow path for token merging module * Add ci workflow for openvino code module * Enable extension workflow for forks * Add cache dependency path for extension workflow * Add missing files * Review fixes --------- Co-authored-by: Artur Paniukov <artur.paniukov@intel.com>
1 parent f6eb6af commit 638faf0

14 files changed

+426
-2
lines changed
 

‎.ci/azure/linux.yml

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ trigger:
66
paths:
77
exclude:
88
- modules/nvidia_plugin
9+
- modules/openvino_code
910

1011
pr:
1112
branches:
@@ -15,6 +16,7 @@ pr:
1516
paths:
1617
exclude:
1718
- modules/nvidia_plugin
19+
- modules/openvino_code
1820

1921
resources:
2022
repositories:

‎.ci/azure/linux_cuda.yml

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ trigger:
77
include:
88
- modules/nvidia_plugin
99
- .ci/azure/linux_cuda.yml
10+
exclude:
11+
- modules/openvino_code
1012

1113
pr:
1214
branches:
@@ -16,6 +18,8 @@ pr:
1618
paths:
1719
include:
1820
- modules/nvidia_plugin
21+
exclude:
22+
- modules/openvino_code
1923

2024
resources:
2125
repositories:

‎.ci/azure/mac.yml

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ trigger:
66
paths:
77
exclude:
88
- modules/nvidia_plugin
9+
- modules/openvino_code
910

1011
pr:
1112
branches:
@@ -15,6 +16,7 @@ pr:
1516
paths:
1617
exclude:
1718
- modules/nvidia_plugin
19+
- modules/openvino_code
1820

1921
resources:
2022
repositories:

‎.ci/azure/windows.yml

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ trigger:
66
paths:
77
exclude:
88
- modules/nvidia_plugin
9+
- modules/openvino_code
910

1011
pr:
1112
branches:
@@ -15,6 +16,7 @@ pr:
1516
paths:
1617
exclude:
1718
- modules/nvidia_plugin
19+
- modules/openvino_code
1820

1921
resources:
2022
repositories:

‎.github/workflows/openvino_code.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: OpenVINO Code Extension Workflow
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
paths:
7+
- 'modules/openvino_code/**'
8+
- '.github/workflows/openvino_code.yml'
9+
10+
concurrency:
11+
group: ${{ github.head_ref || github.ref_name }}-openvino_code
12+
cancel-in-progress: true
13+
14+
defaults:
15+
run:
16+
working-directory: ./modules/openvino_code
17+
18+
jobs:
19+
check_extension:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Use Node.js 16.x
26+
uses: actions/setup-node@v3
27+
with:
28+
node-version: '16.x'
29+
cache: 'npm'
30+
cache-dependency-path: modules/openvino_code/package-lock.json
31+
32+
- name: Install dependencies
33+
run: npm ci
34+
35+
- name: Run Lint
36+
run: npm run lint:all
37+
38+
check_server:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Checkout code
42+
uses: actions/checkout@v4
43+
44+
- name: Set up Python 3.8
45+
uses: actions/setup-python@v4
46+
with:
47+
python-version: '3.8'
48+
cache: 'pip'
49+
50+
- name: Install dependencies
51+
run: pip install ruff black
52+
53+
- name: Lint with ruff and Black
54+
run: |
55+
cd server
56+
ruff check .
57+
black --check .

‎.github/workflows/token_merging.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ name: Token Merging - Test
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches:
6+
- master
7+
paths:
8+
- 'modules/token_merging/**'
69
pull_request:
7-
branches: [ master ]
10+
branches:
11+
- master
12+
paths:
13+
- 'modules/token_merging/**'
814

915
concurrency:
1016
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}

‎modules/openvino_code/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ venv
2626
/server/OVCodExtServer.egg-info/
2727
/server/src/OVCodExtServer.egg-info/
2828
/server/.ruff_cache/
29+
30+
!media/*.png

‎modules/openvino_code/media/logo.png

6.51 KB
Loading
930 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Disposable, ExtensionContext, commands, window, languages } from 'vscode';
2+
import { COMMANDS } from '../constants';
3+
import { IExtensionComponent } from '../extension-component.interface';
4+
import { notificationService } from '../services/notification.service';
5+
import { extensionState } from '../state';
6+
import { CommandInlineCompletionItemProvider } from './command-inline-completion-provider';
7+
8+
class InlineCompletion implements IExtensionComponent {
9+
private _disposables: Disposable[] = [];
10+
11+
activate(context: ExtensionContext): void {
12+
// Register Inline Completion triggered by command
13+
const commandInlineCompletionProvider = new CommandInlineCompletionItemProvider();
14+
15+
let commandInlineCompletionDisposable: Disposable;
16+
17+
const generateCommandDisposable = commands.registerCommand(COMMANDS.GENERATE_INLINE_COPMLETION, () => {
18+
if (!extensionState.get('isServerAvailable')) {
19+
notificationService.showServerNotAvailableMessage(extensionState.state);
20+
return;
21+
}
22+
if (extensionState.get('isLoading') && window.activeTextEditor) {
23+
void window.showTextDocument(window.activeTextEditor.document);
24+
return;
25+
}
26+
27+
extensionState.set('isLoading', true);
28+
29+
if (commandInlineCompletionDisposable) {
30+
commandInlineCompletionDisposable.dispose();
31+
}
32+
33+
commandInlineCompletionDisposable = languages.registerInlineCompletionItemProvider(
34+
{ pattern: '**' },
35+
commandInlineCompletionProvider
36+
);
37+
38+
void commandInlineCompletionProvider.triggerCompletion(() => {
39+
commandInlineCompletionDisposable.dispose();
40+
extensionState.set('isLoading', false);
41+
});
42+
});
43+
44+
const acceptCommandDisposable = commands.registerCommand(COMMANDS.ACCEPT_INLINE_COMPLETION, () => {
45+
void commands.executeCommand('editor.action.inlineSuggest.commit');
46+
});
47+
48+
context.subscriptions.push(generateCommandDisposable, acceptCommandDisposable);
49+
this._disposables.push(generateCommandDisposable, acceptCommandDisposable);
50+
}
51+
52+
deactivate(): void {
53+
this._disposables.forEach((disposable) => {
54+
disposable.dispose();
55+
});
56+
this._disposables = [];
57+
}
58+
}
59+
60+
export const inlineCompletion = new InlineCompletion();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { EventEmitter as NodeEventEmitter } from 'stream';
2+
import {
3+
InlineCompletionItem,
4+
InlineCompletionItemProvider,
5+
Position,
6+
Range,
7+
TextDocument,
8+
commands,
9+
window,
10+
} from 'vscode';
11+
import { EXTENSION_DISPLAY_NAME } from '../constants';
12+
import completionService from './completion.service';
13+
14+
interface ICommandInlineCompletionItemProvider extends InlineCompletionItemProvider {
15+
triggerCompletion(onceCompleted: () => void): void;
16+
}
17+
18+
/**
19+
* Trigger {@link ICommandInlineCompletionItemProvider.provideInlineCompletionItems}.
20+
* Executing editor.action.inlineSuggest.trigger command doesn't trigger inline completion when inlineSuggestionVisible context key is set.
21+
* Executing editor.action.inlineSuggest.hide before editor.action.inlineSuggest.trigger will make inline completion text bliks.
22+
* Replacing previous character before trigger seems to do the job.
23+
*/
24+
async function triggerInlineCompletionProvider(): Promise<void> {
25+
const editor = window.activeTextEditor;
26+
if (!editor) {
27+
return;
28+
}
29+
30+
const document = editor.document;
31+
const activePosition = editor.selection.active;
32+
const activeOffset = document.offsetAt(activePosition);
33+
34+
if (activeOffset === 0) {
35+
return;
36+
}
37+
38+
const prevCharPosition = document.positionAt(activeOffset - 1);
39+
const replaceRange = new Range(prevCharPosition, activePosition);
40+
const value = document.getText(replaceRange);
41+
42+
await editor.edit((edit) => edit.replace(replaceRange, value));
43+
await commands.executeCommand('editor.action.inlineSuggest.trigger');
44+
}
45+
46+
export class StreamingCommandInlineCompletionItemProvider implements ICommandInlineCompletionItemProvider {
47+
private _isCommandRunning = false;
48+
49+
private readonly _emitter = new NodeEventEmitter().setMaxListeners(1);
50+
51+
private _streamBuffer: string = '';
52+
53+
private readonly _commandCompletedEvent = 'CommandInlineCompletionItemProvider:completed';
54+
55+
private _abortController = new AbortController();
56+
57+
private _beforeComplete(): void {
58+
this._isCommandRunning = false;
59+
this._streamBuffer = '';
60+
this._abortController.abort();
61+
this._abortController = new AbortController();
62+
this._emitter.emit(this._commandCompletedEvent);
63+
}
64+
65+
async triggerCompletion(onceCompleted: () => void) {
66+
this._emitter.once(this._commandCompletedEvent, onceCompleted);
67+
68+
if (!window.activeTextEditor) {
69+
void window.showInformationMessage(`Please open a file first to use ${EXTENSION_DISPLAY_NAME}.`);
70+
this._beforeComplete();
71+
return;
72+
}
73+
74+
if (this._isCommandRunning) {
75+
return;
76+
}
77+
78+
this._isCommandRunning = true;
79+
80+
void commands.executeCommand('workbench.action.focusStatusBar');
81+
void window.showTextDocument(window.activeTextEditor.document);
82+
83+
await completionService.getCompletionStream(
84+
window.activeTextEditor.document,
85+
window.activeTextEditor.selection.active,
86+
async (chunk) => {
87+
this._streamBuffer += chunk;
88+
await triggerInlineCompletionProvider();
89+
},
90+
this._abortController.signal
91+
);
92+
93+
this._isCommandRunning = false;
94+
await triggerInlineCompletionProvider();
95+
}
96+
97+
stopGeneration() {
98+
this._abortController.abort();
99+
}
100+
101+
cancelGeneration() {
102+
this._beforeComplete();
103+
}
104+
105+
provideInlineCompletionItems(document: TextDocument, position: Position) {
106+
const buffer = this._streamBuffer;
107+
if (!this._isCommandRunning) {
108+
this._beforeComplete();
109+
}
110+
111+
return [new InlineCompletionItem(`${buffer}`, new Range(position, position.translate(0, 1)))];
112+
}
113+
}

0 commit comments

Comments
 (0)
Please sign in to comment.