project

package
v0.0.0-...-6fb8e68 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APISnapshotRequest

type APISnapshotRequest struct {
	OpenProjects  *collections.Set[string]
	CloseProjects *collections.Set[tspath.Path]
}

type ATAStateChange

type ATAStateChange struct {
	ProjectID tspath.Path
	// TypingsInfo is the new typings info for the project.
	TypingsInfo *ata.TypingsInfo
	// TypingsFiles is the new list of typing files for the project.
	TypingsFiles []string
	// TypingsFilesToWatch is the new list of typing files to watch for changes.
	TypingsFilesToWatch []string
	Logs                *logging.LogTree
}

ATAStateChange represents a change to a project's ATA state.

type CheckerPool

type CheckerPool struct {
	// contains filtered or unexported fields
}

func (*CheckerPool) GetChecker

func (p *CheckerPool) GetChecker(ctx context.Context) (*checker.Checker, func())

func (*CheckerPool) GetCheckerForFile

func (p *CheckerPool) GetCheckerForFile(ctx context.Context, file *ast.SourceFile) (*checker.Checker, func())

func (*CheckerPool) GetCheckerForFileExclusive

func (p *CheckerPool) GetCheckerForFileExclusive(ctx context.Context, file *ast.SourceFile) (*checker.Checker, func())

GetCheckerForFileExclusive is the same as GetCheckerForFile but also locks a mutex associated with the checker. Call `done` to free the lock.

type Client

type Client interface {
	WatchFiles(ctx context.Context, id WatcherID, watchers []*lsproto.FileSystemWatcher) error
	UnwatchFiles(ctx context.Context, id WatcherID) error
	RefreshDiagnostics(ctx context.Context) error
	PublishDiagnostics(ctx context.Context, params *lsproto.PublishDiagnosticsParams) error
	RefreshInlayHints(ctx context.Context) error
	RefreshCodeLens(ctx context.Context) error
	ProgressStart(message *diagnostics.Message, args ...any)
	ProgressFinish(message *diagnostics.Message, args ...any)
}

type ConfigFileRegistry

type ConfigFileRegistry struct {
	// contains filtered or unexported fields
}

func (*ConfigFileRegistry) ForEachTestConfigEntry

func (c *ConfigFileRegistry) ForEachTestConfigEntry(cb func(tspath.Path, *TestConfigEntry))

For testing

func (*ConfigFileRegistry) ForEachTestConfigFileNamesEntry

func (c *ConfigFileRegistry) ForEachTestConfigFileNamesEntry(cb func(tspath.Path, *TestConfigFileNamesEntry))

For testing

func (*ConfigFileRegistry) GetAncestorConfigFileName

func (c *ConfigFileRegistry) GetAncestorConfigFileName(path tspath.Path, higherThanConfig string) string

func (*ConfigFileRegistry) GetConfig

func (*ConfigFileRegistry) GetConfigFileName

func (c *ConfigFileRegistry) GetConfigFileName(path tspath.Path) string

func (*ConfigFileRegistry) GetTestConfigEntry

func (c *ConfigFileRegistry) GetTestConfigEntry(path tspath.Path) *TestConfigEntry

For testing

func (*ConfigFileRegistry) GetTestConfigFileNamesEntry

func (c *ConfigFileRegistry) GetTestConfigFileNamesEntry(path tspath.Path) *TestConfigFileNamesEntry

For testing

type CreateProgramResult

type CreateProgramResult struct {
	Program     *compiler.Program
	UpdateKind  ProgramUpdateKind
	CheckerPool *CheckerPool
}

type ExtendedConfigCacheEntry

type ExtendedConfigCacheEntry struct {
	*tsoptions.ExtendedConfigCacheEntry
	Hash xxh3.Uint128
}

type ExtendedConfigParseArgs

type ExtendedConfigParseArgs struct {
	FileName        string
	Content         string
	FS              FileSource
	ResolutionStack []string
	Host            tsoptions.ParseConfigHost
	Cache           tsoptions.ExtendedConfigCache
}

type FileChange

