@@ -133,22 +133,30 @@ func (s *ScriptInfo) markContainingProjectsAsDirty() {
133
133
// attachToProject attaches the script info to the project if it's not already attached
134
134
// and returns true if the script info was newly attached.
135
135
func (s * ScriptInfo ) attachToProject (project * Project ) bool {
136
- if ! s .isAttached (project ) {
137
- s .containingProjectsMu .Lock ()
138
- s .containingProjects = append (s .containingProjects , project )
136
+ if s .isAttached (project ) {
137
+ return false
138
+ }
139
+ s .containingProjectsMu .Lock ()
140
+ if s .isAttachedLocked (project ) {
139
141
s .containingProjectsMu .Unlock ()
140
- if project .compilerOptions .PreserveSymlinks != core .TSTrue {
141
- s .ensureRealpath (project .FS ())
142
- }
143
- project .onFileAddedOrRemoved ()
144
- return true
142
+ return false
143
+ }
144
+ s .containingProjects = append (s .containingProjects , project )
145
+ s .containingProjectsMu .Unlock ()
146
+ if project .compilerOptions .PreserveSymlinks != core .TSTrue {
147
+ s .ensureRealpath (project )
145
148
}
146
- return false
149
+ project .onFileAddedOrRemoved ()
150
+ return true
147
151
}
148
152
149
153
func (s * ScriptInfo ) isAttached (project * Project ) bool {
150
154
s .containingProjectsMu .RLock ()
151
155
defer s .containingProjectsMu .RUnlock ()
156
+ return s .isAttachedLocked (project )
157
+ }
158
+
159
+ func (s * ScriptInfo ) isAttachedLocked (project * Project ) bool {
152
160
return slices .Contains (s .containingProjects , project )
153
161
}
154
162
@@ -171,15 +179,9 @@ func (s *ScriptInfo) editContent(change ls.TextChange) {
171
179
s .markContainingProjectsAsDirty ()
172
180
}
173
181
174
- func (s * ScriptInfo ) ensureRealpath (fs vfs. FS ) {
182
+ func (s * ScriptInfo ) ensureRealpath (project * Project ) {
175
183
if s .realpath == "" {
176
- s .containingProjectsMu .RLock ()
177
- defer s .containingProjectsMu .RUnlock ()
178
- if len (s .containingProjects ) == 0 {
179
- panic ("scriptInfo must be attached to a project before calling ensureRealpath" )
180
- }
181
- realpath := fs .Realpath (string (s .path ))
182
- project := s .containingProjects [0 ]
184
+ realpath := project .FS ().Realpath (string (s .path ))
183
185
s .realpath = project .toPath (realpath )
184
186
if s .realpath != s .path {
185
187
project .host .OnDiscoveredSymlink (s )
0 commit comments