Documentation
¶
Index ¶
- func TypeToAutoImportableTypeNode(c *checker.Checker, importAdder ImportAdder, t *checker.Type, ...) *ast.TypeNode
- type BucketState
- type BucketStats
- type CacheStats
- type Export
- type ExportID
- type ExportSyntax
- type Fix
- type FixAndExport
- type ImportAdder
- type Index
- type ModuleID
- type Named
- type QueryKind
- type Registry
- func (r *Registry) Clone(ctx context.Context, change RegistryChange, host RegistryCloneHost, ...) (*Registry, error)
- func (r *Registry) GetCacheStats() *CacheStats
- func (r *Registry) IsPreparedForImportingFile(fileName string, projectPath tspath.Path, preferences *lsutil.UserPreferences) bool
- func (r *Registry) NodeModulesDirectories() map[tspath.Path]string
- type RegistryBucket
- type RegistryChange
- type RegistryCloneHost
- type View
- func (v *View) CompareFixesForRanking(a, b *Fix) int
- func (v *View) CompareFixesForSorting(a, b *Fix) int
- func (v *View) GetCompletions(ctx context.Context, prefix string, position lsproto.Position, forJSX bool, ...) []*FixAndExport
- func (v *View) GetFixes(ctx context.Context, export *Export, forJSX bool, isValidTypeOnlyUseSite bool, ...) []*Fix
- func (v *View) GetModuleSpecifier(export *Export, userPreferences modulespecifiers.UserPreferences) (string, modulespecifiers.ResultKind)
- func (v *View) Search(query string, kind QueryKind) []*Export
- func (v *View) SearchByExportID(id ExportID) []*Export
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BucketState ¶
type BucketState struct {
// contains filtered or unexported fields
}
BucketState represents the dirty state of a bucket. In general, a bucket can be used for an auto-imports request if it is clean or if the only edited file is the one that was requested for auto-imports. Most edits within a file will not change the imports available to that file. However, one exception causes the bucket to be rebuilt after a change to a single file: local files are newly added to the project by a manual import. This can only happen after a full (non-clone) program update. When this happens, the `newProgramStructure` flag is set until the next time the bucket is rebuilt, when this condition will be checked.
func (BucketState) Dirty ¶
func (b BucketState) Dirty() bool
func (BucketState) DirtyFile ¶
func (b BucketState) DirtyFile() tspath.Path
func (BucketState) DirtyPackages ¶
func (b BucketState) DirtyPackages() *collections.Set[string]
type BucketStats ¶
type BucketStats struct {
Path tspath.Path
ExportCount int
FileCount int
State BucketState
DependencyNames *collections.Set[string]
PackageNames *collections.Set[string]
}
type CacheStats ¶
type CacheStats struct {
ProjectBuckets []BucketStats
NodeModulesBuckets []BucketStats
}
type Export ¶
type Export struct {
ExportID
ModuleFileName string
Syntax ExportSyntax
Flags ast.SymbolFlags
Target ExportID
IsTypeOnly bool
ScriptElementKind lsutil.ScriptElementKind
ScriptElementKindModifiers collections.Set[lsutil.ScriptElementKindModifier]
// The file where the export was found.
Path tspath.Path
NodeModulesDirectory tspath.Path
PackageName string
// contains filtered or unexported fields
}
func (*Export) AmbientModuleName ¶
func (*Export) IsRenameable ¶
func (*Export) IsUnresolvedAlias ¶
type ExportSyntax ¶
type ExportSyntax int
const ( ExportSyntaxNone ExportSyntax = iota // export const x = {} ExportSyntaxModifier // export { x } ExportSyntaxNamed // export default function f() {} ExportSyntaxDefaultModifier // export default f ExportSyntaxDefaultDeclaration // export = x ExportSyntaxEquals // export as namespace x ExportSyntaxUMD // export * from "module" ExportSyntaxStar // module.exports = {} ExportSyntaxCommonJSModuleExports // exports.x = {} ExportSyntaxCommonJSExportsProperty )
func (ExportSyntax) String ¶
func (i ExportSyntax) String() string
type Fix ¶
type Fix struct {
*lsproto.AutoImportFix
ModuleSpecifierKind modulespecifiers.ResultKind
IsReExport bool
ModuleFileName string
TypeOnlyAliasDeclaration *ast.Declaration
}
func (*Fix) Edits ¶
func (f *Fix) Edits( ctx context.Context, file *ast.SourceFile, compilerOptions *core.CompilerOptions, formatOptions *lsutil.FormatCodeSettings, converters *lsconv.Converters, preferences *lsutil.UserPreferences, ) ([]*lsproto.TextEdit, string)
type FixAndExport ¶
type ImportAdder ¶
type ImportAdder interface {
HasFixes() bool
AddImportFromExportedSymbol(symbol *ast.Symbol, isValidTypeOnlyUseSite bool)
Edits() []*lsproto.TextEdit
}
func NewImportAdder ¶
func NewImportAdder( ctx context.Context, program *compiler.Program, checker *checker.Checker, file *ast.SourceFile, view *View, formatOptions *lsutil.FormatCodeSettings, converters *lsconv.Converters, preferences *lsutil.UserPreferences, ) ImportAdder
type Index ¶
type Index[T Named] struct { // contains filtered or unexported fields }
Index stores entries with an index mapping uppercase letters to entries whose name starts with that letter, and lowercase letters to entries whose name contains a word starting with that letter.
func (*Index[T]) Clone ¶
Clone creates a new Index containing only entries for which filter returns true.
func (*Index[T]) SearchWordPrefix ¶
SearchWordPrefix returns each entry whose name contains a word beginning with the first character of 'prefix', and whose name contains all characters of 'prefix' in order (case-insensitive). If 'filter' is provided, only entries for which filter(entry) returns true are included.
type ModuleID ¶
type ModuleID string
ModuleID uniquely identifies a module across multiple declarations. If the export is from an ambient module declaration, this is the module name. If the export is from a module augmentation, this is the Path() of the resolved module file. Otherwise this is the Path() of the exporting source file.
type Named ¶
type Named interface {
Name() string
}
Named is a constraint for types that can provide their name.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func (*Registry) Clone ¶
func (r *Registry) Clone(ctx context.Context, change RegistryChange, host RegistryCloneHost, logger *logging.LogTree) (*Registry, error)
func (*Registry) GetCacheStats ¶
func (r *Registry) GetCacheStats() *CacheStats
func (*Registry) IsPreparedForImportingFile ¶
type RegistryBucket ¶
type RegistryBucket struct {
// Paths maps file paths to package names. For project buckets, the package name
// is always empty string. For node_modules buckets, this enables reverse lookup
// from path to package for granular updates. Only paths eligible for granular
// update (project reference packages) have entries here.
Paths map[tspath.Path]string
// PackageFiles maps package names to their file paths and file names.
// All package directory names in node_modules are keys; indexed packages have
// non-nil maps with path→fileName entries, unindexed packages have nil maps.
// This enables efficient removal of a package's files during granular updates
// without iterating through all entries. Only defined for node_modules buckets.
PackageFiles map[string]map[tspath.Path]string
// ResolvedPackageNames is only defined for project buckets. It is the set of
// package names that were resolved from imports in the project's program files.
// This is passed to node_modules buckets so they include packages that are
// directly imported even if not listed in package.json dependencies.
ResolvedPackageNames *collections.Set[string]
// DependencyNames is only defined for node_modules buckets. It is the set of
// package names that will be included in the bucket if present in the directory,
// computed from package.json dependencies plus resolved package names from
// active programs. If nil, all packages are included because at least one open
// file has access to this node_modules directory without being filtered by a
// package.json.
DependencyNames *collections.Set[string]
// AmbientModuleNames is only defined for node_modules buckets. It is the set of
// ambient module names found while extracting exports in the bucket.
AmbientModuleNames map[string][]string
// Entrypoints is only defined for node_modules buckets. Keys are package entrypoint
// file paths, and values describe the ways of importing the package that would resolve
// to that file.
Entrypoints map[tspath.Path][]*module.ResolvedEntrypoint
Index *Index[*Export]
// contains filtered or unexported fields
}
func (*RegistryBucket) Clone ¶
func (b *RegistryBucket) Clone() *RegistryBucket
type RegistryChange ¶
type RegistryChange struct {
RequestedFile tspath.Path
OpenFiles map[tspath.Path]string
Changed collections.Set[lsproto.DocumentUri]
Created collections.Set[lsproto.DocumentUri]
Deleted collections.Set[lsproto.DocumentUri]
// RebuiltPrograms maps from project path to:
// - true: the program was rebuilt with a different set of file names
// - false: the program was rebuilt but the set of file names is unchanged
RebuiltPrograms map[tspath.Path]bool
UserPreferences *lsutil.UserPreferences
}
type RegistryCloneHost ¶
type RegistryCloneHost interface {
module.ResolutionHost
FS() vfs.FS
GetDefaultProject(path tspath.Path) (tspath.Path, *compiler.Program)
GetProgramForProject(projectPath tspath.Path) *compiler.Program
GetPackageJson(fileName string) *packagejson.InfoCacheEntry
GetSourceFile(fileName string, path tspath.Path) *ast.SourceFile
Dispose()
}
type View ¶
type View struct {
// contains filtered or unexported fields
}
func NewView ¶
func NewView(registry *Registry, importingFile *ast.SourceFile, projectKey tspath.Path, program *compiler.Program, preferences modulespecifiers.UserPreferences) *View
func (*View) CompareFixesForRanking ¶
CompareFixesForRanking returns negative if `a` is better than `b`. Sorting with this comparator will place the best fix first. Fixes of equal desirability will be considered equal.
func (*View) CompareFixesForSorting ¶
CompareFixesForSorting returns negative if `a` is better than `b`. Sorting with this comparator will place the best fix first. After rank sorting, fixes will be sorted by arbitrary but stable criteria to ensure a deterministic order.
func (*View) GetCompletions ¶
func (*View) GetModuleSpecifier ¶
func (v *View) GetModuleSpecifier( export *Export, userPreferences modulespecifiers.UserPreferences, ) (string, modulespecifiers.ResultKind)