type FileChange struct {
	Kind         FileChangeKind
	URI          lsproto.DocumentUri
	Version      int32                                                     // Only set for Open/Change
	Content      string                                                    // Only set for Open
	LanguageKind lsproto.LanguageKind                                      // Only set for Open
	Changes      []lsproto.TextDocumentContentChangePartialOrWholeDocument // Only set for Change
}

type FileChangeKind

type FileChangeKind int
const (
	FileChangeKindOpen FileChangeKind = iota
	FileChangeKindClose
	FileChangeKindChange
	FileChangeKindSave
	FileChangeKindWatchCreate
	FileChangeKindWatchChange
	FileChangeKindWatchDelete
)

func (FileChangeKind) IsWatchKind

func (k FileChangeKind) IsWatchKind() bool

type FileChangeSummary

type FileChangeSummary struct {
	// Only one file can be opened at a time per request
	Opened lsproto.DocumentUri
	// Reopened is set if a close and open occurred for the same file in a single batch of changes.
	Reopened lsproto.DocumentUri
	Closed   collections.Set[lsproto.DocumentUri]
	Changed  collections.Set[lsproto.DocumentUri]
	// Only set when file watching is enabled
	Created collections.Set[lsproto.DocumentUri]
	// Only set when file watching is enabled
	Deleted collections.Set[lsproto.DocumentUri]

	// IncludesWatchChangeOutsideNodeModules is true if the summary includes a create, change, or delete watch
	// event of a file outside a node_modules directory.
	IncludesWatchChangeOutsideNodeModules bool
	// InvalidateAll indicates that all cached file state should be discarded.
	InvalidateAll bool
}

func (FileChangeSummary) HasExcessiveNonCreateWatchEvents

func (f FileChangeSummary) HasExcessiveNonCreateWatchEvents() bool

func (FileChangeSummary) HasExcessiveWatchEvents

func (f FileChangeSummary) HasExcessiveWatchEvents() bool

func (FileChangeSummary) IsEmpty

func (f FileChangeSummary) IsEmpty() bool

type FileContent

type FileContent interface {
	Content() string
	Hash() xxh3.Uint128
}

type FileHandle

type FileHandle interface {
	FileContent
	FileName() string
	Version() int32
	MatchesDiskText() bool
	IsOverlay() bool
	LSPLineMap() *lsconv.LSPLineMap
	ECMALineInfo() *sourcemap.ECMALineInfo
	Kind() core.ScriptKind
}

type FileSource

type FileSource interface {
	FS() vfs.FS
	GetFile(fileName string) FileHandle
	GetFileByPath(fileName string, path tspath.Path) FileHandle
	FileExists(fileName string, path tspath.Path) bool
	GetAccessibleEntries(path string) vfs.Entries
}

type Kind

type Kind int
const (
	KindInferred Kind = iota
	KindConfigured
)

func (Kind) String

func (i Kind) String() string

type Overlay

type Overlay struct {
	// contains filtered or unexported fields
}

func (*Overlay) Content

func (f *Overlay) Content() string

func (*Overlay) ECMALineInfo

func (f *Overlay) ECMALineInfo() *sourcemap.ECMALineInfo

func (*Overlay) FileName

func (f *Overlay) FileName() string

func (*Overlay) Hash

func (f *Overlay) Hash() xxh3.Uint128

func (*Overlay) IsOverlay

func (o *Overlay) IsOverlay() bool

func (*Overlay) Kind

func (o *Overlay) Kind() core.ScriptKind

func (*Overlay) LSPLineMap

func (f *Overlay) LSPLineMap() *lsconv.LSPLineMap

func (*Overlay) MatchesDiskText

func (o *Overlay) MatchesDiskText() bool

MatchesDiskText may return false negatives, but never false positives.

func (*Overlay) Text

func (o *Overlay) Text() string

func (*Overlay) Version

func (o *Overlay) Version() int32

type OwnerCache

type OwnerCache[K comparable, V any, LoadArgs any] struct {
	// contains filtered or unexported fields
}

OwnerCache is like RefCountCache, but each entry tracks the set of its owners instead of a count. We use this to associate extended config cache entries with each snapshot that contains them, since the same config can be Acquired multiple times during config parsing while only appearing once in the ParsedCommandLine's list of extended files. When updating this code, check if the same changes should be made to RefCountCache as well.

