@@ -82,7 +82,7 @@ func (s *Server) diagnoseDetached(snapshot source.Snapshot) {
82
82
s .publishReports (ctx , snapshot , reports , false )
83
83
}
84
84
85
- func (s * Server ) diagnoseSnapshot (snapshot source.Snapshot , changedURIs []span.URI ) {
85
+ func (s * Server ) diagnoseSnapshot (snapshot source.Snapshot , changedURIs []span.URI , onDisk bool ) {
86
86
ctx := snapshot .View ().BackgroundContext ()
87
87
88
88
delay := snapshot .View ().Options ().ExperimentalDiagnosticsDelay
@@ -93,7 +93,7 @@ func (s *Server) diagnoseSnapshot(snapshot source.Snapshot, changedURIs []span.U
93
93
// by file modifications (no analysis).
94
94
//
95
95
// The second phase does everything, and is debounced by the configured delay.
96
- reports , err := s .diagnoseChangedFiles (ctx , snapshot , changedURIs )
96
+ reports , err := s .diagnoseChangedFiles (ctx , snapshot , changedURIs , onDisk )
97
97
if err != nil {
98
98
if ! errors .Is (err , context .Canceled ) {
99
99
event .Error (ctx , "diagnosing changed files" , err )
@@ -112,11 +112,16 @@ func (s *Server) diagnoseSnapshot(snapshot source.Snapshot, changedURIs []span.U
112
112
s .publishReports (ctx , snapshot , reports , false )
113
113
}
114
114
115
- func (s * Server ) diagnoseChangedFiles (ctx context.Context , snapshot source.Snapshot , uris []span.URI ) (* reportSet , error ) {
115
+ func (s * Server ) diagnoseChangedFiles (ctx context.Context , snapshot source.Snapshot , uris []span.URI , onDisk bool ) (* reportSet , error ) {
116
116
ctx , done := event .Start (ctx , "Server.diagnoseChangedFiles" )
117
117
defer done ()
118
118
packages := make (map [source.Package ]struct {})
119
119
for _ , uri := range uris {
120
+ // If the change is only on-disk and the file is not open, don't
121
+ // directly request its package. It may not be a workspace package.
122
+ if onDisk && ! snapshot .IsOpen (uri ) {
123
+ continue
124
+ }
120
125
pkgs , err := snapshot .PackagesForFile (ctx , uri , source .TypecheckWorkspace )
121
126
if err != nil {
122
127
// TODO (rFindley): we should probably do something with the error here,
0 commit comments