Skip to content

Commit c7474b5

Browse files
committed
userpreferences snapshot
1 parent db2f039 commit c7474b5

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

internal/project/session.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,16 @@ func (s *Session) Snapshot() (*Snapshot, func()) {
347347

348348
func (s *Session) GetLanguageService(ctx context.Context, uri lsproto.DocumentUri) (*ls.LanguageService, error) {
349349
var snapshot *Snapshot
350-
fileChanges, overlays, ataChanges, updateConfig := s.flushChanges(ctx)
351-
updateSnapshot := !fileChanges.IsEmpty() || len(ataChanges) > 0 || updateConfig
350+
fileChanges, overlays, ataChanges, newConfig := s.flushChanges(ctx)
351+
updateSnapshot := !fileChanges.IsEmpty() || len(ataChanges) > 0 || newConfig != nil
352352
if updateSnapshot {
353353
// If there are pending file changes, we need to update the snapshot.
354354
// Sending the requested URI ensures that the project for this URI is loaded.
355355
snapshot = s.UpdateSnapshot(ctx, overlays, SnapshotChange{
356356
reason: UpdateReasonRequestedLanguageServicePendingChanges,
357357
fileChanges: fileChanges,
358358
ataChanges: ataChanges,
359+
newConfig: newConfig,
359360
requestedURIs: []lsproto.DocumentUri{uri},
360361
})
361362
} else {
@@ -519,7 +520,7 @@ func (s *Session) Close() {
519520
s.backgroundQueue.Close()
520521
}
521522

522-
func (s *Session) flushChanges(ctx context.Context) (FileChangeSummary, map[tspath.Path]*overlay, map[tspath.Path]*ATAStateChange, bool) {
523+
func (s *Session) flushChanges(ctx context.Context) (FileChangeSummary, map[tspath.Path]*overlay, map[tspath.Path]*ATAStateChange, *ls.UserPreferences) {
523524
s.pendingFileChangesMu.Lock()
524525
defer s.pendingFileChangesMu.Unlock()
525526
s.pendingATAChangesMu.Lock()
@@ -528,10 +529,13 @@ func (s *Session) flushChanges(ctx context.Context) (FileChangeSummary, map[tspa
528529
s.pendingATAChanges = make(map[tspath.Path]*ATAStateChange)
529530
fileChanges, overlays := s.flushChangesLocked(ctx)
530531
s.pendingConfigChangesMu.Lock()
531-
updateConfig := s.pendingConfigChanges
532+
var newConfig *ls.UserPreferences
533+
if s.pendingConfigChanges {
534+
newConfig = s.userPreferences.Copy()
535+
}
532536
s.pendingConfigChanges = false
533537
defer s.pendingConfigChangesMu.Unlock()
534-
return fileChanges, overlays, pendingATAChanges, updateConfig
538+
return fileChanges, overlays, pendingATAChanges, newConfig
535539
}
536540

537541
// flushChangesLocked should only be called with s.pendingFileChangesMu held.

internal/project/snapshot.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ type SnapshotChange struct {
133133
// It should only be set the value in the next snapshot should be changed. If nil, the
134134
// value from the previous snapshot will be copied to the new snapshot.
135135
compilerOptionsForInferredProjects *core.CompilerOptions
136+
newConfig *ls.UserPreferences
136137
// ataChanges contains ATA-related changes to apply to projects in the new snapshot.
137138
ataChanges map[tspath.Path]*ATAStateChange
138139
apiRequest *APISnapshotRequest
@@ -251,6 +252,11 @@ func (s *Snapshot) Clone(ctx context.Context, change SnapshotChange, overlays ma
251252
}
252253
}
253254
}
255+
256+
userPreferences := s.userPreferences
257+
if change.newConfig != nil {
258+
userPreferences = change.newConfig
259+
}
254260

255261
snapshotFS, _ := fs.Finalize()
256262
newSnapshot := NewSnapshot(
@@ -261,7 +267,7 @@ func (s *Snapshot) Clone(ctx context.Context, change SnapshotChange, overlays ma
261267
session.extendedConfigCache,
262268
nil,
263269
compilerOptionsForInferredProjects,
264-
session.userPreferences,
270+
userPreferences,
265271
s.toPath,
266272
)
267273
newSnapshot.parentId = s.id

0 commit comments

Comments
 (0)