func NewOwnerCache

func NewOwnerCache[K comparable, V any, LoadArgs any](
	parse func(K, LoadArgs) V,
	isExpired func(K, V, LoadArgs) bool,
) *OwnerCache[K, V, LoadArgs]

func (*OwnerCache[K, V, LoadArgs]) Acquire

func (c *OwnerCache[K, V, LoadArgs]) Acquire(identity K, owner uint64, value V)

func (*OwnerCache[K, V, LoadArgs]) AddOwner

func (c *OwnerCache[K, V, LoadArgs]) AddOwner(identity K, owner uint64)

AddOwner adds an owner to an existing live entry. The entry must exist and have at least one current owner; callers must ensure the entry is kept alive (e.g. via snapshot ref counting).

func (*OwnerCache[K, V, LoadArgs]) Has

func (c *OwnerCache[K, V, LoadArgs]) Has(identity K) bool

func (*OwnerCache[K, V, LoadArgs]) LoadAndAcquire

func (c *OwnerCache[K, V, LoadArgs]) LoadAndAcquire(identity K, owner uint64, loadArgs LoadArgs) V

func (*OwnerCache[K, V, LoadArgs]) Release

func (c *OwnerCache[K, V, LoadArgs]) Release(identity K, owner uint64)

type ParseCache

func NewParseCache

func NewParseCache(options RefCountCacheOptions) *ParseCache

type ParseCacheKey

type ParseCacheKey struct {
	ast.SourceFileParseOptions
	ScriptKind core.ScriptKind
	Hash       xxh3.Uint128
}

func NewParseCacheKey

func NewParseCacheKey(
	options ast.SourceFileParseOptions,
	hash xxh3.Uint128,
	scriptKind core.ScriptKind,
) ParseCacheKey

type PatternsAndIgnored

type PatternsAndIgnored struct {
	// contains filtered or unexported fields
}

type PendingReload

type PendingReload int
const (
	PendingReloadNone PendingReload = iota
	PendingReloadFileNames
	PendingReloadFull
)

type ProgramUpdateKind

type ProgramUpdateKind int
const (
	ProgramUpdateKindNone ProgramUpdateKind = iota
	ProgramUpdateKindCloned
	ProgramUpdateKindSameFileNames
	ProgramUpdateKindNewFiles
)

type Project

type Project struct {
	Kind Kind

	CommandLine *tsoptions.ParsedCommandLine

	Program *compiler.Program
	// The kind of update that was performed on the program last time it was updated.
	ProgramUpdateKind ProgramUpdateKind
	// The ID of the snapshot that created the program stored in this project.
	ProgramLastUpdate uint64
	// contains filtered or unexported fields
}

Project represents a TypeScript project. If changing struct fields, also update the Clone method.

func NewConfiguredProject

func NewConfiguredProject(
	configFileName string,
	configFilePath tspath.Path,
	builder *ProjectCollectionBuilder,
	logger *logging.LogTree,
) *Project

func NewInferredProject

func NewInferredProject(
	currentDirectory string,
	compilerOptions *core.CompilerOptions,
	rootFileNames []string,
	builder *ProjectCollectionBuilder,
	logger *logging.LogTree,
) *Project

func NewProject

func NewProject(
	configFileName string,
	kind Kind,
	currentDirectory string,
	builder *ProjectCollectionBuilder,
	logger *logging.LogTree,
) *Project

func (*Project) Clone

func (p *Project) Clone() *Project

func (*Project) CloneWatchers

func (p *Project) CloneWatchers() *WatchedFiles[*collections.SyncSet[tspath.Path]]

func (*Project) ComputeTypingsInfo

func (p *Project) ComputeTypingsInfo() ata.TypingsInfo

func (*Project) ConfigFileName

func (p *Project) ConfigFileName() string

ConfigFileName panics if Kind() is not KindConfigured.

func (*Project) ConfigFilePath

func (p *Project) ConfigFilePath() tspath.Path

ConfigFilePath panics if Kind() is not KindConfigured.

func (*Project) CreateProgram

