File tree Expand file tree Collapse file tree 4 files changed +27
-7
lines changed
snapshots/output/enclosing-ranges Expand file tree Collapse file tree 4 files changed +27
-7
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "version" : " 0.2.0" ,
3+ "configurations" : [
4+ {
5+ "type" : " node" ,
6+ "request" : " launch" ,
7+ "name" : " Debug Tests" ,
8+ "runtimeExecutable" : " npm" ,
9+ "runtimeArgs" : [" run" , " test" ]
10+ }
11+ ]
12+ }
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ function test2() {
3434// < start enclosing_range enclosing-ranges 0.0.1 `range.js`/Test#
3535class Test {
3636// ^^^^ definition enclosing-ranges 0.0.1 `range.js`/Test#
37+ // ⌄ start enclosing_range enclosing-ranges 0.0.1 `range.js`/Test#`<constructor>`().
3738 constructor ( ) {
3839//^^^^^^^^^^^ definition enclosing-ranges 0.0.1 `range.js`/Test#`<constructor>`().
3940 const a = 'a'
@@ -45,6 +46,7 @@ class Test {
4546// ^ reference local 14
4647// ^ reference local 17
4748 }
49+ // ^ end enclosing_range enclosing-ranges 0.0.1 `range.js`/Test#`<constructor>`().
4850
4951// ⌄ start enclosing_range enclosing-ranges 0.0.1 `range.js`/Test#test().
5052 test ( ) {
Original file line number Diff line number Diff line change @@ -166,7 +166,13 @@ export class FileIndexer {
166166 }
167167
168168 private visitSymbolOccurrence ( node : ts . Node , sym : ts . Symbol ) : void {
169- const range = Range . fromNode ( node ) . toLsif ( )
169+ const isConstructor = ts . isConstructorDeclaration ( node )
170+ // For constructors, this method is passed the declaration node and not the identifier node.
171+ // In either case, this method needs to get the range of the "name" of the declaration, for constructors we
172+ // get the firstToken which contains the text "constructor".
173+ const range = Range . fromNode (
174+ isConstructor ? node . getFirstToken ( ) ?? node : node
175+ ) . toLsif ( )
170176 let role = 0
171177 let declarations : ts . Node [ ] =
172178 this . getDeclarationsForPropertyAssignment ( node ) ?? [ ]
@@ -207,7 +213,8 @@ export class FileIndexer {
207213 ts . isTypeAliasDeclaration ( declaration ) ||
208214 ts . isClassDeclaration ( declaration ) ||
209215 ts . isMethodDeclaration ( declaration ) ||
210- ts . isInterfaceDeclaration ( declaration )
216+ ts . isInterfaceDeclaration ( declaration ) ||
217+ ts . isConstructorDeclaration ( declaration )
211218 ) {
212219 enclosingRange = Range . fromNode ( declaration ) . toLsif ( )
213220 }
Original file line number Diff line number Diff line change @@ -33,18 +33,17 @@ export class Range {
3333 new Position ( endLine , endCharacter )
3434 )
3535 }
36+
3637 public static fromNode ( node : ts . Node ) : Range {
3738 const sourceFile = node . getSourceFile ( )
38- const rangeNode : ts . Node = ts . isConstructorDeclaration ( node )
39- ? node . getFirstToken ( ) ?? node
40- : node
41- const start = sourceFile . getLineAndCharacterOfPosition ( rangeNode . getStart ( ) )
42- const end = sourceFile . getLineAndCharacterOfPosition ( rangeNode . getEnd ( ) )
39+ const start = sourceFile . getLineAndCharacterOfPosition ( node . getStart ( ) )
40+ const end = sourceFile . getLineAndCharacterOfPosition ( node . getEnd ( ) )
4341 return new Range (
4442 new Position ( start . line , start . character ) ,
4543 new Position ( end . line , end . character )
4644 )
4745 }
46+
4847 public isSingleLine ( ) : boolean {
4948 return this . start . line === this . end . line
5049 }
You can’t perform that action at this time.
0 commit comments