project

package
v0.0.0-...-7d7180d Latest Latest
Warning

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

Go to latest
Published: May 24, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	WatchFiles(ctx context.Context, watchers []*lsproto.FileSystemWatcher) (WatcherHandle, error)
	UnwatchFiles(ctx context.Context, handle WatcherHandle) error
	RefreshDiagnostics(ctx context.Context) error
}

type DocumentRegistry

type DocumentRegistry struct {
	Options tspath.ComparePathsOptions
	Hooks   DocumentRegistryHooks
	// contains filtered or unexported fields
}

The document registry represents a store of SourceFile objects that can be shared between multiple LanguageService instances.

func (*DocumentRegistry) AcquireDocument

func (r *DocumentRegistry) AcquireDocument(scriptInfo *ScriptInfo, compilerOptions *core.CompilerOptions, oldSourceFile *ast.SourceFile, oldCompilerOptions *core.CompilerOptions) *ast.SourceFile

AcquireDocument gets a SourceFile from the registry if it exists as the same version tracked by the ScriptInfo. If it does not exist, or is out of date, it creates a new SourceFile and stores it, tracking that the caller has referenced it. If an oldSourceFile is passed, the registry will decrement its reference count and remove it from the registry if the count reaches 0. (If the old file and new file have the same key, this results in a no-op to the ref count.)

This code is greatly simplified compared to the old TS codebase because of the lack of incremental parsing. Previously, source files could be updated and reused by the same LanguageService instance over time, as well as across multiple instances. Here, we still reuse files across multiple LanguageServices, but we only reuse them across Program updates when the files haven't changed.

func (*DocumentRegistry) ReleaseDocument

func (r *DocumentRegistry) ReleaseDocument(file *ast.SourceFile, compilerOptions *core.CompilerOptions)

type DocumentRegistryHooks

type DocumentRegistryHooks struct {
	OnReleaseDocument func(file *ast.SourceFile)
}

type Kind

type Kind int
const (
	KindInferred Kind = iota
	KindConfigured
	KindAutoImportProvider
	KindAuxiliary
)

func (Kind) String

func (i Kind) String() string

type LogLevel

type LogLevel int
const (
	LogLevelTerse LogLevel = iota
	LogLevelNormal
	LogLevelRequestTime
	LogLevelVerbose
)

type Logger

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

func NewLogger

func NewLogger(outputs []io.Writer, file string, level LogLevel) *Logger

func (*Logger) Close

func (l *Logger) Close()

func (*Logger) EndGroup

func (l *Logger) EndGroup()

func (*Logger) Error

func (l *Logger) Error(s string)

func (*Logger) HasLevel

func (l *Logger) HasLevel(level LogLevel) bool

func (*Logger) Info

func (l *Logger) Info(s string)

func (*Logger) LoggingEnabled

func (l *Logger) LoggingEnabled() bool

func (*Logger) PerfTrace

func (l *Logger) PerfTrace(s string)

func (*Logger) SetFile

func (l *Logger) SetFile(file string)

func (*Logger) StartGroup

func (l *Logger) StartGroup()

type PendingReload

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

type Project

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

func NewConfiguredProject

func NewConfiguredProject(configFileName string, configFilePath tspath.Path, host ProjectHost) *Project

func NewInferredProject

func NewInferredProject(compilerOptions *core.CompilerOptions, currentDirectory string, projectRootPath tspath.Path, host ProjectHost) *Project

func NewProject

func NewProject(name string, kind Kind, currentDirectory string, host ProjectHost) *Project

func (*Project) AddRoot

func (p *Project) AddRoot(info *ScriptInfo)

func (*Project) Close

func (p *Project) Close()

func (*Project) CurrentProgram

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

func (*Project) DefaultLibraryPath

func (p *Project) DefaultLibraryPath() string

DefaultLibraryPath implements compiler.CompilerHost.

func (*Project) FS

func (p *Project) FS() vfs.FS

FS implements compiler.CompilerHost.

func (*Project) GetCompilerOptions

func (p *Project) GetCompilerOptions() *core.CompilerOptions

func (*Project) GetCurrentDirectory

func (p *Project) GetCurrentDirectory() string

GetCurrentDirectory implements compiler.CompilerHost.

func (*Project) GetDefaultLibraryPath

func (p *Project) GetDefaultLibraryPath() string

GetDefaultLibraryPath implements compiler.CompilerHost.

func (*Project) GetLanguageServiceForRequest

func (p *Project) GetLanguageServiceForRequest(ctx context.Context) (*ls.LanguageService, func())

func (*Project) GetProgram

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

Updates the program if needed.

func (*Project) GetRootFileNames

func (p *Project) GetRootFileNames() []string

func (*Project) GetSourceFile

func (p *Project) GetSourceFile(fileName string, path tspath.Path, languageVersion core.ScriptTarget) *ast.SourceFile

GetSourceFile implements compiler.CompilerHost.

func (*Project) Kind

func (p *Project) Kind() Kind

func (*Project) LoadConfig

func (p *Project) LoadConfig() error

func (*Project) MarkFileAsDirty

