-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate Go func, func name, and lambda to treesitter (#1756)
The previous definitions were mostly correct, although they were missing the possibility of declaring a function without a body. (Understandably. They are rare.) See the end of https://go.dev/ref/spec#Function_declarations. ## 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
- Loading branch information
Showing
21 changed files
with
547 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package p | ||
|
||
func plainOldFunction() { | ||
go func() { | ||
// anonymous function | ||
}() | ||
_ = func() string { | ||
return "x" | ||
} | ||
} | ||
|
||
func genericFunction[T int | int64](x T) T { | ||
if x == 0 { | ||
panic("zero") | ||
} | ||
return x | ||
} | ||
|
||
func (a A) method() { | ||
defer func() { | ||
recover() | ||
}() | ||
[]func(){ | ||
func() { panic(0) }, | ||
func() { panic(1) }, | ||
}[a[0].(int)]() | ||
} | ||
|
||
func stub() string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/go/changeFunk.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
languageId: go | ||
command: | ||
version: 6 | ||
spokenForm: change funk | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: namedFunction} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: _ = func() { /* body */ } | ||
selections: | ||
- anchor: {line: 0, character: 25} | ||
active: {line: 0, character: 25} | ||
marks: {} | ||
finalState: | ||
documentContents: "_ = " | ||
selections: | ||
- anchor: {line: 0, character: 4} | ||
active: {line: 0, character: 4} |
27 changes: 27 additions & 0 deletions
27
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/go/changeFunkAir.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
languageId: go | ||
command: | ||
version: 6 | ||
spokenForm: change funk air | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: namedFunction} | ||
mark: {type: decoratedSymbol, symbolColor: default, character: a} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: func f[X any]() { /* body */ } | ||
selections: | ||
- anchor: {line: 0, character: 30} | ||
active: {line: 0, character: 30} | ||
marks: | ||
default.a: | ||
start: {line: 0, character: 9} | ||
end: {line: 0, character: 12} | ||
finalState: | ||
documentContents: "" | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} |
27 changes: 27 additions & 0 deletions
27
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/go/changeFunkBat.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
languageId: go | ||
command: | ||
version: 6 | ||
spokenForm: change funk bat | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: namedFunction} | ||
mark: {type: decoratedSymbol, symbolColor: default, character: b} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: func f() { /* body */ } | ||
selections: | ||
- anchor: {line: 0, character: 18} | ||
active: {line: 0, character: 18} | ||
marks: | ||
default.b: | ||
start: {line: 0, character: 14} | ||
end: {line: 0, character: 18} | ||
finalState: | ||
documentContents: "" | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} |
27 changes: 27 additions & 0 deletions
27
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/go/changeFunkBat2.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
languageId: go | ||
command: | ||
version: 6 | ||
spokenForm: change funk bat | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: namedFunction} | ||
mark: {type: decoratedSymbol, symbolColor: default, character: b} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: func (t T) f() { /* body */ } | ||
selections: | ||
- anchor: {line: 0, character: 29} | ||
active: {line: 0, character: 29} | ||
marks: | ||
default.b: | ||
start: {line: 0, character: 20} | ||
end: {line: 0, character: 24} | ||
finalState: | ||
documentContents: "" | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} |
27 changes: 27 additions & 0 deletions
27
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/go/changeFunkFine.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
languageId: go | ||
command: | ||
version: 6 | ||
spokenForm: change funk fine | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: namedFunction} | ||
mark: {type: decoratedSymbol, symbolColor: default, character: f} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: func f() { /* body */ } | ||
selections: | ||
- anchor: {line: 0, character: 18} | ||
active: {line: 0, character: 18} | ||
marks: | ||
default.f: | ||
start: {line: 0, character: 5} | ||
end: {line: 0, character: 6} | ||
finalState: | ||
documentContents: "" | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} |
27 changes: 27 additions & 0 deletions
27
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/go/changeFunkFine2.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
languageId: go | ||
command: | ||
version: 6 | ||
spokenForm: change funk fine | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: namedFunction} | ||
mark: {type: decoratedSymbol, symbolColor: default, character: f} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: func (t T) f() { /* body */ } | ||
selections: | ||
- anchor: {line: 0, character: 29} | ||
active: {line: 0, character: 29} | ||
marks: | ||
default.f: | ||
start: {line: 0, character: 11} | ||
end: {line: 0, character: 12} | ||
finalState: | ||
documentContents: "" | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} |
27 changes: 27 additions & 0 deletions
27
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/go/changeFunkFine3.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
languageId: go | ||
command: | ||
version: 6 | ||
spokenForm: change funk fine | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: namedFunction} | ||
mark: {type: decoratedSymbol, symbolColor: default, character: f} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: func f() | ||
selections: | ||
- anchor: {line: 0, character: 8} | ||
active: {line: 0, character: 8} | ||
marks: | ||
default.f: | ||
start: {line: 0, character: 5} | ||
end: {line: 0, character: 6} | ||
finalState: | ||
documentContents: "" | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} |
27 changes: 27 additions & 0 deletions
27
...ages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/go/changeFunkNameBat.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
languageId: go | ||
command: | ||
version: 6 | ||
spokenForm: change funk name bat | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: functionName} | ||
mark: {type: decoratedSymbol, symbolColor: default, character: b} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: func f() { /* body */ } | ||
selections: | ||
- anchor: {line: 0, character: 18} | ||
active: {line: 0, character: 18} | ||
marks: | ||
default.b: | ||
start: {line: 0, character: 14} | ||
end: {line: 0, character: 18} | ||
finalState: | ||
documentContents: func () { /* body */ } | ||
selections: | ||
- anchor: {line: 0, character: 5} | ||
active: {line: 0, character: 5} |
27 changes: 27 additions & 0 deletions
27
...ges/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/go/changeFunkNameFine.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
languageId: go | ||
command: | ||
version: 6 | ||
spokenForm: change funk name fine | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: functionName} | ||
mark: {type: decoratedSymbol, symbolColor: default, character: f} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: func f() { /* body */ } | ||
selections: | ||
- anchor: {line: 0, character: 18} | ||
active: {line: 0, character: 18} | ||
marks: | ||
default.f: | ||
start: {line: 0, character: 5} | ||
end: {line: 0, character: 6} | ||
finalState: | ||
documentContents: func () { /* body */ } | ||
selections: | ||
- anchor: {line: 0, character: 5} | ||
active: {line: 0, character: 5} |
27 changes: 27 additions & 0 deletions
27
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/go/changeFunkTrap.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
languageId: go | ||
command: | ||
version: 6 | ||
spokenForm: change funk trap | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: namedFunction} | ||
mark: {type: decoratedSymbol, symbolColor: default, character: t} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: func (t T) f() { /* body */ } | ||
selections: | ||
- anchor: {line: 0, character: 29} | ||
active: {line: 0, character: 29} | ||
marks: | ||
default.t: | ||
start: {line: 0, character: 8} | ||
end: {line: 0, character: 9} | ||
finalState: | ||
documentContents: "" | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} |
24 changes: 24 additions & 0 deletions
24
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/go/changeInsideFunk.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
languageId: go | ||
command: | ||
version: 6 | ||
spokenForm: change inside funk | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- {type: interiorOnly} | ||
- type: containingScope | ||
scopeType: {type: namedFunction} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: "func (t T) f() {\n\t_ = 1\n}" | ||
selections: | ||
- anchor: {line: 1, character: 6} | ||
active: {line: 1, character: 6} | ||
marks: {} | ||
finalState: | ||
documentContents: "func (t T) f() {\n\t\n}" | ||
selections: | ||
- anchor: {line: 1, character: 1} | ||
active: {line: 1, character: 1} |
28 changes: 28 additions & 0 deletions
28
...es/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/go/changeInsideFunkBat.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
languageId: go | ||
command: | ||
version: 6 | ||
spokenForm: change inside funk bat | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- {type: interiorOnly} | ||
- type: containingScope | ||
scopeType: {type: namedFunction} | ||
mark: {type: decoratedSymbol, symbolColor: default, character: b} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: func f() { /* body */ } | ||
selections: | ||
- anchor: {line: 0, character: 18} | ||
active: {line: 0, character: 18} | ||
marks: | ||
default.b: | ||
start: {line: 0, character: 14} | ||
end: {line: 0, character: 18} | ||
finalState: | ||
documentContents: func f() { } | ||
selections: | ||
- anchor: {line: 0, character: 11} | ||
active: {line: 0, character: 11} |
Oops, something went wrong.