Skip to content

Commit 34989d0

Browse files
Added support for function signatures in typescript (#2756)
Fixes #1121 ## Checklist - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [/] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet
1 parent 220e381 commit 34989d0

File tree

5 files changed

+181
-0
lines changed

5 files changed

+181
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
class MyClass {
2+
constructor(value: string)
3+
constructor(value: number);
4+
constructor(value: string | number) {}
5+
}
6+
---
7+
8+
[#1 Content] =
9+
[#1 Domain] = 1:2-1:28
10+
>--------------------------<
11+
1| constructor(value: string)
12+
13+
[#1 Removal] = 1:0-1:28
14+
>----------------------------<
15+
1| constructor(value: string)
16+
17+
[#1 Leading delimiter] = 1:0-1:2
18+
>--<
19+
1| constructor(value: string)
20+
21+
[#1 Insertion delimiter] = "\n\n"
22+
23+
24+
[#2 Content] =
25+
[#2 Domain] = 2:2-2:29
26+
>---------------------------<
27+
2| constructor(value: number);
28+
29+
[#2 Removal] = 2:0-2:29
30+
>-----------------------------<
31+
2| constructor(value: number);
32+
33+
[#2 Leading delimiter] = 2:0-2:2
34+
>--<
35+
2| constructor(value: number);
36+
37+
[#2 Insertion delimiter] = "\n\n"
38+
39+
40+
[#3 Content] =
41+
[#3 Domain] = 3:2-3:40
42+
>--------------------------------------<
43+
3| constructor(value: string | number) {}
44+
45+
[#3 Removal] = 3:0-3:40
46+
>----------------------------------------<
47+
3| constructor(value: string | number) {}
48+
49+
[#3 Leading delimiter] = 3:0-3:2
50+
>--<
51+
3| constructor(value: string | number) {}
52+
53+
[#3 Insertion delimiter] = "\n\n"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
class MyClass {
2+
foo(value: string)
3+
foo(value: number);
4+
foo(value: string | number) {}
5+
}
6+
---
7+
8+
[#1 Content] =
9+
[#1 Domain] = 1:2-1:20
10+
>------------------<
11+
1| foo(value: string)
12+
13+
[#1 Removal] = 1:0-1:20
14+
>--------------------<
15+
1| foo(value: string)
16+
17+
[#1 Leading delimiter] = 1:0-1:2
18+
>--<
19+
1| foo(value: string)
20+
21+
[#1 Insertion delimiter] = "\n\n"
22+
23+
24+
[#2 Content] =
25+
[#2 Domain] = 2:2-2:21
26+
>-------------------<
27+
2| foo(value: number);
28+
29+
[#2 Removal] = 2:0-2:21
30+
>---------------------<
31+
2| foo(value: number);
32+
33+
[#2 Leading delimiter] = 2:0-2:2
34+
>--<
35+
2| foo(value: number);
36+
37+
[#2 Insertion delimiter] = "\n\n"
38+
39+
40+
[#3 Content] =
41+
[#3 Domain] = 3:2-3:32
42+
>------------------------------<
43+
3| foo(value: string | number) {}
44+
45+
[#3 Removal] = 3:0-3:32
46+
>--------------------------------<
47+
3| foo(value: string | number) {}
48+
49+
[#3 Leading delimiter] = 3:0-3:2
50+
>--<
51+
3| foo(value: string | number) {}
52+
53+
[#3 Insertion delimiter] = "\n\n"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function foo(value: string)
2+
function foo(value: number);
3+
function foo(value: string | number) {}
4+
---
5+
6+
[#1 Content] =
7+
[#1 Removal] =
8+
[#1 Domain] = 0:0-0:27
9+
>---------------------------<
10+
0| function foo(value: string)
11+
12+
[#1 Insertion delimiter] = "\n\n"
13+
14+
15+
[#2 Content] =
16+
[#2 Removal] =
17+
[#2 Domain] = 1:0-1:28
18+
>----------------------------<
19+
1| function foo(value: number);
20+
21+
[#2 Insertion delimiter] = "\n\n"
22+
23+
24+
[#3 Content] =
25+
[#3 Removal] =
26+
[#3 Domain] = 2:0-2:39
27+
>---------------------------------------<
28+
2| function foo(value: string | number) {}
29+
30+
[#3 Insertion delimiter] = "\n\n"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
interface Aaa {
2+
bbb(): void;
3+
}
4+
---
5+
6+
[#1 Content] =
7+
[#1 Removal] =
8+
[#1 Domain] = 0:0-2:1
9+
>---------------
10+
0| interface Aaa {
11+
1| bbb(): void;
12+
2| }
13+
-<
14+
15+
[#1 Insertion delimiter] = "\n"
16+
17+
18+
[#2 Content] =
19+
[#2 Domain] = 1:4-1:16
20+
>------------<
21+
1| bbb(): void;
22+
23+
[#2 Removal] = 1:0-1:16
24+
>----------------<
25+
1| bbb(): void;
26+
27+
[#2 Leading delimiter] = 1:0-1:4
28+
>----<
29+
1| bbb(): void;
30+
31+
[#2 Insertion delimiter] = "\n"

queries/typescript.core.scm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
;; import javascript.core.scm
66

7+
;;!! class Aaa { bbb(); }
8+
;;! ^^^^^^
9+
(_
10+
(method_signature) @statement.start
11+
.
12+
";"? @statement.end
13+
)
14+
715
;;!! function aaa(bbb = "ddd") {}
816
;;! ^^^--------
917
(required_parameter
@@ -41,6 +49,12 @@
4149
;; Define these here because these node types don't exist in javascript.
4250
(_
4351
[
52+
;;!! function foo();
53+
;;! ^^^^^^^^^^^^^^^
54+
(function_signature
55+
name: (_) @functionName @name
56+
)
57+
4458
;;!! class Foo { foo() {} }
4559
;;! ^^^^^^^^
4660
;;!! interface Foo { foo(): void; }

0 commit comments

Comments
 (0)