File tree 4 files changed +27
-7
lines changed
snapshots/output/enclosing-ranges
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() {
34
34
// < start enclosing_range enclosing-ranges 0.0.1 `range.js`/Test#
35
35
class Test {
36
36
// ^^^^ definition enclosing-ranges 0.0.1 `range.js`/Test#
37
+ // ⌄ start enclosing_range enclosing-ranges 0.0.1 `range.js`/Test#`<constructor>`().
37
38
constructor ( ) {
38
39
//^^^^^^^^^^^ definition enclosing-ranges 0.0.1 `range.js`/Test#`<constructor>`().
39
40
const a = 'a'
@@ -45,6 +46,7 @@ class Test {
45
46
// ^ reference local 14
46
47
// ^ reference local 17
47
48
}
49
+ // ^ end enclosing_range enclosing-ranges 0.0.1 `range.js`/Test#`<constructor>`().
48
50
49
51
// ⌄ start enclosing_range enclosing-ranges 0.0.1 `range.js`/Test#test().
50
52
test ( ) {
Original file line number Diff line number Diff line change @@ -166,7 +166,13 @@ export class FileIndexer {
166
166
}
167
167
168
168
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 ( )
170
176
let role = 0
171
177
let declarations : ts . Node [ ] =
172
178
this . getDeclarationsForPropertyAssignment ( node ) ?? [ ]
@@ -207,7 +213,8 @@ export class FileIndexer {
207
213
ts . isTypeAliasDeclaration ( declaration ) ||
208
214
ts . isClassDeclaration ( declaration ) ||
209
215
ts . isMethodDeclaration ( declaration ) ||
210
- ts . isInterfaceDeclaration ( declaration )
216
+ ts . isInterfaceDeclaration ( declaration ) ||
217
+ ts . isConstructorDeclaration ( declaration )
211
218
) {
212
219
enclosingRange = Range . fromNode ( declaration ) . toLsif ( )
213
220
}
Original file line number Diff line number Diff line change @@ -33,18 +33,17 @@ export class Range {
33
33
new Position ( endLine , endCharacter )
34
34
)
35
35
}
36
+
36
37
public static fromNode ( node : ts . Node ) : Range {
37
38
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 ( ) )
43
41
return new Range (
44
42
new Position ( start . line , start . character ) ,
45
43
new Position ( end . line , end . character )
46
44
)
47
45
}
46
+
48
47
public isSingleLine ( ) : boolean {
49
48
return this . start . line === this . end . line
50
49
}
You can’t perform that action at this time.
0 commit comments