@@ -132,6 +132,18 @@ export interface IIdentifier {
132132 startCol : number ;
133133}
134134
135+ /*
136+ * xxxx
137+ * endxxx
138+ *
139+ */
140+ export interface IRange {
141+ startLine : number
142+ startCol : number
143+ endLine : number
144+ endCol : number
145+ }
146+
135147const globalFuncPattern = / ^ ( g : \w + ( \. \w + ) * | [ a - z A - Z _ ] \w * ( \. \w + ) * | \w + ( # \w + ) + ) $ / ;
136148const scriptFuncPattern = / ^ ( s : \w + ( \. \w + ) * | < S I D > \w + ( \. \w + ) * ) $ / i;
137149const globalVariablePattern = / ^ ( g : \w + ( \. \w + ) * | b : \w + ( \. \w + ) * | \w { 1 , } ( \. \w + ) * | \w + ( # \w + ) + ) $ / ;
@@ -153,6 +165,8 @@ export class Buffer {
153165 private envs : Record < string , IIdentifier [ ] > = { } ;
154166 private envRefs : Record < string , IIdentifier [ ] > = { } ;
155167
168+ private ranges : IRange [ ] = [ ]
169+
156170 constructor (
157171 private uri : string ,
158172 private projectRoot : string ,
@@ -193,6 +207,10 @@ export class Buffer {
193207 return this . localVariableRefs ;
194208 }
195209
210+ public getRanges ( ) {
211+ return this . ranges
212+ }
213+
196214 public getProjectRoot ( ) {
197215 return this . projectRoot ;
198216 }
@@ -402,6 +420,7 @@ export class Buffer {
402420 this . localVariableRefs = { } ;
403421 this . envs = { } ;
404422 this . envRefs = { } ;
423+ this . ranges = [ ]
405424 }
406425
407426 private resolveCompletionItems ( nodes : INode | INode [ ] ) {
@@ -446,6 +465,7 @@ export class Buffer {
446465 case NODE_ELSEIF :
447466 case NODE_ELSE :
448467 case NODE_WHILE :
468+ this . takeRange ( node , [ 'endif' , 'endwhile' ] )
449469 nodeList = nodeList . concat ( node . body || [ ] ) ;
450470 nodeList = nodeList . concat ( node . cond || [ ] ) ;
451471 nodeList = nodeList . concat ( node . elseif || [ ] ) ;
@@ -501,10 +521,12 @@ export class Buffer {
501521 nodeList = nodeList . concat ( node . body || [ ] ) ;
502522 nodeList = nodeList . concat ( node . right || [ ] ) ;
503523 this . takeFor ( [ ] . concat ( node . left || [ ] ) . concat ( node . list || [ ] ) ) ;
524+ this . takeRange ( node , 'endfor' )
504525 break ;
505526 case NODE_TRY :
506527 case NODE_CATCH :
507528 case NODE_FINALLY :
529+ this . takeRange ( node , 'endtry' )
508530 nodeList = nodeList . concat ( node . body || [ ] ) ;
509531 nodeList = nodeList . concat ( node . catch || [ ] ) ;
510532 nodeList = nodeList . concat ( node . _finally || [ ] ) ;
@@ -515,6 +537,7 @@ export class Buffer {
515537 nodeList = nodeList . concat ( node . left . left ) ;
516538 }
517539 this . takeFunction ( node ) ;
540+ this . takeRange ( node , 'endfunction' )
518541 break ;
519542 case NODE_LIST :
520543 nodeList = nodeList . concat ( node . value || [ ] ) ;
@@ -810,6 +833,19 @@ export class Buffer {
810833 }
811834 }
812835
836+ private takeRange ( node : INode , keys : string | string [ ] ) {
837+ [ ] . concat ( keys ) . forEach ( key => {
838+ if ( node . pos && node [ key ] && node [ key ] . pos ) {
839+ this . ranges . push ( {
840+ startLine : node . pos . lnum ,
841+ startCol : node . pos . col ,
842+ endLine : node [ key ] . pos . lnum ,
843+ endCol : node [ key ] . pos . col
844+ } )
845+ }
846+ } )
847+ }
848+
813849 private takeFor ( nodes : INode [ ] ) {
814850 nodes . forEach ( ( node ) => {
815851 if ( node . type !== NODE_IDENTIFIER || ! node . pos ) {
0 commit comments