func (p *Project) CreateProgram() CreateProgramResult

func (*Project) DisplayName

func (p *Project) DisplayName(cwd string) string

DisplayName returns a short, human-readable name for the project, relative to the given workspace root directory. For configured projects, this is the config file path made relative. For inferred projects, this is the last component of the current directory.

func (*Project) GetProgram

func (p *Project) GetProgram() *compiler.Program

func (*Project) GetTypeAcquisition

func (p *Project) GetTypeAcquisition() *core.TypeAcquisition

GetTypeAcquisition returns the type acquisition settings for this project.

func (*Project) GetUnresolvedImports

func (p *Project) GetUnresolvedImports() *collections.Set[string]

GetUnresolvedImports extracts unresolved imports from this project's program.

func (*Project) HasFile

func (p *Project) HasFile(fileName string) bool

func (*Project) ID

func (p *Project) ID() tspath.Path

func (*Project) Id

func (p *Project) Id() tspath.Path

func (*Project) IsSourceFromProjectReference

func (p *Project) IsSourceFromProjectReference(path tspath.Path) bool

func (*Project) Name

func (p *Project) Name() string

func (*Project) ShouldTriggerATA

func (p *Project) ShouldTriggerATA(snapshotID uint64) bool

ShouldTriggerATA determines if ATA should be triggered for this project.

type ProjectCollection

type ProjectCollection struct {
	// contains filtered or unexported fields
}

func (*ProjectCollection) ConfigFileRegistry

func (c *ProjectCollection) ConfigFileRegistry() *ConfigFileRegistry

func (*ProjectCollection) ConfiguredProject

func (c *ProjectCollection) ConfiguredProject(path tspath.Path) *Project

func (*ProjectCollection) ConfiguredProjects

func (c *ProjectCollection) ConfiguredProjects() []*Project

ConfiguredProjects returns all configured projects in a stable order.

func (*ProjectCollection) GetDefaultProject

func (c *ProjectCollection) GetDefaultProject(path tspath.Path) *Project

!!! result could be cached

func (*ProjectCollection) GetProjectByPath

func (c *ProjectCollection) GetProjectByPath(projectPath tspath.Path) *Project

func (*ProjectCollection) GetProjectsContainingFile

func (c *ProjectCollection) GetProjectsContainingFile(path tspath.Path) []ls.Project

func (*ProjectCollection) InferredProject

func (c *ProjectCollection) InferredProject() *Project

func (*ProjectCollection) Projects

func (c *ProjectCollection) Projects() []*Project

Projects returns all projects, including the inferred project if it exists, in a stable order.

func (*ProjectCollection) ProjectsByPath

func (c *ProjectCollection) ProjectsByPath() *collections.OrderedMap[tspath.Path, *Project]

ProjectsByPath returns an ordered map of configured projects keyed by their config file path, plus the inferred project, if it exists, with the key `inferredProjectName`.

type ProjectCollectionBuilder

type ProjectCollectionBuilder struct {
	// contains filtered or unexported fields
}

func (*ProjectCollectionBuilder) DidChangeCustomConfigFileName

func (b *ProjectCollectionBuilder) DidChangeCustomConfigFileName(logger *logging.LogTree)

if customConfigFileName changes, invalidate default projects.

func (*ProjectCollectionBuilder) DidChangeFiles

func (b *ProjectCollectionBuilder) DidChangeFiles(summary FileChangeSummary, logger *logging.LogTree)

func (*ProjectCollectionBuilder) DidRequestFile

func (b *ProjectCollectionBuilder) DidRequestFile(uri lsproto.DocumentUri, configuredProjectsOnly bool, logger *logging.LogTree)

DidRequestFile ensures projects are loaded for the given URI. If configuredProjectsOnly is true, only configured projects are loaded; no inferred project is created and it is not guaranteed that there will be any project containing the file in the resulting snapshot.

func (*ProjectCollectionBuilder) DidRequestProject

func (b *ProjectCollectionBuilder) DidRequestProject(projectId tspath.Path, logger *logging.LogTree)

func (*ProjectCollectionBuilder) DidRequestProjectTrees

