project

package
v0.0.0-...-94ae2f2 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2025 License: Apache-2.0 Imports: 31 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]
	UpdateProjects *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 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
}

type ConfigFileRegistry

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

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

type CreateProgramResult

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

type FileChange

type FileChange struct {
	Kind         FileChangeKind
	URI          lsproto.DocumentUri
	Hash         xxh3.Uint128                                              // Only set for Close
	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
)

type FileChangeSummary

type FileChangeSummary struct {
	// Only one file can be opened at a time per request
	Opened lsproto.DocumentUri
	// Values are the content hashes of the overlays before closing.
	Closed  map[lsproto.DocumentUri]xxh3.Uint128
	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]
}

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() *ls.LSPLineMap
	ECMALineInfo() *sourcemap.ECMALineInfo
	Kind() core.ScriptKind
}

type FileSource

type FileSource interface {
	FS() vfs.FS
	GetFile(fileName string) FileHandle
}

type Kind

type Kind int
const (
	KindInferred Kind = iota
	KindConfigured
)

func (Kind) String

func (i Kind) String() string

type ParseCache

type ParseCache struct {
	Options ParseCacheOptions
	// contains filtered or unexported fields
}

func (*ParseCache) Acquire

func (c *ParseCache) Acquire(
	fh FileContent,
	opts ast.SourceFileParseOptions,
	scriptKind core.ScriptKind,
) *ast.SourceFile

func (*ParseCache) Deref

func (c *ParseCache) Deref(file *ast.SourceFile)

func (*ParseCache) Ref

func (c *ParseCache) Ref(file *ast.SourceFile)

type ParseCacheOptions

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

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() (failedLookupsWatch *WatchedFiles[map[tspath.Path]string], affectingLocationsWatch *WatchedFiles[map[tspath.Path]string])

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) 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) 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) 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(fileName string, path tspath.Path) *Project

!!! result could be cached

func (*ProjectCollection) GetProjectByPath

func (c *ProjectCollection) GetProjectByPath(projectPath tspath.Path) *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 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) Close

func (s *Session) Close()

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) GetLanguageService

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

func (*Session) NpmInstall

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

func (*Session) OpenProject

func (s *Session) OpenProject(ctx context.Context, configFileName string) (*Project, error)

func (*Session) ScheduleDiagnosticsRefresh

func (s *Session) ScheduleDiagnosticsRefresh()

func (*Session) Snapshot

func (s *Session) Snapshot() (*Snapshot, func())

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) *Snapshot

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.

type SessionInit

type SessionInit struct {
	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
	DebounceDelay      time.Duration
}

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
	// contains filtered or unexported fields
}

func NewSnapshot

func NewSnapshot(
	id uint64,
	fs *snapshotFS,
	sessionOptions *SessionOptions,
	parseCache *ParseCache,
	extendedConfigCache *extendedConfigCache,
	configFileRegistry *ConfigFileRegistry,
	compilerOptionsForInferredProjects *core.CompilerOptions,
	toPath func(fileName string) tspath.Path,
) *Snapshot

NewSnapshot

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() *ls.Converters

func (*Snapshot) Deref

func (s *Snapshot) Deref() bool

func (*Snapshot) GetDefaultProject

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

func (*Snapshot) GetECMALineInfo

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

func (*Snapshot) GetFile

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

func (*Snapshot) ID

func (s *Snapshot) ID() uint64

func (*Snapshot) LSPLineMap

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

func (*Snapshot) ReadFile

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

func (*Snapshot) Ref

func (s *Snapshot) Ref()

func (*Snapshot) UseCaseSensitiveFileNames

func (s *Snapshot) UseCaseSensitiveFileNames() bool

type SnapshotChange

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

type UpdateReason

type UpdateReason int
const (
	UpdateReasonUnknown UpdateReason = iota
	UpdateReasonDidOpenFile
	UpdateReasonDidChangeCompilerOptionsForInferredProjects
	UpdateReasonRequestedLanguageServicePendingChanges
	UpdateReasonRequestedLanguageServiceProjectNotLoaded
	UpdateReasonRequestedLanguageServiceProjectDirty
)

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) []string) *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]) ParsedGlobs

func (w *WatchedFiles[T]) ParsedGlobs() []*glob.Glob

func (*WatchedFiles[T]) WatchKind

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

func (*WatchedFiles[T]) Watchers

func (w *WatchedFiles[T]) Watchers() (WatcherID, []*lsproto.FileSystemWatcher)

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