Skip to content

Commit 93918bd

Browse files
authored
migrate Go scopes map and list to treesitter (#1724)
## 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 a84b635 commit 93918bd

File tree

18 files changed

+597
-2
lines changed

18 files changed

+597
-2
lines changed

data/playground/go/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module cursorless.org
2+
3+
go 1.20

data/playground/go/maps_and_lists.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package p
2+
3+
type S struct {
4+
one, a int
5+
}
6+
7+
type (
8+
A [2]any
9+
AA [3]A
10+
AS [2]S
11+
M map[any]int
12+
)
13+
14+
const one = 1
15+
16+
func mapsAndLists() {
17+
_ = A{}
18+
_ = A{1}
19+
_ = A{1, 2}
20+
_ = A{1: 1}
21+
_ = S{a: 1}
22+
_ = M{"a": 1}
23+
_ = M{"a": 1, 1: 1}
24+
_ = AS{{}}
25+
_ = AA{{1}}
26+
_ = AS{{a: 1}}
27+
_ = AA{{1}, {one: 1}}
28+
_ = AA{{1}, {}, {one: 1}}
29+
_ = &A{}
30+
_ = &A{1}
31+
_ = &A{one: 1}
32+
_ = &A{1: 1}
33+
}

data/playground/go/statements.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package p
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
)
7+
8+
func statements() error {
9+
fmt.Println("hello")
10+
if b := false; b {
11+
return nil
12+
}
13+
c := make(chan int, 1)
14+
c <- 1
15+
<-c
16+
var x int
17+
x = 1
18+
x++
19+
{
20+
type T int
21+
const two T = 2
22+
var x T = 1
23+
x--
24+
x /= two
25+
}
26+
for {
27+
break
28+
}
29+
defer func() {
30+
recover()
31+
}()
32+
go func() {
33+
fmt.Println("concurrency is not parallelism")
34+
}()
35+
var a any = "how long is a piece of me?"
36+
switch a := a.(type) {
37+
case int:
38+
panic("wow")
39+
default:
40+
_ = a
41+
}
42+
switch {
43+
case x != 2:
44+
fallthrough
45+
case x == 1:
46+
break
47+
}
48+
Again:
49+
switch x {
50+
case 1:
51+
x &= 1
52+
goto Again
53+
case 2:
54+
return fmt.Errorf("%v", x*2+x/3)
55+
}
56+
Label:
57+
for x := 0; x < 10; x++ {
58+
if x == 0 {
59+
continue
60+
}
61+
if x == 1 {
62+
break Label
63+
}
64+
fmt.Println(x)
65+
}
66+
return errors.New("error")
67+
}

packages/cursorless-engine/src/languages/go.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import { SimpleScopeTypeType } from "@cursorless/common";
1111
const nodeMatchers: Partial<
1212
Record<SimpleScopeTypeType, NodeMatcherAlternative>
1313
> = {
14-
map: "composite_literal",
15-
list: ["composite_literal", "slice_type", "array_type"],
1614
ifStatement: "if_statement",
1715
functionCall: ["call_expression", "composite_literal"],
1816
functionCallee: ["call_expression[function]", "composite_literal[type]"],
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
languageId: go
2+
command:
3+
version: 6
4+
spokenForm: change list one
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: list}
12+
mark: {type: decoratedSymbol, symbolColor: default, character: '1'}
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: _ = T{{1}}
16+
selections:
17+
- anchor: {line: 0, character: 10}
18+
active: {line: 0, character: 10}
19+
marks:
20+
default.1:
21+
start: {line: 0, character: 7}
22+
end: {line: 0, character: 8}
23+
finalState:
24+
documentContents: _ = T{}
25+
selections:
26+
- anchor: {line: 0, character: 6}
27+
active: {line: 0, character: 6}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
languageId: go
2+
command:
3+
version: 6
4+
spokenForm: change list one
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: list}
12+
mark: {type: decoratedSymbol, symbolColor: default, character: '1'}
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: "_ = T{{1, 2: \"a\"}}"
16+
selections:
17+
- anchor: {line: 0, character: 18}
18+
active: {line: 0, character: 18}
19+
marks:
20+
default.1:
21+
start: {line: 0, character: 7}
22+
end: {line: 0, character: 8}
23+
finalState:
24+
documentContents: _ = T{}
25+
selections:
26+
- anchor: {line: 0, character: 6}
27+
active: {line: 0, character: 6}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
languageId: go
2+
command:
3+
version: 6
4+
spokenForm: change list trap
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: list}
12+
mark: {type: decoratedSymbol, symbolColor: default, character: t}
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: _ = &T{}
16+
selections:
17+
- anchor: {line: 0, character: 0}
18+
active: {line: 0, character: 0}
19+
marks:
20+
default.t:
21+
start: {line: 0, character: 5}
22+
end: {line: 0, character: 6}
23+
finalState:
24+
documentContents: "_ = "
25+
selections:
26+
- anchor: {line: 0, character: 4}
27+
active: {line: 0, character: 4}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
languageId: go
2+
command:
3+
version: 6
4+
spokenForm: change list trap
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: list}
12+
mark: {type: decoratedSymbol, symbolColor: default, character: t}
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: _ = &T{1}
16+
selections:
17+
- anchor: {line: 0, character: 0}
18+
active: {line: 0, character: 0}
19+
marks:
20+
default.t:
21+
start: {line: 0, character: 5}
22+
end: {line: 0, character: 6}
23+
finalState:
24+
documentContents: "_ = "
25+
selections:
26+
- anchor: {line: 0, character: 4}
27+
active: {line: 0, character: 4}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
languageId: go
2+
command:
3+
version: 6
4+
spokenForm: change list trap
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: list}
12+
mark: {type: decoratedSymbol, symbolColor: default, character: t}
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: _ = T{}
16+
selections:
17+
- anchor: {line: 0, character: 7}
18+
active: {line: 0, character: 7}
19+
marks:
20+
default.t:
21+
start: {line: 0, character: 4}
22+
end: {line: 0, character: 5}
23+
finalState:
24+
documentContents: "_ = "
25+
selections:
26+
- anchor: {line: 0, character: 4}
27+
active: {line: 0, character: 4}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
languageId: go
2+
command:
3+
version: 6
4+
spokenForm: change list trap
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: list}
12+
mark: {type: decoratedSymbol, symbolColor: default, character: t}
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: "_ = T{1, 2: \"a\"}"
16+
selections:
17+
- anchor: {line: 0, character: 16}
18+
active: {line: 0, character: 16}
19+
marks:
20+
default.t:
21+
start: {line: 0, character: 4}
22+
end: {line: 0, character: 5}
23+
finalState:
24+
documentContents: "_ = "
25+
selections:
26+
- anchor: {line: 0, character: 4}
27+
active: {line: 0, character: 4}

0 commit comments

Comments
 (0)