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 DocumentRegistry
- type DocumentRegistryHooks
- type Kind
- type LogLevel
- type Logger
- type NameValidationResult
- type NpmConfig
- type NpmDependecyEntry
- type NpmInstallOperation
- type NpmLock
- type PendingReload
- type PendingRequest
- type Project
- func (p *Project) AddRoot(info *ScriptInfo)
- 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) GetRootFileNames() []string
- func (p *Project) GetSourceFile(fileName string, path tspath.Path, languageVersion core.ScriptTarget) *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, detachFromProject bool)
- 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 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) DefaultLibraryPath() string
- func (s *Service) DocumentRegistry() *DocumentRegistry
- 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) GetOrCreateScriptInfoForFile(fileName string, path tspath.Path, scriptKind core.ScriptKind) *ScriptInfo
- func (s *Service) GetScriptInfo(fileName string) *ScriptInfo
- func (s *Service) GetScriptInfoByPath(path tspath.Path) *ScriptInfo
- func (s *Service) HasLevel(level LogLevel) bool
- 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) OnDiscoveredSymlink(info *ScriptInfo)
- 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) SourceFileCount() int
- func (s *Service) TypingsInstaller() *TypingsInstaller
- type ServiceHost
- type ServiceOptions
- type TypingsInfo
- type TypingsInstaller
- 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 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 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 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) 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) GetRootFileNames ¶
func (*Project) GetSourceFile ¶
func (p *Project) GetSourceFile(fileName string, path tspath.Path, languageVersion core.ScriptTarget) *ast.SourceFile
GetSourceFile implements compiler.CompilerHost.
func (*Project) LoadConfig ¶
func (*Project) MarkFileAsDirty ¶
func (*Project) RemoveFile ¶
func (p *Project) RemoveFile(info *ScriptInfo, fileExists bool, detachFromProject bool)
func (*Project) UpdateTypingFiles ¶
func (p *Project) UpdateTypingFiles(typingsInfo *TypingsInfo, typingFiles []string)
func (*Project) WatchTypingLocations ¶
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 (s *Service) ChangeFile(document lsproto.VersionedTextDocumentIdentifier, changes []lsproto.TextDocumentContentChangeEvent) error
func (*Service) DefaultLibraryPath ¶
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) GetCurrentDirectory ¶
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 ¶
IsWatchEnabled implements ProjectHost.
func (*Service) MarkFileSaved ¶
func (*Service) OnDiscoveredSymlink ¶
func (s *Service) OnDiscoveredSymlink(info *ScriptInfo)
func (*Service) OnWatchedFilesChanged ¶
func (*Service) PositionEncoding ¶
func (s *Service) PositionEncoding() lsproto.PositionEncodingKind
PositionEncoding implements ProjectHost.
func (*Service) SourceFileCount ¶
SourceFileCount should only be used for testing.
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 }
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 WatcherHandle ¶
type WatcherHandle string