func (b *ProjectCollectionBuilder) DidRequestProjectTrees(projectTreeRequest *ProjectTreeRequest, logger *logging.LogTree)

func (*ProjectCollectionBuilder) DidUpdateATAState

func (b *ProjectCollectionBuilder) DidUpdateATAState(ataChanges map[tspath.Path]*ATAStateChange, logger *logging.LogTree)

func (*ProjectCollectionBuilder) Finalize

func (*ProjectCollectionBuilder) HandleAPIRequest

func (b *ProjectCollectionBuilder) HandleAPIRequest(apiRequest *APISnapshotRequest, logger *logging.LogTree) error

type ProjectTreeRequest

type ProjectTreeRequest struct {
	// contains filtered or unexported fields
}

func (*ProjectTreeRequest) IsAllProjects

func (p *ProjectTreeRequest) IsAllProjects() bool

func (*ProjectTreeRequest) IsProjectReferenced

func (p *ProjectTreeRequest) IsProjectReferenced(projectID tspath.Path) bool

func (*ProjectTreeRequest) Projects

func (p *ProjectTreeRequest) Projects() []tspath.Path

type RefCountCache

type RefCountCache[K comparable, V any, AcquireArgs any] struct {
	Options RefCountCacheOptions
	// contains filtered or unexported fields
}

func NewRefCountCache

func NewRefCountCache[K comparable, V any, AcquireArgs any](
	options RefCountCacheOptions,
	parse func(K, AcquireArgs) V,
) *RefCountCache[K, V, AcquireArgs]

func (*RefCountCache[K, V, AcquireArgs]) Acquire

func (c *RefCountCache[K, V, AcquireArgs]) Acquire(identity K, acquireArgs AcquireArgs) V

Acquire retrieves or creates a cache entry for the given identity and hash. If an entry exists with matching identity and hash, its refcount is incremented and the cached value is returned. Otherwise, parse() is called to create the value, which is stored and returned with refcount 1.

The caller is responsible for calling Deref when done with the value.

func (*RefCountCache[K, V, AcquireArgs]) Deref

func (c *RefCountCache[K, V, AcquireArgs]) Deref(identity K)

Deref decrements the reference count for an entry. When the refcount reaches zero, the entry is removed from the cache (unless DisableDeletion is set).

func (*RefCountCache[K, V, AcquireArgs]) Has

func (c *RefCountCache[K, V, AcquireArgs]) Has(identity K) bool

func (*RefCountCache[K, V, AcquireArgs]) Ref

func (c *RefCountCache[K, V, AcquireArgs]) Ref(identity K)

Ref increments the reference count for an existing entry. Panics if the entry does not exist.

type RefCountCacheOptions

type RefCountCacheOptions struct {
	// DisableDeletion prevents entries from being removed from the cache.
	// Used for testing.
	DisableDeletion bool
}

type ResourceRequest

type ResourceRequest struct {
	// Documents are URIs that were requested by the client.
	// The new snapshot should ensure projects for these URIs have loaded programs.
	Documents []lsproto.DocumentUri
	// ConfiguredProjectDocuments are URIs for which configured projects should be loaded
	// (if disableSolutionSearching/disableReferencedProjectLoad settings allow),
	// but no inferred project should be created if no configured project is found.
	// This is used by cross-project operations like find-all-references.
	ConfiguredProjectDocuments []lsproto.DocumentUri
	// Update requested Projects.
	// this is used when we want to get LS and from all the Projects the file can be part of
	Projects []tspath.Path
	// Update and ensure project trees that reference the projects
	// This is used to compute the solution and project tree so that
	// we can find references across all the projects in the solution irrespective of which project is open
	ProjectTree *ProjectTreeRequest
	// AutoImports is the document URI for which auto imports should be prepared.
	AutoImports lsproto.DocumentUri
}

type Session

type Session struct {
	// contains filtered or unexported fields
}

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 updates file watchers and Automatic Type Acquisition (ATA) state accordingly.

func NewSession

func NewSession(init *SessionInit) *Session

func (*Session) APIOpenProject

func (s *Session) APIOpenProject(ctx context.Context, configFileName string, apiFileChanges FileChangeSummary) (*Project, *Snapshot, error)

