project

package
v0.0.0-...-a4721f4 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const TsVersionToUse = "latest"

!!! sheetal currently we use latest instead of core.VersionMajorMinor()

Variables

This section is empty.

Functions

func DiscoverTypings

func DiscoverTypings(
	fs vfs.FS,
	log func(s string),
	typingsInfo *TypingsInfo,
	fileNames []string,
	projectRootPath string,
	packageNameToTypingLocation *collections.SyncMap[string, *CachedTyping],
	typesRegistry map[string]map[string]string,
) (cachedTypingPaths []string, newTypingNames []string, filesToWatch []string)

func InstallNpmPackages

func InstallNpmPackages(
	packageNames []string,
	installPackages func(packages []string, hasError *atomic.Bool),
) bool

func IsTypingUpToDate

func IsTypingUpToDate(cachedTyping *CachedTyping, availableTypingVersions map[string]string) bool

func NpmInstall

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

func RenderPackageNameValidationFailure

func RenderPackageNameValidationFailure(typing string, result NameValidationResult, name string, isScopeName bool) string

* @internal

Types

type CachedTyping

type CachedTyping struct {
	TypingsLocation string
	Version         semver.Version
}

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

type NameValidationResult

type NameValidationResult int
const (
	NameOk NameValidationResult = iota
	EmptyName
	NameTooLong
	NameStartsWithDot
	NameStartsWithUnderscore
	NameContainsNonURISafeCharacters
)

func ValidatePackageName

func ValidatePackageName(packageName string) (result NameValidationResult, name string, isScopeName bool)

*

type NpmConfig

type NpmConfig struct {
	DevDependencies map[string]any `json:"devDependencies"`
}

type NpmDependecyEntry

type NpmDependecyEntry struct {
	Version string `json:"version"`
}

type NpmInstallOperation

type NpmInstallOperation func(string, []string) ([]byte, error)

type NpmLock

type NpmLock struct {
	Dependencies map[string]NpmDependecyEntry `json:"dependencies"`
	Packages     map[string]NpmDependecyEntry `json:"packages"`
}

type PendingReload

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

type PendingRequest

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

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

func (p *Project) GetFileNames(excludeFilesFromExternalLibraries bool, excludeConfigFiles bool) []string

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

func (p *Project) Log(s string)

func (*Project) Logf

func (p *Project) Logf(format string, args ...interface{})

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

func (p *Project) UpdateTypingFiles(typingsInfo *TypingsInfo, typingFiles []string)

func (*Project) Version

func (p *Project) Version() int

func (*Project) WatchTypingLocations

func (p *Project) WatchTypingLocations(files []string)

type ProjectHost

type ProjectHost interface {
	tsoptions.ParseConfigHost
	NewLine() string
	DefaultLibraryPath() string
	TypingsInstaller() *TypingsInstaller
	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) HasLevel

func (s *Service) HasLevel(level LogLevel) bool

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.

func (*Service) TypingsInstaller

func (s *Service) TypingsInstaller() *TypingsInstaller

TypingsInstaller implements ProjectHost.

type ServiceHost

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

	Client() Client
}

type ServiceOptions

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

type TypingsInfo

type TypingsInfo struct {
	TypeAcquisition   *core.TypeAcquisition
	CompilerOptions   *core.CompilerOptions
	UnresolvedImports []string
}

type TypingsInstaller

type TypingsInstaller struct {
	TypingsLocation string
	// contains filtered or unexported fields
}

func (*TypingsInstaller) EnqueueInstallTypingsRequest

func (ti *TypingsInstaller) EnqueueInstallTypingsRequest(p *Project, typingsInfo *TypingsInfo)

func (*TypingsInstaller) InstallPackage

func (ti *TypingsInstaller) InstallPackage(p *Project, fileName string, packageName string)

func (*TypingsInstaller) IsKnownTypesPackageName

func (ti *TypingsInstaller) IsKnownTypesPackageName(p *Project, name string) bool

type TypingsInstallerOptions

type TypingsInstallerOptions struct {
	// !!! sheetal strada params to keep or not
	// 	const typingSafeListLocation = ts.server.findArgument(ts.server.Arguments.TypingSafeListLocation);
	// const typesMapLocation = ts.server.findArgument(ts.server.Arguments.TypesMapLocation);
	// const npmLocation = ts.server.findArgument(ts.server.Arguments.NpmLocation);
	// const validateDefaultNpmLocation = ts.server.hasArgument(ts.server.Arguments.ValidateDefaultNpmLocation);
	ThrottleLimit int

	// For testing
	NpmInstall    NpmInstallOperation
	InstallStatus chan TypingsInstallerStatus
}

type TypingsInstallerStatus

type TypingsInstallerStatus struct {
	RequestId int32
	Project   *Project
	Status    string
}

type WatcherHandle

type WatcherHandle string

Jump to

Keyboard shortcuts

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