func (p *Project) MarkFileAsDirty(path tspath.Path)

func (*Project) Name

func (p *Project) Name() string

func (*Project) NewLine

func (p *Project) NewLine() string

NewLine implements compiler.CompilerHost.

func (*Project) RemoveFile

func (p *Project) RemoveFile(info *ScriptInfo, fileExists bool, detachFromProject bool)

func (*Project) Trace

func (p *Project) Trace(msg string)

Trace implements compiler.CompilerHost.

func (*Project) Version

func (p *Project) Version() int

type ProjectHost

type ProjectHost interface {
	tsoptions.ParseConfigHost
	NewLine() string
	DefaultLibraryPath() string
	DocumentRegistry() *DocumentRegistry
	GetScriptInfoByPath(path tspath.Path) *ScriptInfo
	GetOrCreateScriptInfoForFile(fileName string, path tspath.Path, scriptKind core.ScriptKind) *ScriptInfo
	OnDiscoveredSymlink(info *ScriptInfo)
	Log(s string)
	PositionEncoding() lsproto.PositionEncodingKind

	IsWatchEnabled() bool
	Client() Client
}

type ScriptInfo

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

func NewScriptInfo

func NewScriptInfo(fileName string, path tspath.Path, scriptKind core.ScriptKind, fs vfs.FS) *ScriptInfo

func (*ScriptInfo) FileName

func (s *ScriptInfo) FileName() string

func (*ScriptInfo) LineMap

func (s *ScriptInfo) LineMap() *ls.LineMap

func (*ScriptInfo) Path

func (s *ScriptInfo) Path() tspath.Path

func (*ScriptInfo) SetTextFromDisk

func (s *ScriptInfo) SetTextFromDisk(newText string)

func (*ScriptInfo) Text

func (s *ScriptInfo) Text() string

func (*ScriptInfo) Version

func (s *ScriptInfo) Version() int

type Service

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

func NewService

func NewService(host ServiceHost, options ServiceOptions) *Service

func (*Service) ChangeFile

func (*Service) Client

func (s *Service) Client() Client

Client implements ProjectHost.

func (*Service) Close

func (s *Service) Close()

func (*Service) CloseFile

func (s *Service) CloseFile(fileName string)

func (*Service) DefaultLibraryPath

func (s *Service) DefaultLibraryPath() string

DefaultLibraryPath implements ProjectHost.

func (*Service) DocumentRegistry

func (s *Service) DocumentRegistry() *DocumentRegistry

DocumentRegistry implements ProjectHost.

func (*Service) EnsureDefaultProjectForFile

func (s *Service) EnsureDefaultProjectForFile(fileName string) (*ScriptInfo, *Project)

func (*Service) EnsureDefaultProjectForURI

func (s *Service) EnsureDefaultProjectForURI(url lsproto.DocumentUri) *Project

func (*Service) FS

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

FS implements ProjectHost.

func (*Service) GetCurrentDirectory

func (s *Service) GetCurrentDirectory() string

GetCurrentDirectory implements ProjectHost.

func (*Service) GetOrCreateScriptInfoForFile

func (s *Service) GetOrCreateScriptInfoForFile(fileName string, path tspath.Path, scriptKind core.ScriptKind) *ScriptInfo

GetOrCreateScriptInfoForFile implements ProjectHost.

func (*Service) GetScriptInfo

func (s *Service) GetScriptInfo(fileName string) *ScriptInfo

func (*Service) GetScriptInfoByPath

func (s *Service) GetScriptInfoByPath(path tspath.Path) *ScriptInfo

func (*Service) IsWatchEnabled

func (s *Service) IsWatchEnabled() bool

IsWatchEnabled implements ProjectHost.

func (*Service) Log

func (s *Service) Log(msg string)

Log implements ProjectHost.

func (*Service) MarkFileSaved

func (s *Service) MarkFileSaved(fileName string, text string)

func (*Service) NewLine

func (s *Service) NewLine() string

NewLine implements ProjectHost.

func (s *Service) OnDiscoveredSymlink(info *ScriptInfo)

func (*Service) OnWatchedFilesChanged

func (s *Service) OnWatchedFilesChanged(ctx context.Context, changes []*lsproto.FileEvent) error

func (*Service) OpenFile

func (s *Service) OpenFile(fileName string, fileContent string, scriptKind core.ScriptKind, projectRootPath string)

func (*Service) PositionEncoding

func (s *Service) PositionEncoding() lsproto.PositionEncodingKind

PositionEncoding implements ProjectHost.

func (*Service) Projects

func (s *Service) Projects() []*Project

func (*Service) SourceFileCount

func (s *Service) SourceFileCount() int

SourceFileCount should only be used for testing.

type ServiceHost

type ServiceHost interface {
	FS() vfs.FS
	DefaultLibraryPath() string
	GetCurrentDirectory() string
	NewLine() string

	Client() Client
}

type ServiceOptions

type ServiceOptions struct {
	Logger           *Logger
	PositionEncoding lsproto.PositionEncodingKind
	WatchEnabled     bool
}

type WatcherHandle

type WatcherHandle string

Jump to

Keyboard shortcuts

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