-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Edit/Chat: Always expand to the nearest enclosing function, if availa…
…ble, before folding ranges (#3507)
- Loading branch information
Showing
17 changed files
with
555 additions
and
7 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
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
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
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
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
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
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
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
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
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
41 changes: 41 additions & 0 deletions
41
vscode/src/tree-sitter/query-tests/enclosing-function.test.ts
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,41 @@ | ||
import { describe, it } from 'vitest' | ||
|
||
import { initTreeSitterSDK } from '../test-helpers' | ||
|
||
import { SupportedLanguage } from '../grammars' | ||
import { annotateAndMatchSnapshot } from './annotate-and-match-snapshot' | ||
|
||
describe('getEnclosingFunction', () => { | ||
it('typescript', async () => { | ||
const { language, parser, queries } = await initTreeSitterSDK(SupportedLanguage.typescript) | ||
|
||
await annotateAndMatchSnapshot({ | ||
parser, | ||
language, | ||
captures: queries.getEnclosingFunction, | ||
sourcesPath: 'test-data/enclosing-function.ts', | ||
}) | ||
}) | ||
|
||
it('python', async () => { | ||
const { language, parser, queries } = await initTreeSitterSDK(SupportedLanguage.python) | ||
|
||
await annotateAndMatchSnapshot({ | ||
parser, | ||
language, | ||
captures: queries.getEnclosingFunction, | ||
sourcesPath: 'test-data/enclosing-function.py', | ||
}) | ||
}) | ||
|
||
it('go', async () => { | ||
const { language, parser, queries } = await initTreeSitterSDK(SupportedLanguage.go) | ||
|
||
await annotateAndMatchSnapshot({ | ||
parser, | ||
language, | ||
captures: queries.getEnclosingFunction, | ||
sourcesPath: 'test-data/enclosing-function.go', | ||
}) | ||
}) | ||
}) |
49 changes: 49 additions & 0 deletions
49
vscode/src/tree-sitter/query-tests/test-data/enclosing-function.go
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,49 @@ | ||
func nestedVar() { | ||
y := 4 | ||
// | | ||
} | ||
|
||
// ------------------------------------ | ||
|
||
func greet() { | ||
// | | ||
} | ||
|
||
// ------------------------------------ | ||
|
||
func (u User) DisplayName() string { | ||
return u.FirstName + " " + u.LastName | ||
// | | ||
} | ||
|
||
// ------------------------------------ | ||
|
||
func funcFactory(mystring string) func(before, after string) string { | ||
return func(before, after string) string { | ||
return fmt.Sprintf("%s %s %s", before, mystring, after) | ||
// | | ||
} | ||
} | ||
|
||
// ------------------------------------ | ||
|
||
func funcFactory(mystring string) func(before, after string) string { | ||
// | | ||
return func(before, after string) string { | ||
return fmt.Sprintf("%s %s %s", before, mystring, after) | ||
} | ||
} | ||
|
||
// ------------------------------------ | ||
|
||
func() { | ||
fmt.Println("I'm an anonymous function!") | ||
// | | ||
}() | ||
|
||
// ------------------------------------ | ||
|
||
var varFunction = func(name string) { | ||
fmt.Println("Hello,", name) | ||
// | | ||
} |
40 changes: 40 additions & 0 deletions
40
vscode/src/tree-sitter/query-tests/test-data/enclosing-function.py
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,40 @@ | ||
def wrapper(): | ||
print('wrapper') | ||
def test(): | ||
pass | ||
# | | ||
|
||
# ------------------------------------ | ||
|
||
def test(): | ||
pass | ||
# | | ||
|
||
# ------------------------------------ | ||
|
||
def test_parameter(val): | ||
# | | ||
wrapper() | ||
|
||
# ------------------------------------ | ||
|
||
class Agent: | ||
pass | ||
# | | ||
|
||
# ------------------------------------ | ||
|
||
class Agent: | ||
def __init__(self, name): | ||
self.name = name | ||
# | | ||
|
||
# ------------------------------------ | ||
|
||
class Agent: | ||
def __init__(self, name): | ||
self.name = name | ||
|
||
def test(self): | ||
pass | ||
# | |
Oops, something went wrong.