Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VSCode Extension] Add missing files & Configure CI #748

Merged
merged 10 commits into from
Oct 16, 2023
2 changes: 2 additions & 0 deletions .ci/azure/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ trigger:
paths:
exclude:
- modules/nvidia_plugin
- modules/openvino_code

pr:
branches:
Expand All @@ -15,6 +16,7 @@ pr:
paths:
exclude:
- modules/nvidia_plugin
- modules/openvino_code

resources:
repositories:
Expand Down
4 changes: 4 additions & 0 deletions .ci/azure/linux_cuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ trigger:
include:
- modules/nvidia_plugin
- .ci/azure/linux_cuda.yml
exclude:
- modules/openvino_code

pr:
branches:
Expand All @@ -16,6 +18,8 @@ pr:
paths:
include:
- modules/nvidia_plugin
exclude:
- modules/openvino_code

resources:
repositories:
Expand Down
2 changes: 2 additions & 0 deletions .ci/azure/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ trigger:
paths:
exclude:
- modules/nvidia_plugin
- modules/openvino_code

pr:
branches:
Expand All @@ -15,6 +16,7 @@ pr:
paths:
exclude:
- modules/nvidia_plugin
- modules/openvino_code

resources:
repositories:
Expand Down
2 changes: 2 additions & 0 deletions .ci/azure/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ trigger:
paths:
exclude:
- modules/nvidia_plugin
- modules/openvino_code

pr:
branches:
Expand All @@ -15,6 +16,7 @@ pr:
paths:
exclude:
- modules/nvidia_plugin
- modules/openvino_code

resources:
repositories:
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/openvino_code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: OpenVINO Code Extension Workflow

on:
pull_request:
types: [opened, synchronize]
paths:
- 'modules/openvino_code/**'
- '.github/workflows/openvino_code.yml'

concurrency:
group: ${{ github.head_ref || github.ref_name }}-openvino_code
cancel-in-progress: true

defaults:
run:
working-directory: ./modules/openvino_code

jobs:
check_extension:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: 'npm'
cache-dependency-path: modules/openvino_code/package-lock.json

- name: Install dependencies
run: npm ci

- name: Run Lint
run: npm run lint:all

check_server:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: '3.8'
cache: 'pip'

- name: Install dependencies
run: pip install ruff black

- name: Lint with ruff and Black
run: |
cd server
ruff check .
black --check .
10 changes: 8 additions & 2 deletions .github/workflows/token_merging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ name: Token Merging - Test

on:
push:
branches: [ master ]
branches:
- master
paths:
- 'modules/token_merging/**'
pull_request:
branches: [ master ]
branches:
- master
paths:
- 'modules/token_merging/**'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand Down
2 changes: 2 additions & 0 deletions modules/openvino_code/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ venv
/server/OVCodExtServer.egg-info/
/server/src/OVCodExtServer.egg-info/
/server/.ruff_cache/

