From e772676b60a15ef78eac1b5461a2b0b91b67ef31 Mon Sep 17 00:00:00 2001 From: rjmacarthy Date: Mon, 15 Jan 2024 20:28:12 +0000 Subject: [PATCH] update completion rules fix double closes --- src/providers/completion.ts | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/providers/completion.ts b/src/providers/completion.ts index 85e3c0bf..5e5a99e0 100644 --- a/src/providers/completion.ts +++ b/src/providers/completion.ts @@ -73,7 +73,10 @@ export class CompletionProvider implements InlineCompletionItemProvider { try { const json = JSON.parse(chunk) completion = completion + json.response - if (json.response && json.response === '\n' || json.response.match('')) { + if ( + (json.response && json.response === '\n') || + json.response.match('') + ) { onComplete() resolveStream(null) this._statusBar.text = '🤖' @@ -92,7 +95,7 @@ export class CompletionProvider implements InlineCompletionItemProvider { }, noop, noop, - this._useTls, + this._useTls ) }) } catch (error) { @@ -173,17 +176,43 @@ export class CompletionProvider implements InlineCompletionItemProvider { ] } + const cursorPosition = editor.selection.active + const charBeforeRange = new Range( position.translate(0, -1), editor.selection.start ) + const lineEndPosition = editor.document.lineAt(cursorPosition.line).range + .end + + const textAfterRange = new Range(cursorPosition, lineEndPosition) + const textAfterCursor = document.getText(textAfterRange).trim() const charBefore = document.getText(charBeforeRange) + const lineStart = editor.document.lineAt(cursorPosition).range.start + const lineRange = new Range(lineStart, lineEndPosition) + const lineText = document.getText(lineRange) + + if ( + completion.trim() === '/' || + lineText.includes(completion.trim()) || + (completion.trim() === '/>' && lineText.includes('