Skip to content

Commit 8d25c96

Browse files
committed
restrict inline completions
1 parent 4e3d4a4 commit 8d25c96

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

src/chat-sidebar.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ function SidebarComponent(props: any) {
13231323
}
13241324

13251325
setCopilotRequestInProgress(true);
1326-
1326+
console.log('Request triggered on input - ', prompt);
13271327
const activeDocInfo: IActiveDocumentInfo = props.getActiveDocumentInfo();
13281328
const extractedPrompt = prompt;
13291329
const contents: IChatMessageContent[] = [];
@@ -1363,8 +1363,6 @@ function SidebarComponent(props: any) {
13631363
}
13641364
}
13651365

1366-
console.log('Complete context : ', additionalContext);
1367-
13681366
submitCompletionRequest(
13691367
{
13701368
messageId: lastMessageId.current,

src/index.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ class NBIInlineCompletionProvider
345345
get schema(): ISettingRegistry.IProperty {
346346
return {
347347
default: {
348-
debouncerDelay: 200,
348+
debouncerDelay: 100,
349349
timeout: 15000
350350
}
351351
};
@@ -438,7 +438,6 @@ class NBIInlineCompletionProvider
438438
editorType
439439
}
440440
});
441-
442441
return new Promise((resolve, reject) => {
443442
const items: IInlineCompletionItem[] = [];
444443

@@ -453,11 +452,35 @@ class NBIInlineCompletionProvider
453452
RequestDataType.CancelInlineCompletionRequest,
454453
{ chatId: this._lastRequestInfo.chatId }
455454
);
455+
456+
if (
457+
this._lastRequestInfo.completion &&
458+
preCursor.length > 0 &&
459+
preCursor[preCursor.length - 1] ===
460+
this._lastRequestInfo.completion[0]
461+
) {
462+
// if the last element of the preCursor is the first element of the completion
463+
// we do not need to make a completion request on the assumption that the
464+
// user is about to type the rest of the completion
465+
resolve({
466+
items: [
467+
{ insertText: this._lastRequestInfo.completion.substring(1) }
468+
]
469+
});
470+
this._lastRequestInfo.completion =
471+
this._lastRequestInfo.completion.substring(1);
472+
return;
473+
}
456474
}
457475

458476
const messageId = UUID.uuid4();
459477
const chatId = UUID.uuid4();
460-
this._lastRequestInfo = { chatId, messageId, requestTime: new Date() };
478+
this._lastRequestInfo = {
479+
chatId,
480+
messageId,
481+
completion: '',
482+
requestTime: new Date()
483+
};
461484

462485
NBIAPI.inlineCompletionsRequest(
463486
chatId,
@@ -475,6 +498,7 @@ class NBIInlineCompletionProvider
475498
items.push({
476499
insertText: response.data.completions
477500
});
501+
this._lastRequestInfo.completion = response.data.completions;
478502

479503
const timeElapsed =
480504
(new Date().getTime() -
@@ -518,6 +542,7 @@ class NBIInlineCompletionProvider
518542
private _lastRequestInfo: {
519543
chatId: string;
520544
messageId: string;
545+
completion: string;
521546
requestTime: Date;
522547
} = null;
523548
private _telemetryEmitter: TelemetryEmitter;
@@ -721,7 +746,7 @@ const plugin: JupyterFrontEndPlugin<INotebookIntelligence> = {
721746
})
722747
.catch(reason => {
723748
console.error(
724-
'Failed to load settings for @notebook-intelligence/lab-notebook-intelligence.',
749+
'Failed to load settings for @lab-notebook-intelligence/lab-notebook-intelligence.',
725750
reason
726751
);
727752
});

style/base.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
.sidebar {
99
display: flex;
1010
flex-direction: column;
11-
min-width: 40%;
11+
min-width: 50%;
1212
height: 100%;
1313
}
1414

0 commit comments

Comments
 (0)