forked from golang/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gopls/internal/lsp/source: put context first in extracted functions
Put the context first when extracting functions/methods Fixes golang/go#60738
- Loading branch information
1 parent
db6a81e
commit a979900
Showing
6 changed files
with
62 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
13 changes: 13 additions & 0 deletions
13
gopls/internal/lsp/testdata/extract/extract_method/extract_context.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,13 @@ | ||
package extract | ||
|
||
import "context" | ||
|
||
type A struct { | ||
x int | ||
y int | ||
} | ||
|
||
func (a *A) AddP(ctx context.Context) (int, error) { | ||
sum := a.x + a.y | ||
return sum, ctx.Err() //@extractmethod("return", "ctx.Err()"),extractfunc("return", "ctx.Err()") | ||
} |
19 changes: 19 additions & 0 deletions
19
gopls/internal/lsp/testdata/extract/extract_method/extract_context.go.golden
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,19 @@ | ||
-- methodextraction_extract_context_12_2 -- | ||
package extract | ||
|
||
import "context" | ||
|
||
type A struct { | ||
x int | ||
y int | ||
} | ||
|
||
func (a *A) AddP(ctx context.Context) (int, error) { | ||
sum := a.x + a.y | ||
return a.newMethod(ctx, sum) //@extractmethod("return", "ctx.Err()"),extractfunc("return", "ctx.Err()") | ||
} | ||
|
||
func (*A) newMethod(ctx context.Context, sum int) (int, error) { | ||
return sum, ctx.Err() | ||
} | ||
|
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