APIOpenProject opens a project and returns a ref'd snapshot. The caller must call snapshot.Deref(s) when done.

func (*Session) APIUpdateWithFileChanges

func (s *Session) APIUpdateWithFileChanges(ctx context.Context, apiFileChanges FileChangeSummary) *Snapshot

APIUpdateWithFileChanges creates a new snapshot incorporating the given file changes. Returns a ref'd snapshot; caller must Deref when done.

func (*Session) Close

func (s *Session) Close()

func (*Session) Config

func (s *Session) Config() *lsutil.UserConfig

Gets copy of current configuration

func (*Session) Configure

func (s *Session) Configure(config *lsutil.UserConfig)

func (*Session) DidChangeCompilerOptionsForInferredProjects

func (s *Session) DidChangeCompilerOptionsForInferredProjects(ctx context.Context, options *core.CompilerOptions)

func (*Session) DidChangeFile

func (*Session) DidChangeWatchedFiles

func (s *Session) DidChangeWatchedFiles(ctx context.Context, changes []*lsproto.FileEvent)

func (*Session) DidCloseFile

func (s *Session) DidCloseFile(ctx context.Context, uri lsproto.DocumentUri)

func (*Session) DidOpenFile

func (s *Session) DidOpenFile(ctx context.Context, uri lsproto.DocumentUri, version int32, content string, languageKind lsproto.LanguageKind)

func (*Session) DidSaveFile

func (s *Session) DidSaveFile(ctx context.Context, uri lsproto.DocumentUri)

func (*Session) FS

func (s *Session) FS() vfs.FS

FS implements module.ResolutionHost

func (*Session) GetCurrentDirectory

func (s *Session) GetCurrentDirectory() string

GetCurrentDirectory implements module.ResolutionHost

func (*Session) GetCurrentLanguageServiceWithAutoImports

func (s *Session) GetCurrentLanguageServiceWithAutoImports(ctx context.Context, uri lsproto.DocumentUri) (*ls.LanguageService, error)

GetCurrentLanguageServiceWithAutoImports flushes pending file changes, clones the current snapshot with auto-import preparation for the given URI, then returns a LanguageService for the default project. Use this only outside of request handling (e.g. cache warming). For request handlers, use GetLanguageServiceWithAutoImports with the request-level snapshot instead.

func (*Session) GetLanguageService

func (s *Session) GetLanguageService(ctx context.Context, uri lsproto.DocumentUri) (*ls.LanguageService, error)

func (*Session) GetLanguageServiceAndProjectsForFile

func (s *Session) GetLanguageServiceAndProjectsForFile(ctx context.Context, uri lsproto.DocumentUri) (*Project, *ls.LanguageService, []ls.Project, error)

func (*Session) GetLanguageServiceForProjectWithFile

func (s *Session) GetLanguageServiceForProjectWithFile(ctx context.Context, project *Project, uri lsproto.DocumentUri) *ls.LanguageService

func (*Session) GetLanguageServiceWithAutoImports

func (s *Session) GetLanguageServiceWithAutoImports(ctx context.Context, baseSnapshot *Snapshot, uri lsproto.DocumentUri) (*ls.LanguageService, error)

GetLanguageServiceWithAutoImports clones the given snapshot with auto-import preparation for the given URI, without flushing pending file changes. The cloned snapshot will be adopted as the session's current snapshot in the background if other changes haven't been adopted in the meantime.

func (*Session) GetProjectsForFile

func (s *Session) GetProjectsForFile(ctx context.Context, uri lsproto.DocumentUri) ([]ls.Project, error)

func (*Session) InitializeWithUserConfig

func (s *Session) InitializeWithUserConfig(config *lsutil.UserConfig)

func (*Session) NpmInstall

func (s *Session) NpmInstall(cwd string, npmInstallArgs []string) ([]byte, error)

func (*Session) ScheduleDiagnosticsRefresh

func (s *Session) ScheduleDiagnosticsRefresh()

func (*Session) Snapshot

func (s *Session) Snapshot() *Snapshot

func (*Session) Trace

