internal/settings: add inliner to analyses

This analyzer will supply a code action on a call to a function
that is annotated "//go:fix inline".

Updates golang/go#32816.

Change-Id: I9e0da21a4e1cb8dd9c167099108c7d8adfcaf012
Reviewed-on: https://go-review.googlesource.com/c/tools/+/645155
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
diff --git a/gopls/doc/analyzers.md b/gopls/doc/analyzers.md
index aa0081d..282a9f4 100644
--- a/gopls/doc/analyzers.md
+++ b/gopls/doc/analyzers.md
@@ -376,6 +376,15 @@
 
 Package documentation: [infertypeargs](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/infertypeargs)
 
+<a id='inline'></a>
+## `inline`: inline calls to functions with "//go:fix inline" doc comment
+
+
+
+Default: on.
+
+Package documentation: [inline](https://pkg.go.dev/golang.org/x/tools/internal/refactor/inline/analyzer)
+
 <a id='loopclosure'></a>
 ## `loopclosure`: check references to loop variables from within nested functions
 
diff --git a/gopls/internal/doc/api.json b/gopls/internal/doc/api.json
index 0439072..83151ae 100644
--- a/gopls/internal/doc/api.json
+++ b/gopls/internal/doc/api.json
@@ -494,6 +494,11 @@
 							"Default": "true"
 						},
 						{
+							"Name": "\"inline\"",
+							"Doc": "inline calls to functions with \"//go:fix inline\" doc comment",
+							"Default": "true"
+						},
+						{
 							"Name": "\"loopclosure\"",
 							"Doc": "check references to loop variables from within nested functions\n\nThis analyzer reports places where a function literal references the\niteration variable of an enclosing loop, and the loop calls the function\nin such a way (e.g. with go or defer) that it may outlive the loop\niteration and possibly observe the wrong value of the variable.\n\nNote: An iteration variable can only outlive a loop iteration in Go versions \u003c=1.21.\nIn Go 1.22 and later, the loop variable lifetimes changed to create a new\niteration variable per loop iteration. (See go.dev/issue/60078.)\n\nIn this example, all the deferred functions run after the loop has\ncompleted, so all observe the final value of v [\u003cgo1.22].\n\n\tfor _, v := range list {\n\t    defer func() {\n\t        use(v) // incorrect\n\t    }()\n\t}\n\nOne fix is to create a new variable for each iteration of the loop:\n\n\tfor _, v := range list {\n\t    v := v // new var per iteration\n\t    defer func() {\n\t        use(v) // ok\n\t    }()\n\t}\n\nAfter Go version 1.22, the previous two for loops are equivalent\nand both are correct.\n\nThe next example uses a go statement and has a similar problem [\u003cgo1.22].\nIn addition, it has a data race because the loop updates v\nconcurrent with the goroutines accessing it.\n\n\tfor _, v := range elem {\n\t    go func() {\n\t        use(v)  // incorrect, and a data race\n\t    }()\n\t}\n\nA fix is the same as before. The checker also reports problems\nin goroutines started by golang.org/x/sync/errgroup.Group.\nA hard-to-spot variant of this form is common in parallel tests:\n\n\tfunc Test(t *testing.T) {\n\t    for _, test := range tests {\n\t        t.Run(test.name, func(t *testing.T) {\n\t            t.Parallel()\n\t            use(test) // incorrect, and a data race\n\t        })\n\t    }\n\t}\n\nThe t.Parallel() call causes the rest of the function to execute\nconcurrent with the loop [\u003cgo1.22].\n\nThe analyzer reports references only in the last statement,\nas it is not deep enough to understand the effects of subsequent\nstatements that might render the reference benign.\n(\"Last statement\" is defined recursively in compound\nstatements such as if, switch, and select.)\n\nSee: https://golang.org/doc/go_faq.html#closures_and_goroutines",
 							"Default": "true"
@@ -1165,6 +1170,12 @@
 			"Default": true
 		},
 		{
+			"Name": "inline",
+			"Doc": "inline calls to functions with \"//go:fix inline\" doc comment",
+			"URL": "https://pkg.go.dev/golang.org/x/tools/internal/refactor/inline/analyzer",
+			"Default": true
+		},
+		{
 			"Name": "loopclosure",
 			"Doc": "check references to loop variables from within nested functions\n\nThis analyzer reports places where a function literal references the\niteration variable of an enclosing loop, and the loop calls the function\nin such a way (e.g. with go or defer) that it may outlive the loop\niteration and possibly observe the wrong value of the variable.\n\nNote: An iteration variable can only outlive a loop iteration in Go versions \u003c=1.21.\nIn Go 1.22 and later, the loop variable lifetimes changed to create a new\niteration variable per loop iteration. (See go.dev/issue/60078.)\n\nIn this example, all the deferred functions run after the loop has\ncompleted, so all observe the final value of v [\u003cgo1.22].\n\n\tfor _, v := range list {\n\t    defer func() {\n\t        use(v) // incorrect\n\t    }()\n\t}\n\nOne fix is to create a new variable for each iteration of the loop:\n\n\tfor _, v := range list {\n\t    v := v // new var per iteration\n\t    defer func() {\n\t        use(v) // ok\n\t    }()\n\t}\n\nAfter Go version 1.22, the previous two for loops are equivalent\nand both are correct.\n\nThe next example uses a go statement and has a similar problem [\u003cgo1.22].\nIn addition, it has a data race because the loop updates v\nconcurrent with the goroutines accessing it.\n\n\tfor _, v := range elem {\n\t    go func() {\n\t        use(v)  // incorrect, and a data race\n\t    }()\n\t}\n\nA fix is the same as before. The checker also reports problems\nin goroutines started by golang.org/x/sync/errgroup.Group.\nA hard-to-spot variant of this form is common in parallel tests:\n\n\tfunc Test(t *testing.T) {\n\t    for _, test := range tests {\n\t        t.Run(test.name, func(t *testing.T) {\n\t            t.Parallel()\n\t            use(test) // incorrect, and a data race\n\t        })\n\t    }\n\t}\n\nThe t.Parallel() call causes the rest of the function to execute\nconcurrent with the loop [\u003cgo1.22].\n\nThe analyzer reports references only in the last statement,\nas it is not deep enough to understand the effects of subsequent\nstatements that might render the reference benign.\n(\"Last statement\" is defined recursively in compound\nstatements such as if, switch, and select.)\n\nSee: https://golang.org/doc/go_faq.html#closures_and_goroutines",
 			"URL": "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/loopclosure",
diff --git a/gopls/internal/settings/analysis.go b/gopls/internal/settings/analysis.go
index 7be5d89..cd0254e 100644
--- a/gopls/internal/settings/analysis.go
+++ b/gopls/internal/settings/analysis.go
@@ -62,6 +62,7 @@
 	"golang.org/x/tools/gopls/internal/analysis/unusedvariable"
 	"golang.org/x/tools/gopls/internal/analysis/yield"
 	"golang.org/x/tools/gopls/internal/protocol"
+	inline "golang.org/x/tools/internal/refactor/inline/analyzer"
 )
 
 // Analyzer augments a [analysis.Analyzer] with additional LSP configuration.
