MCPcopy Create free account
hub / github.com/microsoft/typescript-go / Session

Struct Session

internal/project/session.go:85–178  ·  view source on GitHub ↗

Session manages the state of an LSP session. It receives textDocument events and requests for LanguageService objects from the LPS server and processes them into immutable snapshots as the data source for LanguageServices. When Session transitions from one snapshot to the next, it diffs them and upd

Source from the content-addressed store, hash-verified

83// next, it diffs them and updates file watchers and Automatic Type
84// Acquisition (ATA) state accordingly.
85type Session struct {
86 backgroundCtx context.Context
87 options *SessionOptions
88 startTime time.Time
89 toPath func(string) tspath.Path
90 client Client
91 logger logging.Logger
92 npmExecutor ata.NpmExecutor
93 fs *overlayFS
94
95 // parseCache is the ref-counted cache of source files used when
96 // creating programs during snapshot cloning.
97 parseCache *ParseCache
98 // extendedConfigCache is the ref-counted cache of tsconfig ASTs
99 // that are used in the "extends" of another tsconfig.
100 extendedConfigCache *ExtendedConfigCache
101 // programCounter counts how many snapshots reference a program.
102 // When a program is no longer referenced, its source files are
103 // released from the parseCache.
104 programCounter *programCounter
105
106 // read-only after initialization
107 initialUserPreferences lsutil.UserPreferences
108 // current preferences
109 workspaceUserPreferences lsutil.UserPreferences
110 compilerOptionsForInferredProjects *core.CompilerOptions
111 typingsInstaller *ata.TypingsInstaller
112 backgroundQueue *background.Queue
113
114 // snapshotID is the counter for snapshot IDs. It does not necessarily
115 // equal the `snapshot.ID`. It is stored on Session instead of globally
116 // so IDs are predictable in tests.
117 snapshotID atomic.Uint64
118
119 // snapshot is the current immutable state of all projects.
120 snapshot *Snapshot
121 snapshotMu sync.RWMutex
122 snapshotUpdateMu sync.Mutex
123
124 // scheduledSnapshotUpdateCancel is the cancelation function for a scheduled
125 // snapshot update. Snapshot updates are scheduled and debounced after file closes.
126 scheduledSnapshotUpdateCancel context.CancelFunc
127 scheduledSnapshotUpdateGeneration uint64
128 scheduledSnapshotUpdateMu sync.Mutex
129
130 pendingUserConfigChanges bool
131 userConfigRWMu sync.Mutex
132
133 // pendingFileChanges are accumulated from textDocument/* events delivered
134 // by the LSP server through DidOpenFile(), DidChangeFile(), etc. They are
135 // applied to the next snapshot update.
136 pendingFileChanges []FileChange
137 pendingFileChangesMu sync.Mutex
138
139 // pendingATAChanges are produced by Automatic Type Acquisition (ATA)
140 // installations and applied to the next snapshot update.
141 pendingATAChanges map[tspath.Path]*ATAStateChange
142 pendingATAChangesMu sync.Mutex

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected