Przeglądaj źródła

Check searchTrimmed and trim more new lines

beatlevic 3 miesięcy temu
rodzic
commit
b08ef971dd

+ 0 - 1
src/services/ghost/GhostInlineCompletionProvider.ts

@@ -81,7 +81,6 @@ export class GhostInlineCompletionProvider implements vscode.InlineCompletionIte
 		const { prefix, suffix } = extractPrefixSuffix(document, position)
 
 		const matchingText = findMatchingSuggestion(prefix, suffix, this.suggestionsHistory)
-
 		if (matchingText !== null) {
 			const item: vscode.InlineCompletionItem = {
 				insertText: matchingText,

+ 18 - 6
src/services/ghost/GhostStreamingParser.ts

@@ -252,22 +252,34 @@ export class GhostStreamingParser {
 			return null
 		}
 
+		// Trim trailing whitespace from search for better matching
+		const searchTrimmed = searchWithoutMarker.trimEnd()
+
 		// Extract the new content
 		let newContent = replaceWithoutMarker
-		if (replaceWithoutMarker.startsWith(searchWithoutMarker)) {
+		if (replaceWithoutMarker.startsWith(searchTrimmed)) {
 			// LLM preserved the search context - remove it
-			newContent = replaceWithoutMarker.substring(searchWithoutMarker.length)
+			newContent = replaceWithoutMarker.substring(searchTrimmed.length)
 		}
 
+		// Trim trailing newlines from the content (LLM often adds extras)
+		newContent = newContent.trimEnd()
+
 		// Check if current line (where cursor is) has content
-		// Extract the last line before cursor marker in the original search
 		const lines = prefix.split("\n")
 		const currentLine = lines[lines.length - 1]
 		const currentLineHasContent = currentLine.trim().length > 0
 
-		// Only add newline if current line has content
-		if (currentLineHasContent && !newContent.startsWith("\n")) {
-			newContent = "\n" + newContent
+		if (currentLineHasContent) {
+			// Current line has content - add newline if not present
+			if (!newContent.startsWith("\n")) {
+				newContent = "\n" + newContent
+			}
+		} else {
+			// Current line is empty - remove any leading newline LLM might have added
+			if (newContent.startsWith("\n")) {
+				newContent = newContent.substring(1)
+			}
 		}
 
 		return { text: newContent, prefix, suffix }