@@ -32,6 +32,7 @@ import (
3232 "github.com/microsoft/TypeScript/tsc/internal/project/logging"
3333 "github.com/microsoft/TypeScript/tsc/internal/tspath"
3434 "github.com/microsoft/TypeScript/tsc/internal/vfs"
35+ "github.com/microsoft/TypeScript/tsc/internal/vfs/pnpvfs"
3536)
3637
3738type UpdateReason int
@@ -89,7 +90,6 @@ type SessionInit struct {
8990 Client Client
9091 Logger logging.Logger
9192 NpmExecutor ata.NpmExecutor
92- PnpApi * pnp.PnpApi
9393 // Spawner launches content mapper processes. It is nil when the host cannot spawn processes.
9494 Spawner contentmapper.Spawner
9595 ContentMapperLogger contentmapper.Logger
@@ -233,11 +233,18 @@ func newContentMapperHost(init *SessionInit) contentmapper.Host {
233233
234234func NewSession (init * SessionInit ) * Session {
235235 currentDirectory := init .Options .CurrentDirectory
236- useCaseSensitiveFileNames := init .FS .UseCaseSensitiveFileNames ()
236+ fs := init .FS
237+ // Keep a cwd-based API for hosts that do not have a project context yet.
238+ // Project-specific hosts select their own API when the project is created.
239+ pnpApi := pnp .InitPnpApi (fs , currentDirectory )
240+ if pnpApi != nil {
241+ fs = pnpvfs .From (fs )
242+ }
243+ useCaseSensitiveFileNames := fs .UseCaseSensitiveFileNames ()
237244 toPath := func (fileName string ) tspath.Path {
238245 return tspath .ToPath (fileName , currentDirectory , useCaseSensitiveFileNames )
239246 }
240- overlayFS := newOverlayFS (init . FS , make (map [tspath.Path ]* Overlay ), init .Options .PositionEncoding , toPath )
247+ overlayFS := newOverlayFS (fs , make (map [tspath.Path ]* Overlay ), init .Options .PositionEncoding , toPath )
241248 parseCache := init .ParseCache
242249 if parseCache == nil {
243250 parseCache = NewParseCache (RefCountCacheOptions {})
@@ -261,7 +268,7 @@ func NewSession(init *SessionInit) *Session {
261268 npmExecutor : init .NpmExecutor ,
262269 contentMapperHost : newContentMapperHost (init ),
263270 fs : overlayFS ,
264- pnpApi : init . PnpApi ,
271+ pnpApi : pnpApi ,
265272 parseCache : parseCache ,
266273 contentMappedParseCache : contentMappedParseCache ,
267274 extendedConfigCache : extendedConfigCache ,
@@ -272,7 +279,7 @@ func NewSession(init *SessionInit) *Session {
272279 uint64 (0 ),
273280 & SnapshotFS {
274281 toPath : toPath ,
275- fs : init . FS ,
282+ fs : fs ,
276283 },
277284 init .Options ,
278285 & ConfigFileRegistry {},
@@ -295,7 +302,7 @@ func NewSession(init *SessionInit) *Session {
295302 },
296303 ),
297304 toPath ,
298- init . PnpApi ,
305+ pnpApi ,
299306 ),
300307 initialUserPreferences : lsutil .NewDefaultUserPreferences (),
301308 workspaceUserPreferences : lsutil .NewDefaultUserPreferences (),
@@ -504,7 +511,7 @@ func (s *Session) DidChangeWatchedFiles(ctx context.Context, changes []*lsproto.
504511 case lsproto .FileChangeTypeCreated :
505512 kind = FileChangeKindWatchCreate
506513 case lsproto .FileChangeTypeChanged :
507- if s . pnpApi != nil && strings .HasSuffix (change .Uri .FileName (), ".pnp.cjs" ) {
514+ if strings .HasSuffix (change .Uri .FileName (), ".pnp.cjs" ) {
508515 kind = FileChangeKindPnpInstall
509516 } else {
510517 kind = FileChangeKindWatchChange
0 commit comments