Documentation
¶
Index ¶
- Constants
- func DiscoverTypings(fs vfs.FS, log func(s string), typingsInfo *TypingsInfo, fileNames []string, ...) (cachedTypingPaths []string, newTypingNames []string, filesToWatch []string)
- func InstallNpmPackages(packageNames []string, ...) bool
- func IsTypingUpToDate(cachedTyping *CachedTyping, availableTypingVersions map[string]string) bool
- func NpmInstall(cwd string, npmInstallArgs []string) ([]byte, error)
- func RenderPackageNameValidationFailure(typing string, result NameValidationResult, name string, isScopeName bool) string
- type CachedTyping
- type Client
- type ConfigFileEntry
- type ConfigFileRegistry
- type DocumentRegistry
- type DocumentRegistryHooks
- type DocumentStore
- func (ds *DocumentStore) AddRealpathMapping(info *ScriptInfo)
- func (ds *DocumentStore) DeleteScriptInfo(info *ScriptInfo)
- func (ds *DocumentStore) DocumentRegistry() *DocumentRegistry
- func (ds *DocumentStore) ForEachScriptInfo(fn func(info *ScriptInfo))
- func (ds *DocumentStore) GetOrCreateOpenScriptInfo(fileName string, path tspath.Path, fileContent string, ...) *ScriptInfo
- func (ds *DocumentStore) GetOrCreateScriptInfo(fileName string, path tspath.Path, scriptKind core.ScriptKind, fs vfs.FS) *ScriptInfo
- func (ds *DocumentStore) GetScriptInfoByPath(path tspath.Path) *ScriptInfo
- func (ds *DocumentStore) ScriptInfoCount() int
- func (ds *DocumentStore) SourceFileCount() int
- type DocumentStoreOptions
- type ExtendedConfigFileEntry
- type Kind
- type LogLevel
- type Logger
- type NameValidationResult
- type NpmConfig
- type NpmDependecyEntry
- type NpmInstallOperation
- type NpmLock
- type ParsedFileCache
- type PendingReload
- type PendingRequest
- type Project
- func (p *Project) AddInferredProjectRoot(info *ScriptInfo)
- func (p *Project) Client() Client
- func (p *Project) Close()
- func (p *Project) CurrentProgram() *compiler.Program
- func (p *Project) DefaultLibraryPath() string
- func (p *Project) FS() vfs.FS
- func (p *Project) GetCompilerOptions() *core.CompilerOptions
- func (p *Project) GetCurrentDirectory() string
- func (p *Project) GetDefaultLibraryPath() string
- func (p *Project) GetFileNames(excludeFilesFromExternalLibraries bool, excludeConfigFiles bool) []string
- func (p *Project) GetLanguageServiceForRequest(ctx context.Context) (*ls.LanguageService, func())
- func (p *Project) GetProgram() *compiler.Program
- func (p *Project) GetResolvedProjectReference(fileName string, path tspath.Path) *tsoptions.ParsedCommandLine
- func (p *Project) GetRootFileNames() []string
- func (p *Project) GetSourceFile(opts ast.SourceFileParseOptions) *ast.SourceFile
- func (p *Project) Kind() Kind
- func (p *Project) LoadConfig() error
- func (p *Project) Log(s string)
- func (p *Project) Logf(format string, args ...interface{})
- func (p *Project) MarkFileAsDirty(path tspath.Path)
- func (p *Project) Name() string
- func (p *Project) NewLine() string
- func (p *Project) RemoveFile(info *ScriptInfo, fileExists bool)
- func (p *Project) SetPendingReload(level PendingReload)
- func (p *Project) Trace(msg string)
- func (p *Project) UpdateTypingFiles(typingsInfo *TypingsInfo, typingFiles []string)
- func (p *Project) Version() int
- func (p *Project) WatchTypingLocations(files []string)
- type ProjectHost
- type ResolutionWithLookupLocations
- type ScriptInfo
- type Service
- func (s *Service) ChangeFile(document lsproto.VersionedTextDocumentIdentifier, ...) error
- func (s *Service) Client() Client
- func (s *Service) Close()
- func (s *Service) CloseFile(fileName string)
- func (s *Service) ConfigFileRegistry() *ConfigFileRegistry
- func (s *Service) ConfiguredProject(path tspath.Path) *Project
- func (s *Service) Converters() *ls.Converters
- func (s *Service) DefaultLibraryPath() string
- func (s *Service) DocumentStore() *DocumentStore
- func (s *Service) EnsureDefaultProjectForFile(fileName string) (*ScriptInfo, *Project)
- func (s *Service) EnsureDefaultProjectForURI(url lsproto.DocumentUri) *Project
- func (s *Service) FS() vfs.FS
- func (s *Service) GetCurrentDirectory() string
- func (s *Service) HasLevel(level LogLevel) bool
- func (s *Service) InferredProject(rootPath tspath.Path) *Project
- func (s *Service) IsWatchEnabled() bool
- func (s *Service) Log(msg string)
- func (s *Service) MarkFileSaved(fileName string, text string)
- func (s *Service) NewLine() string
- func (s *Service) OnWatchedFilesChanged(ctx context.Context, changes []*lsproto.FileEvent) error
- func (s *Service) OpenFile(fileName string, fileContent string, scriptKind core.ScriptKind, ...)
- func (s *Service) PositionEncoding() lsproto.PositionEncodingKind
- func (s *Service) Projects() []*Project
- func (s *Service) SetCompilerOptionsForInferredProjects(compilerOptions *core.CompilerOptions)
- func (s *Service) Trace(msg string)
- func (s *Service) TypingsInstaller() *TypingsInstaller
- type ServiceHost
- type ServiceOptions
- type TypingsInfo
- type TypingsInstaller
- func (ti *TypingsInstaller) EnqueueInstallTypingsRequest(p *Project, typingsInfo *TypingsInfo)
- func (ti *TypingsInstaller) InstallPackage(p *Project, fileName string, packageName string)
- func (ti *TypingsInstaller) IsKnownTypesPackageName(p *Project, name string) bool
- func (ti *TypingsInstaller) PendingRunRequestsCount() int
- type TypingsInstallerOptions
- type TypingsInstallerStatus
- type WatcherHandle
Constants ¶
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 IsTypingUpToDate ¶
func IsTypingUpToDate(cachedTyping *CachedTyping, availableTypingVersions map[string]string) bool
func RenderPackageNameValidationFailure ¶
func RenderPackageNameValidationFailure(typing string, result NameValidationResult, name string, isScopeName bool) string
* @internal
Types ¶
type CachedTyping ¶
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 ConfigFileEntry ¶
type ConfigFileEntry struct {
// contains filtered or unexported fields
}
func (*ConfigFileEntry) SetPendingReload ¶
func (e *ConfigFileEntry) SetPendingReload(level PendingReload) bool
type ConfigFileRegistry ¶
type ConfigFileRegistry struct { Host ProjectHost ConfigFiles collections.SyncMap[tspath.Path, *ConfigFileEntry] ExtendedConfigCache collections.SyncMap[tspath.Path, *tsoptions.ExtendedConfigCacheEntry] ExtendedConfigsUsedBy collections.SyncMap[tspath.Path, *ExtendedConfigFileEntry] // contains filtered or unexported fields }
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, opts ast.SourceFileParseOptions, oldSourceFile *ast.SourceFile) *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)
type DocumentRegistryHooks ¶
type DocumentRegistryHooks struct {
OnReleaseDocument func(file *ast.SourceFile)
}
type DocumentStore ¶
type DocumentStore struct {
// contains filtered or unexported fields
}
DocumentStore manages ScriptInfo instances and the DocumentRegistry with thread-safe operations.
func NewDocumentStore ¶
func NewDocumentStore(options DocumentStoreOptions) *DocumentStore
NewDocumentStore creates a new DocumentStore with the given options
func (*DocumentStore) AddRealpathMapping ¶
func (ds *DocumentStore) AddRealpathMapping(info *ScriptInfo)
AddRealpathMapping adds a realpath mapping for a ScriptInfo
func (*DocumentStore) DeleteScriptInfo ¶
func (ds *DocumentStore) DeleteScriptInfo(info *ScriptInfo)
DeleteScriptInfo removes a ScriptInfo from the store
func (*DocumentStore) DocumentRegistry ¶
func (ds *DocumentStore) DocumentRegistry() *DocumentRegistry
DocumentRegistry returns the document registry
func (*DocumentStore) ForEachScriptInfo ¶
func (ds *DocumentStore) ForEachScriptInfo(fn func(info *ScriptInfo))
ForEachScriptInfo calls the given function for each ScriptInfo in the store
func (*DocumentStore) GetOrCreateOpenScriptInfo ¶
func (ds *DocumentStore) GetOrCreateOpenScriptInfo(fileName string, path tspath.Path, fileContent string, scriptKind core.ScriptKind, fs vfs.FS) *ScriptInfo
GetOrCreateOpenScriptInfo creates or returns an existing ScriptInfo for an opened file
func (*DocumentStore) GetOrCreateScriptInfo ¶
func (ds *DocumentStore) GetOrCreateScriptInfo(fileName string, path tspath.Path, scriptKind core.ScriptKind, fs vfs.FS) *ScriptInfo
GetOrCreateScriptInfo creates or returns an existing ScriptInfo for the given file
func (*DocumentStore) GetScriptInfoByPath ¶
func (ds *DocumentStore) GetScriptInfoByPath(path tspath.Path) *ScriptInfo
GetScriptInfoByPath returns the ScriptInfo for the given path, or nil if not found
func (*DocumentStore) ScriptInfoCount ¶
func (ds *DocumentStore) ScriptInfoCount() int
func (*DocumentStore) SourceFileCount ¶
func (ds *DocumentStore) SourceFileCount() int
SourceFileCount returns the number of documents in the registry
type DocumentStoreOptions ¶
type DocumentStoreOptions struct { ComparePathsOptions tspath.ComparePathsOptions ParsedFileCache ParsedFileCache Hooks DocumentRegistryHooks }
DocumentStoreOptions contains options for creating a DocumentStore
type ExtendedConfigFileEntry ¶
type ExtendedConfigFileEntry struct {
// contains filtered or unexported fields
}
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func (*Logger) LoggingEnabled ¶
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)
*
- Validates package name using rules defined at https://docs.npmjs.com/files/package.json *
- @internal
type NpmDependecyEntry ¶
type NpmDependecyEntry struct {
Version string `json:"version"`
}
type NpmLock ¶
type NpmLock struct { Dependencies map[string]NpmDependecyEntry `json:"dependencies"` Packages map[string]NpmDependecyEntry `json:"packages"` }
type ParsedFileCache ¶
type ParsedFileCache interface { GetFile(opts ast.SourceFileParseOptions, text string, scriptKind core.ScriptKind) *ast.SourceFile CacheFile(opts ast.SourceFileParseOptions, text string, scriptKind core.ScriptKind, sourceFile *ast.SourceFile) }
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) AddInferredProjectRoot ¶
func (p *Project) AddInferredProjectRoot(info *ScriptInfo)
func (*Project) CurrentProgram ¶
func (*Project) DefaultLibraryPath ¶
DefaultLibraryPath implements compiler.CompilerHost.
func (*Project) GetCompilerOptions ¶
func (p *Project) GetCompilerOptions() *core.CompilerOptions
func (*Project) GetCurrentDirectory ¶
GetCurrentDirectory implements compiler.CompilerHost.
func (*Project) GetDefaultLibraryPath ¶
GetDefaultLibraryPath implements compiler.CompilerHost.
func (*Project) GetFileNames ¶
func (*Project) GetLanguageServiceForRequest ¶
func (p *Project) GetLanguageServiceForRequest(ctx context.Context) (*ls.LanguageService, func())
func (*Project) GetProgram ¶
Updates the program if needed.
func (*Project) GetResolvedProjectReference ¶
func (p *Project) GetResolvedProjectReference(fileName string, path tspath.Path) *tsoptions.ParsedCommandLine
GetResolvedProjectReference implements compiler.CompilerHost.
func (*Project) GetRootFileNames ¶
func (*Project) GetSourceFile ¶
func (p *Project) GetSourceFile(opts ast.SourceFileParseOptions) *ast.SourceFile
GetSourceFile implements compiler.CompilerHost.
func (*Project) LoadConfig ¶
func (*Project) MarkFileAsDirty ¶
func (*Project) RemoveFile ¶
func (p *Project) RemoveFile(info *ScriptInfo, fileExists bool)
func (*Project) SetPendingReload ¶
func (p *Project) SetPendingReload(level PendingReload)
func (*Project) UpdateTypingFiles ¶
func (p *Project) UpdateTypingFiles(typingsInfo *TypingsInfo, typingFiles []string)
func (*Project) WatchTypingLocations ¶
type ProjectHost ¶
type ProjectHost interface { tsoptions.ParseConfigHost module.ResolutionHost NewLine() string DefaultLibraryPath() string TypingsInstaller() *TypingsInstaller DocumentStore() *DocumentStore ConfigFileRegistry() *ConfigFileRegistry Log(s string) PositionEncoding() lsproto.PositionEncodingKind IsWatchEnabled() bool Client() Client }
type ResolutionWithLookupLocations ¶
type ResolutionWithLookupLocations interface {
GetLookupLocations() *module.LookupLocations
}
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) ContainingProjects ¶
func (s *ScriptInfo) ContainingProjects() []*Project
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 (s *Service) ChangeFile(document lsproto.VersionedTextDocumentIdentifier, changes []lsproto.TextDocumentContentChangeEvent) error
func (*Service) ConfigFileRegistry ¶
func (s *Service) ConfigFileRegistry() *ConfigFileRegistry
ConfigFileRegistry implements ProjectHost.
func (*Service) Converters ¶
func (s *Service) Converters() *ls.Converters
func (*Service) DefaultLibraryPath ¶
DefaultLibraryPath implements ProjectHost.
func (*Service) DocumentStore ¶
func (s *Service) DocumentStore() *DocumentStore
DocumentStore 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) GetCurrentDirectory ¶
GetCurrentDirectory implements ProjectHost.
func (*Service) IsWatchEnabled ¶
IsWatchEnabled implements ProjectHost.
func (*Service) MarkFileSaved ¶
func (*Service) OnWatchedFilesChanged ¶
func (*Service) PositionEncoding ¶
func (s *Service) PositionEncoding() lsproto.PositionEncodingKind
PositionEncoding implements ProjectHost.
func (*Service) SetCompilerOptionsForInferredProjects ¶
func (s *Service) SetCompilerOptionsForInferredProjects(compilerOptions *core.CompilerOptions)
!!! per root compiler options
func (*Service) TypingsInstaller ¶
func (s *Service) TypingsInstaller() *TypingsInstaller
TypingsInstaller implements ProjectHost.
type ServiceHost ¶
type ServiceOptions ¶
type ServiceOptions struct { TypingsInstallerOptions Logger *Logger PositionEncoding lsproto.PositionEncodingKind WatchEnabled bool ParsedFileCache ParsedFileCache }
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
func (*TypingsInstaller) PendingRunRequestsCount ¶
func (ti *TypingsInstaller) PendingRunRequestsCount() int
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 WatcherHandle ¶
type WatcherHandle string