From a8149db948e7b97a830f6399f5244f221b2b8cf3 Mon Sep 17 00:00:00 2001 From: Ahmet Ildirim Date: Mon, 18 Aug 2025 23:18:31 +0200 Subject: [PATCH] refactor: improve completion generation logic with dedicated shouldGenerate method --- src/completions/service.ts | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/completions/service.ts b/src/completions/service.ts index 99cf08d..aa7e12d 100644 --- a/src/completions/service.ts +++ b/src/completions/service.ts @@ -35,12 +35,7 @@ export default class CompletionService { if (!activeEditor) return; if (!activeEditor.editor) return; - // Check if the editor is in Vim insert mode - if (isVimEnabled(activeEditor.editor)) { - if (!isVimInsertMode(activeEditor.editor)) { - return; - } - } + if (!this.shouldGenerate(activeEditor.editor)) return; const profile = this.profileService.getActiveProfile(); const provider = this.providerFactory.getProvider(profile.provider); @@ -96,4 +91,26 @@ export default class CompletionService { yield { text: text }; } } + + private shouldGenerate(editor: Editor): boolean { + // Check if the editor is in Vim insert mode + if (isVimEnabled(editor) && !isVimInsertMode(editor)) { + return false; + } + + const cursor = editor.getCursor(); + const currentLine = editor.getLine(cursor.line); + + // Line must not be empty + if (!currentLine || currentLine.length === 0) return false; + + // Cursor must not be at column 0 + if (cursor.ch === 0) return false; + + // Last character before cursor must be a space + const lastChar = currentLine[cursor.ch - 1]; + if (lastChar !== " ") return false; + + return true; + } } \ No newline at end of file