Skip to content

Commit

Permalink
Expand "type" to include generic type arguments / parameters (#2023)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson authored Nov 15, 2023
1 parent 620c538 commit f577cee
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
languageId: typescript
command:
version: 6
spokenForm: change type
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: type}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
useState<string>()
useState<Record<string, string>>()
selections:
- anchor: {line: 0, character: 9}
active: {line: 0, character: 9}
- anchor: {line: 1, character: 9}
active: {line: 1, character: 9}
marks: {}
finalState:
documentContents: |-
useState<>()
useState<>()
selections:
- anchor: {line: 0, character: 9}
active: {line: 0, character: 9}
- anchor: {line: 1, character: 9}
active: {line: 1, character: 9}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
languageId: typescript
command:
version: 6
spokenForm: change type
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: type}
usePrePhraseSnapshot: true
initialState:
documentContents: foo<Record<string, string>>()
selections:
- anchor: {line: 0, character: 4}
active: {line: 0, character: 4}
marks: {}
finalState:
documentContents: foo<>()
selections:
- anchor: {line: 0, character: 4}
active: {line: 0, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
languageId: typescript
command:
version: 6
spokenForm: change type
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: type}
usePrePhraseSnapshot: true
initialState:
documentContents: foo<string, string>()
selections:
- anchor: {line: 0, character: 4}
active: {line: 0, character: 4}
marks: {}
finalState:
documentContents: foo<, string>()
selections:
- anchor: {line: 0, character: 4}
active: {line: 0, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
languageId: typescript
command:
version: 6
spokenForm: change type
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: type}
usePrePhraseSnapshot: true
initialState:
documentContents: foo<string, string>()
selections:
- anchor: {line: 0, character: 12}
active: {line: 0, character: 12}
marks: {}
finalState:
documentContents: foo<string, >()
selections:
- anchor: {line: 0, character: 12}
active: {line: 0, character: 12}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
languageId: typescript
command:
version: 6
spokenForm: change type
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: type}
usePrePhraseSnapshot: true
initialState:
documentContents: Foo<string>()
selections:
- anchor: {line: 0, character: 4}
active: {line: 0, character: 4}
marks: {}
finalState:
documentContents: Foo<>()
selections:
- anchor: {line: 0, character: 4}
active: {line: 0, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
languageId: typescript
command:
version: 6
spokenForm: change type
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: type}
usePrePhraseSnapshot: true
initialState:
documentContents: |+
function foo<A>() {
}
selections:
- anchor: {line: 0, character: 13}
active: {line: 0, character: 13}
marks: {}
finalState:
documentContents: |+
function foo<>() {
}
selections:
- anchor: {line: 0, character: 13}
active: {line: 0, character: 13}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
languageId: typescript
command:
version: 6
spokenForm: change type
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: type}
usePrePhraseSnapshot: true
initialState:
documentContents: |
const bar = <A>() => {
}
selections:
- anchor: {line: 0, character: 13}
active: {line: 0, character: 13}
marks: {}
finalState:
documentContents: |
const bar = <>() => {
}
selections:
- anchor: {line: 0, character: 13}
active: {line: 0, character: 13}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
languageId: typescript
command:
version: 6
spokenForm: change type
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: type}
usePrePhraseSnapshot: true
initialState:
documentContents: "const foo: Record<string, string> = {}"
selections:
- anchor: {line: 0, character: 18}
active: {line: 0, character: 18}
marks: {}
finalState:
documentContents: "const foo: Record<, string> = {}"
selections:
- anchor: {line: 0, character: 18}
active: {line: 0, character: 18}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
languageId: typescript
command:
version: 6
spokenForm: change type
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: type}
usePrePhraseSnapshot: true
initialState:
documentContents: "const foo: string = new Bar<number>(foo);"
selections:
- anchor: {line: 0, character: 24}
active: {line: 0, character: 24}
marks: {}
finalState:
documentContents: "const foo: string = new (foo);"
selections:
- anchor: {line: 0, character: 24}
active: {line: 0, character: 24}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
languageId: typescript
command:
version: 6
spokenForm: change type
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: type}
usePrePhraseSnapshot: true
initialState:
documentContents: "const foo: Bar<number> = new Bar<number>(foo);"
selections:
- anchor: {line: 0, character: 11}
active: {line: 0, character: 11}
marks: {}
finalState:
documentContents: "const foo: = new Bar<number>(foo);"
selections:
- anchor: {line: 0, character: 11}
active: {line: 0, character: 11}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
languageId: typescript
command:
version: 6
spokenForm: change type
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: type}
usePrePhraseSnapshot: true
initialState:
documentContents: "const foo: Bar<number> = new Bar<number>(foo);"
selections:
- anchor: {line: 0, character: 15}
active: {line: 0, character: 15}
marks: {}
finalState:
documentContents: "const foo: Bar<> = new Bar<number>(foo);"
selections:
- anchor: {line: 0, character: 15}
active: {line: 0, character: 15}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ initialState:
active: {line: 0, character: 18}
marks: {}
finalState:
documentContents: "function whatever<T>(): {}"
documentContents: "function whatever<>(): string {}"
selections:
- anchor: {line: 0, character: 24}
active: {line: 0, character: 24}
- anchor: {line: 0, character: 18}
active: {line: 0, character: 18}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ initialState:
start: {line: 0, character: 28}
end: {line: 0, character: 34}
finalState:
documentContents: "const foo: string = new (foo);"
documentContents: "const foo: string = new Bar<>(foo);"
selections:
- anchor: {line: 0, character: 24}
active: {line: 0, character: 24}
- anchor: {line: 0, character: 28}
active: {line: 0, character: 28}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ initialState:
start: {line: 0, character: 24}
end: {line: 0, character: 30}
finalState:
documentContents: "const foo: = bar<number>(foo);"
documentContents: "const foo: string = bar<>(foo);"
selections:
- anchor: {line: 0, character: 11}
active: {line: 0, character: 11}
- anchor: {line: 0, character: 24}
active: {line: 0, character: 24}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ initialState:
start: {line: 0, character: 15}
end: {line: 0, character: 21}
finalState:
documentContents: "const foo: = new Bar<number>(foo);"
documentContents: "const foo: Bar<> = new Bar<number>(foo);"
selections:
- anchor: {line: 0, character: 11}
active: {line: 0, character: 11}
- anchor: {line: 0, character: 15}
active: {line: 0, character: 15}
17 changes: 17 additions & 0 deletions queries/typescript.core.scm
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,23 @@
type_arguments: (_)? @type.end
)

;;!! useState<string>()
;;! ^^^^^^
;;!! useState<Record<string, string>>()
;;! ^^^^^^^^^^^^^^^^^^^^^^
;;! ^^^^^^ ^^^^^^
(type_arguments
(_) @type
)

;;!! function foo<A>() {}
;;! ^
;;!! const foo = <A>() => {}
;;! ^
(type_parameters
(_) @type
)

;;!! interface Aaa {}
;;!! type Aaa = Bbb;
(
Expand Down

0 comments on commit f577cee

Please sign in to comment.