mirror of
https://github.com/golang/go
synced 2024-11-18 16:14:46 -07:00
go/analysis/doc: provide more motivation for suggestedfix design
Change-Id: I8139010883357616bf6bfd76b62debe00267164b Reviewed-on: https://go-review.googlesource.com/c/tools/+/192681 Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
56125e7d70
commit
8fa7b020d0
@ -62,19 +62,62 @@ Diagnostic struct:
|
||||
|
||||
type Diagnostic struct {
|
||||
...
|
||||
SuggestedFixes []SuggestedFix // this is an optional field
|
||||
SuggestedFixes []SuggestedFix // this is an optional field
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### Requirements for SuggestedFixes
|
||||
|
||||
SuggestedFixes will be required to conform to several requirements:
|
||||
|
||||
* TextEdits for a SuggestedFix should not overlap.
|
||||
* TextEdits for SuggestedFixes should not contain edits for other packages.
|
||||
* Each TextEdit should apply to a single file.
|
||||
|
||||
These requirements guarantee that suggested fixes can be cleanly applied.
|
||||
Because a driver may only analyze, or be able to modify, the current package,
|
||||
we restrict edits to the current package. In general this restriction should
|
||||
not be a big problem for users because other packages might not belong to the
|
||||
same module and so will not be safe to modify in a singe change.
|
||||
|
||||
On the other hand, analyzers will not be required to produce gofmt-compliant
|
||||
code. Analysis drivers will be expected to apply gofmt to the results of
|
||||
a SuggestedFix application.
|
||||
|
||||
## SuggestedFix integration points
|
||||
|
||||
### ```checker -fix```
|
||||
|
||||
Singlechecker and multichecker have the ```-fix``` flag, which will automatically
|
||||
apply all fixes suggested by their analysis or analyses. This is intended to
|
||||
be used primarily by refactoring tools, because in general, like diagnostics,
|
||||
suggested fixes will need to be examined by a human who can decide whether
|
||||
they are relevent.
|
||||
|
||||
### gopls
|
||||
|
||||
Suggested fixes have been integrated into ```gopls```, and editors can choose
|
||||
to display the suggested fixes to the user as they type, so that they can be
|
||||
accepted to fix diagnostics immediately.
|
||||
|
||||
### Code Review Tools (Future Work)
|
||||
|
||||
Suggested fixes can be integrated into programs that are integrated with
|
||||
code review systems to suggest fixes that users can apply from their code review tools.
|
||||
|
||||
## Alternatives
|
||||
|
||||
# Performing transformations directly on the AST
|
||||
|
||||
TODO(matloob): expand on this.
|
||||
### Performing transformations directly on the AST
|
||||
|
||||
Even though it may be more convienient
|
||||
for authors of refactorings to perform transformations directly on
|
||||
the AST, allowing mutations on the AST would mean that a copy of the AST
|
||||
would need to be made every time a transformation was produced, to avoid
|
||||
having transformations interfere with each other.
|
||||
|
||||
This is primarily an issue with the current design of the Go AST and
|
||||
it's possible that a new future version of the AST might make this a more
|
||||
viable option.
|
||||
|
||||
### Supplying AST nodes directly
|
Loading…
Reference in New Issue
Block a user