@@ -400,8 +400,7 @@ export class Architect {
400400 return [ ] ;
401401 }
402402
403- // TODO: this is disabled because it removes many useful suggestions
404- //completion = this.updateSuggestion(suggestionLines, document, position, linePrefix, lineSuffix);
403+ completion = this . updateSuggestion ( suggestionLines , lineSuffix ) ;
405404
406405 if ( ! isCachedResponse ) this . lruResultCache . put ( hashKey , completion )
407406 this . lastCompletion = this . getCompletionDetails ( completion , position , inputPrefix , inputSuffix , prompt ) ;
@@ -672,40 +671,14 @@ export class Architect {
672671 return discardSuggestion ;
673672 }
674673
675- // returns suggestion with removed trailing part, which is the same as the existing code
676- updateSuggestion = ( suggestionLines : string [ ] , document : vscode . TextDocument , position : vscode . Position , linePrefix : string , lineSuffix : string ) => {
677- let updatedSuggestion = suggestionLines . join ( "\n" ) ;
678- if ( suggestionLines . length == 1 && lineSuffix . trim ( ) === "" ) return updatedSuggestion
679- // if suggestion is one line and the line suffix is a suffix of the line - remove the line suffix
680- if ( suggestionLines . length == 1 && suggestionLines [ 0 ] . endsWith ( lineSuffix ) ) return suggestionLines [ 0 ] . slice ( 0 , - lineSuffix . length ) ;
674+ // cut part of the suggestion in some special cases
675+ updateSuggestion = ( suggestionLines : string [ ] , lineSuffix : string ) => {
676+ if ( lineSuffix . trim ( ) != "" ) {
677+ if ( suggestionLines [ 0 ] . endsWith ( lineSuffix ) ) return suggestionLines [ 0 ] . slice ( 0 , - lineSuffix . length ) ;
678+ if ( suggestionLines . length > 1 ) return suggestionLines [ 0 ] ;
679+ }
681680
682- // if cursor on the last line just return the suggestion
683- if ( position . line == document . lineCount - 1 ) return updatedSuggestion ;
684-
685- // if the following lines repeat the suggestion and the line suffix is empty - update suggestion
686- if ( suggestionLines . length > 1
687- && ( lineSuffix . trim ( ) === "" ) ) {
688- let linesToCompareCount = suggestionLines . length - 1
689- // if cursor on the last line don't discard
690- if ( position . line + linesToCompareCount > document . lineCount - 1 ) return updatedSuggestion ;
691- let indLastSuggestionLine = suggestionLines . slice ( 1 ) . reverse ( ) . findIndex ( ( value , index ) => value != document . lineAt ( ( position . line + linesToCompareCount ) - index ) . text )
692- return suggestionLines . slice ( 0 , indLastSuggestionLine + 2 ) . join ( "\n" ) ; // if indLastSuggestionLine is -1 then all following lines are the same as the suggestion
693- }
694-
695- // if the following lines repeat the suggestion and the first line ends with the line suffix update suggestion
696- if ( suggestionLines . length > 1
697- && suggestionLines [ 0 ] . endsWith ( lineSuffix )
698- && suggestionLines . slice ( 1 ) . every ( ( value , index ) => value === document . lineAt ( ( position . line + 1 ) + index ) . text ) ) {
699- return suggestionLines [ 0 ] . slice ( 0 , - lineSuffix . length ) ;
700- }
701-
702- // if there is a line suffix suggest only one line
703- if ( suggestionLines . length > 1
704- && lineSuffix . trim ( ) != "" ) {
705- return suggestionLines [ 0 ] ;
706- }
707-
708- return updatedSuggestion ;
681+ return suggestionLines . join ( "\n" ) ;
709682 }
710683
711684 private getCompletionDetails = ( completion : string , position : vscode . Position , inputPrefix : string , inputSuffix : string , prompt : string ) => {
0 commit comments