@@ -133,19 +133,23 @@ export function getScope(
133133}
134134
135135export function getCommentBoundsList ( document : vscode . TextDocument ) {
136+ console . log ( "test" ) ;
136137 let text = document . getText ( ) ;
137138 let commentBounds : models . CommentBounds [ ] = [ ] ;
138139 let inComment = false ;
139140 let tempStart = 0 ;
140- for ( let i = 0 ; i < text . length - 1 ; i ++ ) {
141+ if ( text . length < 2 ) {
142+ return commentBounds ;
143+ }
144+ for ( let i = 1 ; i < text . length ; i ++ ) {
141145 if ( inComment ) {
142- if ( text [ i ] === "\n" || text === "\r" ) {
146+ if ( text [ i ] === "\n" || text [ i ] === "\r" ) {
143147 inComment = false ;
144148 commentBounds . push ( {
145149 start : tempStart ,
146- end : i ,
150+ end : i - 1 ,
147151 type : "Line" ,
148- raw : text . slice ( tempStart , i + 1 ) ,
152+ raw : text . slice ( tempStart , i ) ,
149153 } ) ;
150154 }
151155 } else {
@@ -160,7 +164,7 @@ export function getCommentBoundsList(document: vscode.TextDocument) {
160164 start : tempStart ,
161165 end : i ,
162166 type : "Line" ,
163- raw : text . slice ( tempStart , i + 1 ) ,
167+ raw : text . slice ( tempStart ) ,
164168 } ) ;
165169 }
166170 }
@@ -173,16 +177,18 @@ export function getCommentBoundsList(document: vscode.TextDocument) {
173177 for ( let i = 1 ; i < text . length ; i ++ ) {
174178 if ( inComment ) {
175179 if ( text [ i - 1 ] + text [ i ] === "*/" ) {
180+ // end
176181 inComment = false ;
177182 commentBounds . push ( {
178183 start : tempStart ,
179- end : i ,
184+ end : i - 1 ,
180185 type : "Block" ,
181- raw : text . slice ( tempStart , i + 1 ) ,
186+ raw : text . slice ( tempStart , i ) ,
182187 } ) ;
183188 }
184189 } else {
185190 if ( text [ i - 1 ] + text [ i ] === "/*" ) {
191+ // start
186192 inComment = true ;
187193 tempStart = i - 1 ;
188194 }
@@ -193,7 +199,7 @@ export function getCommentBoundsList(document: vscode.TextDocument) {
193199 start : tempStart ,
194200 end : i ,
195201 type : "Block" ,
196- raw : text . slice ( tempStart , i + 1 ) ,
202+ raw : text . slice ( tempStart ) ,
197203 } ) ;
198204 }
199205 }
0 commit comments