@@ -137,15 +137,18 @@ export function getCommentBoundsList(document: vscode.TextDocument) {
137137 let commentBounds : models . CommentBounds [ ] = [ ] ;
138138 let inComment = false ;
139139 let tempStart = 0 ;
140- for ( let i = 0 ; i < text . length - 1 ; i ++ ) {
140+ if ( text . length < 2 ) {
141+ return commentBounds ;
142+ }
143+ for ( let i = 1 ; i < text . length ; i ++ ) {
141144 if ( inComment ) {
142- if ( text [ i ] === "\n" || text === "\r" ) {
145+ if ( text [ i ] === "\n" || text [ i ] === "\r" ) {
143146 inComment = false ;
144147 commentBounds . push ( {
145148 start : tempStart ,
146- end : i ,
149+ end : i - 1 ,
147150 type : "Line" ,
148- raw : text . slice ( tempStart , i + 1 ) ,
151+ raw : text . slice ( tempStart , i ) ,
149152 } ) ;
150153 }
151154 } else {
@@ -160,7 +163,7 @@ export function getCommentBoundsList(document: vscode.TextDocument) {
160163 start : tempStart ,
161164 end : i ,
162165 type : "Line" ,
163- raw : text . slice ( tempStart , i + 1 ) ,
166+ raw : text . slice ( tempStart ) ,
164167 } ) ;
165168 }
166169 }
@@ -173,16 +176,18 @@ export function getCommentBoundsList(document: vscode.TextDocument) {
173176 for ( let i = 1 ; i < text . length ; i ++ ) {
174177 if ( inComment ) {
175178 if ( text [ i - 1 ] + text [ i ] === "*/" ) {
179+ // end
176180 inComment = false ;
177181 commentBounds . push ( {
178182 start : tempStart ,
179- end : i ,
183+ end : i - 1 ,
180184 type : "Block" ,
181- raw : text . slice ( tempStart , i + 1 ) ,
185+ raw : text . slice ( tempStart , i ) ,
182186 } ) ;
183187 }
184188 } else {
185189 if ( text [ i - 1 ] + text [ i ] === "/*" ) {
190+ // start
186191 inComment = true ;
187192 tempStart = i - 1 ;
188193 }
@@ -193,7 +198,7 @@ export function getCommentBoundsList(document: vscode.TextDocument) {
193198 start : tempStart ,
194199 end : i ,
195200 type : "Block" ,
196- raw : text . slice ( tempStart , i + 1 ) ,
201+ raw : text . slice ( tempStart ) ,
197202 } ) ;
198203 }
199204 }
0 commit comments