@@ -16,7 +16,6 @@ import (
16
16
"golang.org/x/tools/gopls/internal/cache"
17
17
"golang.org/x/tools/gopls/internal/cache/metadata"
18
18
"golang.org/x/tools/gopls/internal/protocol"
19
- "golang.org/x/tools/gopls/internal/settings"
20
19
"golang.org/x/tools/internal/event"
21
20
)
22
21
@@ -69,10 +68,9 @@ func CompilerOptDetails(ctx context.Context, snapshot *cache.Snapshot, mp *metad
69
68
return nil , err
70
69
}
71
70
reports := make (map [protocol.DocumentURI ][]* cache.Diagnostic )
72
- opts := snapshot .Options ()
73
71
var parseError error
74
72
for _ , fn := range files {
75
- uri , diagnostics , err := parseDetailsFile (fn , opts )
73
+ uri , diagnostics , err := parseDetailsFile (fn )
76
74
if err != nil {
77
75
// expect errors for all the files, save 1
78
76
parseError = err
@@ -93,7 +91,7 @@ func CompilerOptDetails(ctx context.Context, snapshot *cache.Snapshot, mp *metad
93
91
}
94
92
95
93
// 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 ) {
97
95
buf , err := os .ReadFile (filename )
98
96
if err != nil {
99
97
return "" , nil , err
@@ -124,14 +122,30 @@ func parseDetailsFile(filename string, options *settings.Options) (protocol.Docu
124
122
if err := dec .Decode (d ); err != nil {
125
123
return "" , nil , err
126
124
}
125
+ if d .Source != "go compiler" {
126
+ continue
127
+ }
127
128
d .Tags = []protocol.DiagnosticTag {} // must be an actual slice
128
129
msg := d .Code .(string )
129
130
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
130
147
msg = fmt .Sprintf ("%s(%s)" , msg , d .Message )
131
148
}
132
- if ! showDiagnostic (msg , d .Source , options ) {
133
- continue
134
- }
135
149
136
150
// zeroIndexedRange subtracts 1 from the line and
137
151
// range, because the compiler output neglects to
@@ -176,51 +190,6 @@ func parseDetailsFile(filename string, options *settings.Options) (protocol.Docu
176
190
return uri , diagnostics , nil
177
191
}
178
192
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
-
224
193
func findJSONFiles (dir string ) ([]string , error ) {
225
194
ans := []string {}
226
195
f := func (path string , fi os.FileInfo , _ error ) error {
0 commit comments