@@ -16,7 +16,6 @@ import (
1616 "golang.org/x/tools/gopls/internal/cache"
1717 "golang.org/x/tools/gopls/internal/cache/metadata"
1818 "golang.org/x/tools/gopls/internal/protocol"
19- "golang.org/x/tools/gopls/internal/settings"
2019 "golang.org/x/tools/internal/event"
2120)
2221
@@ -69,10 +68,9 @@ func CompilerOptDetails(ctx context.Context, snapshot *cache.Snapshot, mp *metad
6968 return nil , err
7069 }
7170 reports := make (map [protocol.DocumentURI ][]* cache.Diagnostic )
72- opts := snapshot .Options ()
7371 var parseError error
7472 for _ , fn := range files {
75- uri , diagnostics , err := parseDetailsFile (fn , opts )
73+ uri , diagnostics , err := parseDetailsFile (fn )
7674 if err != nil {
7775 // expect errors for all the files, save 1
7876 parseError = err
@@ -93,7 +91,7 @@ func CompilerOptDetails(ctx context.Context, snapshot *cache.Snapshot, mp *metad
9391}
9492
9593// parseDetailsFile parses the file written by the Go compiler which contains a JSON-encoded protocol.Diagnostic.
96- func parseDetailsFile (filename string , options * settings. Options ) (protocol.DocumentURI , []* cache.Diagnostic , error ) {
94+ func parseDetailsFile (filename string ) (protocol.DocumentURI , []* cache.Diagnostic , error ) {
9795 buf , err := os .ReadFile (filename )
9896 if err != nil {
9997 return "" , nil , err
@@ -124,14 +122,30 @@ func parseDetailsFile(filename string, options *settings.Options) (protocol.Docu
124122 if err := dec .Decode (d ); err != nil {
125123 return "" , nil , err
126124 }
125+ if d .Source != "go compiler" {
126+ continue
127+ }
127128 d .Tags = []protocol.DiagnosticTag {} // must be an actual slice
128129 msg := d .Code .(string )
129130 if msg != "" {
131+ // Typical message prefixes gathered by grepping the source of
132+ // cmd/compile for literal arguments in calls to logopt.LogOpt.
133+ // (It is not a well defined set.)
134+ //
135+ // - canInlineFunction
136+ // - cannotInlineCall
137+ // - cannotInlineFunction
138+ // - copy
139+ // - escape
140+ // - escapes
141+ // - isInBounds
142+ // - isSliceInBounds
143+ // - iteration-variable-to-{heap,stack}
144+ // - leak
145+ // - loop-modified-{range,for}
146+ // - nilcheck
130147 msg = fmt .Sprintf ("%s(%s)" , msg , d .Message )
131148 }
132- if ! showDiagnostic (msg , d .Source , options ) {
133- continue
134- }
135149
136150 // zeroIndexedRange subtracts 1 from the line and
137151 // range, because the compiler output neglects to
@@ -176,51 +190,6 @@ func parseDetailsFile(filename string, options *settings.Options) (protocol.Docu
176190 return uri , diagnostics , nil
177191}
178192
179- // showDiagnostic reports whether a given diagnostic should be shown to the end
180- // user, given the current options.
181- func showDiagnostic (msg , source string , o * settings.Options ) bool {
182- if source != "go compiler" {
183- return false
184- }
185- if o .Annotations == nil {
186- return true
187- }
188-
189- // The strings below were gathered by grepping the source of
190- // cmd/compile for literal arguments in calls to logopt.LogOpt.
191- // (It is not a well defined set.)
192- //
193- // - canInlineFunction
194- // - cannotInlineCall
195- // - cannotInlineFunction
196- // - escape
197- // - escapes
198- // - isInBounds
199- // - isSliceInBounds
200- // - leak
201- // - nilcheck
202- //
203- // Additional ones not handled by logic below:
204- // - copy
205- // - iteration-variable-to-{heap,stack}
206- // - loop-modified-{range,for}
207-
208- switch {
209- case strings .HasPrefix (msg , "canInline" ) ||
210- strings .HasPrefix (msg , "cannotInline" ) ||
211- strings .HasPrefix (msg , "inlineCall" ):
212- return o .Annotations [settings .Inline ]
213- case strings .HasPrefix (msg , "escape" ) || msg == "leak" :
214- return o .Annotations [settings .Escape ]
215- case strings .HasPrefix (msg , "nilcheck" ):
216- return o .Annotations [settings .Nil ]
217- case strings .HasPrefix (msg , "isInBounds" ) ||
218- strings .HasPrefix (msg , "isSliceInBounds" ):
219- return o .Annotations [settings .Bounds ]
220- }
221- return false
222- }
223-
224193func findJSONFiles (dir string ) ([]string , error ) {
225194 ans := []string {}
226195 f := func (path string , fi os.FileInfo , _ error ) error {
0 commit comments