@@ -210,6 +211,7 @@
 			severity:    protocol.SeverityInformation,
 		},
 		// other simplifiers
+		{analyzer: inline.Analyzer, severity: protocol.SeverityHint},
 		{analyzer: infertypeargs.Analyzer, severity: protocol.SeverityInformation},
 		{analyzer: unusedparams.Analyzer, severity: protocol.SeverityInformation},
 		{analyzer: unusedfunc.Analyzer, severity: protocol.SeverityInformation},
diff --git a/gopls/internal/test/marker/doc.go b/gopls/internal/test/marker/doc.go
index abddbdd..dff8dfa 100644
--- a/gopls/internal/test/marker/doc.go
+++ b/gopls/internal/test/marker/doc.go
@@ -120,7 +120,7 @@
     argument may be specified only as a string or regular expression in the
     first pass.
 
-  - defloc(name, location): performs a textDocument/defintiion request at the
+  - defloc(name, location): performs a textDocument/definition request at the
     src location, and binds the result to the given name. This may be used to
     refer to positions in the standard library.
 
diff --git a/gopls/internal/test/marker/testdata/diagnostics/analyzers.txt b/gopls/internal/test/marker/testdata/diagnostics/analyzers.txt
index 7ba3380..459ff98 100644
--- a/gopls/internal/test/marker/testdata/diagnostics/analyzers.txt
+++ b/gopls/internal/test/marker/testdata/diagnostics/analyzers.txt
@@ -74,6 +74,14 @@
 	}()
 }
 
+// inline
+func _() {
+	f()  //@diag("f", re"inline call of analyzer.f")
+} 
+
+//go:fix inline
+func f() { fmt.Println(1) }
+
 -- cgocall/cgocall.go --
 package cgocall