func (s *Session) Trace(msg string)

Trace implements module.ResolutionHost

func (*Session) UpdateSnapshot

func (s *Session) UpdateSnapshot(ctx context.Context, overlays map[tspath.Path]*Overlay, change SnapshotChange)

func (*Session) WaitForBackgroundTasks

func (s *Session) WaitForBackgroundTasks()

WaitForBackgroundTasks waits for all background tasks to complete. This is intended to be used only for testing purposes.

func (*Session) WithLanguageServiceAndSnapshot

func (s *Session) WithLanguageServiceAndSnapshot(
	ctx context.Context,
	uri lsproto.DocumentUri,
	fn func(*ls.LanguageService, *Snapshot) (func() error, error),
) (func() error, error)

WithLanguageServiceAndSnapshot synchronously acquires a ref'd snapshot and creates a language service for the given URI. fn receives both the language service and the backing snapshot so it can clone the snapshot (e.g. to enable auto-imports). The snapshot is kept alive until the async work completes.

Only use this method when the callback needs direct access to the snapshot. For handlers that only need a LanguageService, use GetLanguageService directly—language services continue to work even after their backing snapshot has been disposed.

func (*Session) WithSnapshotLoadingProjectTree

func (s *Session) WithSnapshotLoadingProjectTree(
	ctx context.Context,
	requestedProjectTrees *collections.Set[tspath.Path],
	fn func(*Snapshot),
)

WithSnapshotLoadingProjectTree acquires a ref'd snapshot with the requested project trees loaded, then calls fn. The snapshot stays alive for the duration of fn.

type SessionInit

type SessionInit struct {
	BackgroundCtx context.Context
	Options       *SessionOptions
	FS            vfs.FS
	Client        Client
	Logger        logging.Logger
	NpmExecutor   ata.NpmExecutor
	ParseCache    *ParseCache
}

type SessionOptions

type SessionOptions struct {
	CurrentDirectory       string
	DefaultLibraryPath     string
	TypingsLocation        string
	PositionEncoding       lsproto.PositionEncodingKind
	WatchEnabled           bool
	LoggingEnabled         bool
	PushDiagnosticsEnabled bool
	DebounceDelay          time.Duration
	Locale                 locale.Locale
}

SessionOptions are the immutable initialization options for a session. Snapshots may reference them as a pointer since they never change.

type Snapshot

type Snapshot struct {
	ProjectCollection  *ProjectCollection
	ConfigFileRegistry *ConfigFileRegistry
	AutoImports        *autoimport.Registry
	// contains filtered or unexported fields
}

func NewSnapshot

func NewSnapshot(
	id uint64,
	fs *SnapshotFS,
	sessionOptions *SessionOptions,
	configFileRegistry *ConfigFileRegistry,
	compilerOptionsForInferredProjects *core.CompilerOptions,
	allUserPreferences *lsutil.UserConfig,
	autoImports *autoimport.Registry,
	autoImportsWatch *WatchedFiles[map[tspath.Path]string],
	toPath func(fileName string) tspath.Path,
) *Snapshot

NewSnapshot initializes a snapshot with refCount 1. The caller is responsible for calling Deref when done.

func (*Snapshot) AutoImportRegistry

func (s *Snapshot) AutoImportRegistry() *autoimport.Registry

func (*Snapshot) Clone

func (s *Snapshot) Clone(ctx context.Context, change SnapshotChange, overlays map[tspath.Path]*Overlay, session *Session) *Snapshot

func (*Snapshot) Converters

func (s *Snapshot) Converters() *lsconv.Converters

func (*Snapshot) Deref

func (s *Snapshot) Deref(session *Session)

Deref decrements the snapshot's reference count. When the count reaches zero, the snapshot is disposed and its resources are released.

func (*Snapshot) DirectoryExists

func (s *Snapshot) DirectoryExists(path string) bool

func (*Snapshot) GetDefaultProject

func (s *Snapshot) GetDefaultProject(uri lsproto.DocumentUri) *Project

func (*Snapshot) GetDirectories

func (s *Snapshot) GetDirectories(path string) []string

func (*Snapshot) GetECMALineInfo

