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: add code actions to remove unused parameters
Use the new inlining technology to implement a first change-signature refactoring, by rewriting the declaration to be a trivial wrapper around a declaration with modified signature, inlining the wrapper, and then performing string substitution to replace references to the synthetic delegate. This demonstrates the power of inlining, which can be seen as a more general tool for rewriting source code: express old code as new code, recognize instances of old code (in this case, calls), and inline. However, this CL was still rather difficult, primarily because of (1) the problem of manipulating syntax without breaking formatting and comments, and (2) the problem of composing multiple refactoring operations, which in general requires iterative type checking. Neither of those difficulties have general solutions: any form of nontrivial AST manipulation tends to result in an unacceptable movement of comments, and iterative type checking is difficult because it may involve an arbitrarily modified package graph, and because it is difficult to correlate references in the previous version of the package with references in the new version of the package. But in the case of removing a parameter, these problems are solvable: We can avoid most AST mangling by restricting the scope of rewriting to the function signature. We can type check the new package using the imports of the old package. We can find the next reference in the new package by counting. Fixes golang/go#63534 Change-Id: Iba5fa6b0da503b7723bea1b43fd2c4151576a672 Reviewed-on: https://go-review.googlesource.com/c/tools/+/532495 Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Robert Findley <[email protected]>
- Loading branch information
Showing
21 changed files
with
1,655 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// The stringintconv command runs the stringintconv analyzer. | ||
package main | ||
|
||
import ( | ||
"golang.org/x/tools/go/analysis/singlechecker" | ||
"golang.org/x/tools/gopls/internal/lsp/analysis/unusedparams" | ||
) | ||
|
||
func main() { singlechecker.Main(unusedparams.Analyzer) } |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.