From 3a3c16941ee28ac5c2913ea3fbe4bbc293236735 Mon Sep 17 00:00:00 2001 From: Viktor Blomqvist Date: Fri, 28 Jul 2023 10:01:10 +0200 Subject: [PATCH] gopls/internal/lsp/source: refresh embeddirective analyzer docs Bring the analyzer documentation up to speed. Include the recently added feature to check the declaration following the directive. Also fix typo in package comment. Updates golang/go#50262 Change-Id: I0e7a8de0ba10cd414251afe1e9c65ded2090f408 Reviewed-on: https://go-review.googlesource.com/c/tools/+/513895 Reviewed-by: Robert Findley TryBot-Result: Gopher Robot Run-TryBot: Robert Findley Reviewed-by: Hyang-Ah Hana Kim gopls-CI: kokoro --- gopls/doc/analyzers.md | 10 +++++++--- .../lsp/analysis/embeddirective/embeddirective.go | 12 ++++++++---- gopls/internal/lsp/source/api_json.go | 4 ++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/gopls/doc/analyzers.md b/gopls/doc/analyzers.md index c6893a6be3a..8f470e25d25 100644 --- a/gopls/doc/analyzers.md +++ b/gopls/doc/analyzers.md @@ -141,10 +141,14 @@ buildtag analyzer. ## **embed** -check for //go:embed directive import +check //go:embed directive usage -This analyzer checks that the embed package is imported when source code contains //go:embed comment directives. -The embed package must be imported for //go:embed directives to function.import _ "embed". +This analyzer checks that the embed package is imported if //go:embed +directives are present, providing a suggested fix to add the import if +it is missing. + +This analyzer also checks that //go:embed directives precede the +declaration of a single variable. **Enabled by default.** diff --git a/gopls/internal/lsp/analysis/embeddirective/embeddirective.go b/gopls/internal/lsp/analysis/embeddirective/embeddirective.go index 8cc4ea57443..b7efe4753d4 100644 --- a/gopls/internal/lsp/analysis/embeddirective/embeddirective.go +++ b/gopls/internal/lsp/analysis/embeddirective/embeddirective.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // Package embeddirective defines an Analyzer that validates //go:embed directives. -// The analyzer defers fixes to it's parent source.Analyzer. +// The analyzer defers fixes to its parent source.Analyzer. package embeddirective import ( @@ -14,10 +14,14 @@ import ( "golang.org/x/tools/go/analysis" ) -const Doc = `check for //go:embed directive import +const Doc = `check //go:embed directive usage -This analyzer checks that the embed package is imported when source code contains //go:embed comment directives. -The embed package must be imported for //go:embed directives to function.import _ "embed".` +This analyzer checks that the embed package is imported if //go:embed +directives are present, providing a suggested fix to add the import if +it is missing. + +This analyzer also checks that //go:embed directives precede the +declaration of a single variable.` var Analyzer = &analysis.Analyzer{ Name: "embed", diff --git a/gopls/internal/lsp/source/api_json.go b/gopls/internal/lsp/source/api_json.go index 60103b0a1b2..153cb7d6e9a 100644 --- a/gopls/internal/lsp/source/api_json.go +++ b/gopls/internal/lsp/source/api_json.go @@ -280,7 +280,7 @@ var GeneratedAPIJSON = &APIJSON{ }, { Name: "\"embed\"", - Doc: "check for //go:embed directive import\n\nThis analyzer checks that the embed package is imported when source code contains //go:embed comment directives.\nThe embed package must be imported for //go:embed directives to function.import _ \"embed\".", + Doc: "check //go:embed directive usage\n\nThis analyzer checks that the embed package is imported if //go:embed\ndirectives are present, providing a suggested fix to add the import if\nit is missing.\n\nThis analyzer also checks that //go:embed directives precede the\ndeclaration of a single variable.", Default: "true", }, { @@ -979,7 +979,7 @@ var GeneratedAPIJSON = &APIJSON{ }, { Name: "embed", - Doc: "check for //go:embed directive import\n\nThis analyzer checks that the embed package is imported when source code contains //go:embed comment directives.\nThe embed package must be imported for //go:embed directives to function.import _ \"embed\".", + Doc: "check //go:embed directive usage\n\nThis analyzer checks that the embed package is imported if //go:embed\ndirectives are present, providing a suggested fix to add the import if\nit is missing.\n\nThis analyzer also checks that //go:embed directives precede the\ndeclaration of a single variable.", Default: true, }, {