func (s *Snapshot) GetECMALineInfo(fileName string) *sourcemap.ECMALineInfo

func (*Snapshot) GetFile

func (s *Snapshot) GetFile(fileName string) FileHandle

func (*Snapshot) GetPreferences

func (s *Snapshot) GetPreferences(activeFile string) *lsutil.UserPreferences

func (*Snapshot) GetProjectsContainingFile

func (s *Snapshot) GetProjectsContainingFile(uri lsproto.DocumentUri) []ls.Project

func (*Snapshot) ID

func (s *Snapshot) ID() uint64

func (*Snapshot) LSPLineMap

func (s *Snapshot) LSPLineMap(fileName string) *lsconv.LSPLineMap

func (*Snapshot) ReadDirectory

func (s *Snapshot) ReadDirectory(currentDir string, path string, extensions []string, excludes []string, includes []string, depth int) []string

func (*Snapshot) ReadFile

func (s *Snapshot) ReadFile(fileName string) (string, bool)

func (*Snapshot) UseCaseSensitiveFileNames

func (s *Snapshot) UseCaseSensitiveFileNames() bool

func (*Snapshot) UserPreferences

func (s *Snapshot) UserPreferences() *lsutil.UserPreferences

type SnapshotChange

type SnapshotChange struct {
	ResourceRequest
	// contains filtered or unexported fields
}

type SnapshotFS

type SnapshotFS struct {
	// contains filtered or unexported fields
}

func (*SnapshotFS) FS

func (s *SnapshotFS) FS() vfs.FS

func (*SnapshotFS) FileExists

func (s *SnapshotFS) FileExists(fileName string, path tspath.Path) bool

func (*SnapshotFS) GetAccessibleEntries

func (s *SnapshotFS) GetAccessibleEntries(directoryName string) vfs.Entries

func (*SnapshotFS) GetFile

func (s *SnapshotFS) GetFile(fileName string) FileHandle

func (*SnapshotFS) GetFileByPath

func (s *SnapshotFS) GetFileByPath(fileName string, path tspath.Path) FileHandle

type TestConfigEntry

type TestConfigEntry struct {
	FileName           string
	RetainingProjects  iter.Seq[tspath.Path]
	RetainingOpenFiles iter.Seq[tspath.Path]
	RetainingConfigs   iter.Seq[tspath.Path]
}

For testing

type TestConfigFileNamesEntry

type TestConfigFileNamesEntry struct {
	NearestConfigFileName string
	Ancestors             map[string]string
}

type UpdateReason

type UpdateReason int
const (
	UpdateReasonUnknown UpdateReason = iota
	UpdateReasonDidOpenFile
	UpdateReasonDidChangeCompilerOptionsForInferredProjects
	UpdateReasonRequestedLanguageServicePendingChanges
	UpdateReasonRequestedLanguageServiceProjectNotLoaded
	UpdateReasonRequestedLanguageServiceForFileNotOpen
	UpdateReasonRequestedLanguageServiceProjectDirty
	UpdateReasonRequestedLoadProjectTree
	UpdateReasonRequestedLanguageServiceWithAutoImports
	UpdateReasonIdleCleanDiskCache
)

type WatchedFiles

type WatchedFiles[T any] struct {
	// contains filtered or unexported fields
}

func NewWatchedFiles

func NewWatchedFiles[T any](name string, watchKind lsproto.WatchKind, computeGlobPatterns func(input T) PatternsAndIgnored) *WatchedFiles[T]

func (*WatchedFiles[T]) Clone

func (w *WatchedFiles[T]) Clone(input T) *WatchedFiles[T]

func (*WatchedFiles[T]) ID

func (w *WatchedFiles[T]) ID() WatcherID

func (*WatchedFiles[T]) Name

func (w *WatchedFiles[T]) Name() string

func (*WatchedFiles[T]) WatchKind

func (w *WatchedFiles[T]) WatchKind() lsproto.WatchKind

func (*WatchedFiles[T]) Watchers

func (w *WatchedFiles[T]) Watchers() (WatcherID, []*lsproto.FileSystemWatcher, map[string]struct{})

type WatcherID

type WatcherID string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL