@@ -126,21 +126,27 @@ export class FollowAndAuthorRulesProcessor {
126126 try {
127127 //const data = JSON.parse(message);
128128 const fileName = jsonData . data . fileName ;
129- //console.log(fileName);
130129 const convertedJava = jsonData . data . convertedJava ;
131- //console.log("full text: ", convertedJava);
132- const lastLine = convertedJava . trim ( ) . split ( '\n' ) . pop ( ) ;
133- //console.log("Last Line: ",lastLine);
130+ const lastLineSnippet = convertedJava . trim ( ) . split ( '\n' ) . pop ( ) . trim ( ) ;
134131
135132 const openPath = vscode . Uri . file ( fileName ) ;
136133 vscode . workspace . openTextDocument ( openPath ) . then ( doc => {
137134 vscode . window . showTextDocument ( doc ) . then ( editor => {
138135 const text = doc . getText ( ) ;
139- const lastLineIndex = text . split ( '\n' ) . findIndex ( line => line . includes ( lastLine ) ) ;
136+ const lines = text . split ( '\n' ) ;
137+ let lineIndex = - 1 ;
140138
141- if ( lastLineIndex !== - 1 ) {
142- const startPos = new vscode . Position ( lastLineIndex , 0 ) ;
143- const endPos = new vscode . Position ( lastLineIndex , lastLine . length ) ;
139+ // Find the line containing the lastLineSnippet
140+ for ( let i = 0 ; i < lines . length ; i ++ ) {
141+ if ( lines [ i ] . includes ( lastLineSnippet ) ) {
142+ lineIndex = i ;
143+ break ;
144+ }
145+ }
146+
147+ if ( lineIndex !== - 1 ) {
148+ const startPos = new vscode . Position ( lineIndex , 0 ) ;
149+ const endPos = new vscode . Position ( lineIndex , lines [ lineIndex ] . length ) ;
144150 const range = new vscode . Range ( startPos , endPos ) ;
145151
146152 editor . selection = new vscode . Selection ( startPos , endPos ) ;
@@ -154,7 +160,7 @@ export class FollowAndAuthorRulesProcessor {
154160 }
155161 } ) ;
156162 } ) ;
157- } catch ( error ) {
163+ } catch ( error ) {
158164 vscode . window . showErrorMessage ( 'Failed to process the message: ' + error ) ;
159165 }
160166 break ;
0 commit comments