@@ -31,8 +31,8 @@ export class Symbol {
3131 this . startPosition = new vscode . Position ( startLine , 0 ) ;
3232 this . parentScope = parentScope ;
3333 this . parentType = parentType ;
34- this . isValid = isValid ;
35- this . endPosition = new vscode . Position ( endLine , Number . MAX_VALUE ) ;
34+ this . isValid = isValid ?? false ;
35+ this . endPosition = new vscode . Position ( endLine ?? startLine , Number . MAX_VALUE ) ;
3636 }
3737
3838 setEndPosition ( endLine : number ) {
@@ -180,7 +180,7 @@ export class Ctags {
180180 }
181181 }
182182 catch ( e ) {
183- this . logger . error ( 'Exception caught: ' + e . message + ' ' + e . data ) ;
183+ this . logger . error ( 'Exception caught: ' + ( e instanceof Error ? e . message : String ( e ) ) ) ;
184184 }
185185 }
186186 else {
@@ -190,14 +190,14 @@ export class Ctags {
190190 return Promise . resolve ( '' ) ;
191191 }
192192
193- parseTagLine ( line : string ) : Symbol {
193+ parseTagLine ( line : string ) : Symbol | undefined {
194194 try {
195195 let name , type , pattern , lineNoStr , parentScope , parentType : string ;
196196 let scope : string [ ] ;
197197 let lineNo : number ;
198198 let parts : string [ ] = line . split ( '\t' ) ;
199199 name = parts [ 0 ] ;
200- // pattern = parts[2];
200+ pattern = parts [ 2 ] ;
201201 type = parts [ 3 ] ;
202202 // override "type" for parameters (See #102)
203203 if ( parts . length == 6 && parts [ 5 ] === 'parameter:' ) {
@@ -233,22 +233,26 @@ export class Ctags {
233233 let lines : string [ ] = tags . split ( / \r ? \n / ) ;
234234 lines . forEach ( ( line ) => {
235235 if ( line !== '' ) {
236- this . symbols . push ( this . parseTagLine ( line ) ) ;
236+ let tag : Symbol | undefined = this . parseTagLine ( line ) ;
237+ if ( tag ) {
238+ this . symbols . push ( tag ) ;
239+ }
237240 }
238241 } ) ;
239242
240243 // end tags are not supported yet in ctags. So, using regex
241- let match ;
242- let endPosition ;
244+ let match : RegExpExecArray | null ;
245+ let endPosition : vscode . Position ;
243246 let text = this . doc . getText ( ) ;
244247 let eRegex : RegExp = / ^ (? ! [ \r \n ] ) \s * e n d ( \w * ) * [ \s : ] ? / gm;
245248 while ( ( match = eRegex . exec ( text ) ) ) {
246249 if ( match && typeof match [ 1 ] !== 'undefined' ) {
247250 endPosition = this . doc . positionAt ( match . index + match [ 0 ] . length - 1 ) ;
248251 // get the starting symbols of the same type
249252 // doesn't check for begin...end blocks
253+ const matchType = match [ 1 ] ;
250254 let s = this . symbols . filter (
251- ( i ) => i . type === match [ 1 ] && i . startPosition . isBefore ( endPosition ) && ! i . isValid
255+ ( i ) => i . type === matchType && i . startPosition . isBefore ( endPosition ) && ! i . isValid
252256 ) ;
253257 if ( s . length > 0 ) {
254258 // get the symbol nearest to the end tag
@@ -272,7 +276,7 @@ export class Ctags {
272276 this . isDirty = false ;
273277 }
274278 } catch ( e ) {
275- this . logger . error ( e . toString ( ) ) ;
279+ this . logger . error ( String ( e ) ) ;
276280 }
277281 }
278282
@@ -286,7 +290,7 @@ export class Ctags {
286290
287291export class CtagsManager {
288292 private filemap : Map < vscode . TextDocument , Ctags > = new Map ( ) ;
289- private logger : Logger ;
293+ private logger ! : Logger ;
290294
291295 configure ( logger : Logger ) {
292296 this . logger = logger ;
@@ -296,7 +300,7 @@ export class CtagsManager {
296300 }
297301
298302 getCtags ( doc : vscode . TextDocument ) : Ctags {
299- let ctags : Ctags = this . filemap . get ( doc ) ;
303+ let ctags : Ctags | undefined = this . filemap . get ( doc ) ;
300304 if ( ctags === undefined ) {
301305 ctags = new Ctags ( this . logger , doc ) ;
302306 this . filemap . set ( doc , ctags ) ;
@@ -346,7 +350,7 @@ export class CtagsManager {
346350
347351 let textRange = document . getWordRangeAtPosition ( position ) ;
348352 if ( ! textRange || textRange . isEmpty ) {
349- return undefined ;
353+ return [ ] ;
350354 }
351355 let targetText = document . getText ( textRange ) ;
352356
@@ -366,11 +370,13 @@ export class CtagsManager {
366370 }
367371
368372 // kick off async job for indexing for module.sv
369- let searchPattern = new vscode . RelativePattern ( vscode . workspace . workspaceFolders [ 0 ] , `**/${ moduleToFind } .sv` ) ;
370- let files = await vscode . workspace . findFiles ( searchPattern ) ;
371- if ( files . length !== 0 ) {
372- let file = await vscode . workspace . openTextDocument ( files [ 0 ] ) ;
373- tasks . push ( this . findDefinition ( file , targetText ) ) ;
373+ if ( vscode . workspace . workspaceFolders && vscode . workspace . workspaceFolders . length > 0 ) {
374+ let searchPattern = new vscode . RelativePattern ( vscode . workspace . workspaceFolders [ 0 ] , `**/${ moduleToFind } .sv` ) ;
375+ let files = await vscode . workspace . findFiles ( searchPattern ) ;
376+ if ( files . length !== 0 ) {
377+ let file = await vscode . workspace . openTextDocument ( files [ 0 ] ) ;
378+ tasks . push ( this . findDefinition ( file , targetText ) ) ;
379+ }
374380 }
375381
376382 // TODO: use promise.race
0 commit comments