!media/*.png
Binary file added modules/openvino_code/media/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/openvino_code/media/sidebar-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Disposable, ExtensionContext, commands, window, languages } from 'vscode';
import { COMMANDS } from '../constants';
import { IExtensionComponent } from '../extension-component.interface';
import { notificationService } from '../services/notification.service';
import { extensionState } from '../state';
import { CommandInlineCompletionItemProvider } from './command-inline-completion-provider';

class InlineCompletion implements IExtensionComponent {
private _disposables: Disposable[] = [];

activate(context: ExtensionContext): void {
// Register Inline Completion triggered by command
const commandInlineCompletionProvider = new CommandInlineCompletionItemProvider();

let commandInlineCompletionDisposable: Disposable;

const generateCommandDisposable = commands.registerCommand(COMMANDS.GENERATE_INLINE_COPMLETION, () => {
if (!extensionState.get('isServerAvailable')) {
notificationService.showServerNotAvailableMessage(extensionState.state);
return;
}
if (extensionState.get('isLoading') && window.activeTextEditor) {
void window.showTextDocument(window.activeTextEditor.document);
return;
}

extensionState.set('isLoading', true);

if (commandInlineCompletionDisposable) {
commandInlineCompletionDisposable.dispose();
}

commandInlineCompletionDisposable = languages.registerInlineCompletionItemProvider(
{ pattern: '**' },
commandInlineCompletionProvider
);

void commandInlineCompletionProvider.triggerCompletion(() => {
commandInlineCompletionDisposable.dispose();
extensionState.set('isLoading', false);
});
});

const acceptCommandDisposable = commands.registerCommand(COMMANDS.ACCEPT_INLINE_COMPLETION, () => {
void commands.executeCommand('editor.action.inlineSuggest.commit');
});

context.subscriptions.push(generateCommandDisposable, acceptCommandDisposable);
this._disposables.push(generateCommandDisposable, acceptCommandDisposable);
}

deactivate(): void {
this._disposables.forEach((disposable) => {
disposable.dispose();
});
this._disposables = [];
}
}

export const inlineCompletion = new InlineCompletion();
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { EventEmitter as NodeEventEmitter } from 'stream';
import {
InlineCompletionItem,
InlineCompletionItemProvider,
Position,
Range,
TextDocument,
commands,
window,
} from 'vscode';
import { EXTENSION_DISPLAY_NAME } from '../constants';
import completionService from './completion.service';

interface ICommandInlineCompletionItemProvider extends InlineCompletionItemProvider {
triggerCompletion(onceCompleted: () => void): void;
}

/**
* Trigger {@link ICommandInlineCompletionItemProvider.provideInlineCompletionItems}.
* Executing editor.action.inlineSuggest.trigger command doesn't trigger inline completion when inlineSuggestionVisible context key is set.
* Executing editor.action.inlineSuggest.hide before editor.action.inlineSuggest.trigger will make inline completion text bliks.
* Replacing previous character before trigger seems to do the job.
*/
async function triggerInlineCompletionProvider(): Promise<void> {
const editor = window.activeTextEditor;
if (!editor) {
return;
}

const document = editor.document;
const activePosition = editor.selection.active;
const activeOffset = document.offsetAt(activePosition);

if (activeOffset === 0) {
return;
}

const prevCharPosition = document.positionAt(activeOffset - 1);
const replaceRange = new Range(prevCharPosition, activePosition);
const value = document.getText(replaceRange);

await editor.edit((edit) => edit.replace(replaceRange, value));
await commands.executeCommand('editor.action.inlineSuggest.trigger');
}

export class StreamingCommandInlineCompletionItemProvider implements ICommandInlineCompletionItemProvider {
private _isCommandRunning = false;

private readonly _emitter = new NodeEventEmitter().setMaxListeners(1);

private _streamBuffer: string = '';

private readonly _commandCompletedEvent = 'CommandInlineCompletionItemProvider:completed';

private _abortController = new AbortController();

private _beforeComplete(): void {
this._isCommandRunning = false;
this._streamBuffer = '';
this._abortController.abort();
this._abortController = new AbortController();
this._emitter.emit(this._commandCompletedEvent);
}

async triggerCompletion(onceCompleted: () => void) {
this._emitter.once(this._commandCompletedEvent, onceCompleted);

if (!window.activeTextEditor) {
void window.showInformationMessage(`Please open a file first to use ${EXTENSION_DISPLAY_NAME}.`);
this._beforeComplete();
return;
}

if (this._isCommandRunning) {
return;
}

this._isCommandRunning = true;

void commands.executeCommand('workbench.action.focusStatusBar');
void window.showTextDocument(window.activeTextEditor.document);

await completionService.getCompletionStream(
window.activeTextEditor.document,
window.activeTextEditor.selection.active,
async (chunk) => {
this._streamBuffer += chunk;
await triggerInlineCompletionProvider();
},
this._abortController.signal
);

this._isCommandRunning = false;
await triggerInlineCompletionProvider();
}

stopGeneration() {
this._abortController.abort();
}

cancelGeneration() {
this._beforeComplete();
}

provideInlineCompletionItems(document: TextDocument, position: Position) {
const buffer = this._streamBuffer;
if (!this._isCommandRunning) {
this._beforeComplete();
}

return [new InlineCompletionItem(`${buffer}`, new Range(position, position.translate(0, 1)))];
}
}
Loading