ls

package
v0.0.0-...-b62c2c2 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Completions that require `this.` insertion text
	SourceThisProperty = "ThisProperty/"
	// Auto-import that comes attached to a class member snippet
	SourceClassMemberSnippet = "ClassMemberSnippet/"
	// A type-only import that needs to be promoted in order to be used at the completion location
	SourceTypeOnlyAlias = "TypeOnlyAlias/"
	// Auto-import that comes attached to an object literal method snippet
	SourceObjectLiteralMethodSnippet = "ObjectLiteralMethodSnippet/"
	// Case completions for switch statements
	SourceSwitchCases = "SwitchCases/"
	// Completions for an object literal expression
	SourceObjectLiteralMemberWithComma = "ObjectLiteralMemberWithComma/"
)

Special values for `CompletionInfo['source']` used to disambiguate completion items with the same `name`. (Each completion item must have a unique name/source combination, because those two fields comprise `CompletionEntryIdentifier` in `getCompletionEntryDetails`.

When the completion item is an auto-import suggestion, the source is the module specifier of the suggestion. To avoid collisions, the values here should not be a module specifier we would ever generate for an auto-import.

Variables

View Source
var (
	ErrNoSourceFile      = errors.New("source file not found")
	ErrNoTokenAtPosition = errors.New("no token found at position")
)
View Source
var ErrNeedsAutoImports = errors.New("completion list needs auto imports")
View Source
var ImportFixProvider = &CodeFixProvider{
	ErrorCodes:     importFixErrorCodes,
	GetCodeActions: getImportCodeActions,
	FixIds:         []string{importFixID},
}

ImportFixProvider is the CodeFixProvider for import-related fixes

View Source
var TriggerCharacters = []string{".", `"`, "'", "`", "/", "@", "<", "#", " "}

Functions

func CompareCompletionEntries

func CompareCompletionEntries(a, b *lsproto.CompletionItem) int

Editors will use the `sortText` and then fall back to `name` for sorting, but leave ties in response order. So, it's important that we sort those ties in the order we want them displayed if it matters. We don't strictly need to sort by name or SortText here since clients are going to do it anyway, but we have to do the work of comparing them so we can sort those ties appropriately.

func IsInString

func IsInString(sourceFile *ast.SourceFile, position int, previousToken *ast.Node) bool

func ProvideWorkspaceSymbols

func ProvideWorkspaceSymbols(
	ctx context.Context,
	programs []*compiler.Program,
	converters *lsconv.Converters,
	preferences *lsutil.UserPreferences,
	query string,
) (lsproto.WorkspaceSymbolResponse, error)

func RangeContainsRange

func RangeContainsRange(r1 core.TextRange, r2 core.TextRange) bool

Types

type CallHierarchyDeclaration

type CallHierarchyDeclaration = *ast.Node

type CandidateOrTypeInfo

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

type CodeAction

type CodeAction struct {
	Description string
	Changes     []*lsproto.TextEdit
}

CodeAction represents a single code action fix

type CodeFixContext

type CodeFixContext struct {
	SourceFile *ast.SourceFile
	Span       core.TextRange
	ErrorCode  int32
	Program    *compiler.Program
	LS         *LanguageService
	Diagnostic *lsproto.Diagnostic
	Params     *lsproto.CodeActionParams
}

CodeFixContext contains the context needed to generate code fixes

type CodeFixProvider

type CodeFixProvider struct {
	ErrorCodes        []int32
	GetCodeActions    func(ctx context.Context, fixContext *CodeFixContext) ([]CodeAction, error)
	FixIds            []string
	GetAllCodeActions func(ctx context.Context, fixContext *CodeFixContext) (*CombinedCodeActions, error)
}

CodeFixProvider represents a provider for a specific type of code fix

type CombinedCodeActions

type CombinedCodeActions struct {
	Description string
	Changes     []*lsproto.TextEdit
}

CombinedCodeActions represents combined code actions for fix-all scenarios

type CompletionKind

type CompletionKind int
const (
	CompletionKindNone CompletionKind = iota
	CompletionKindObjectPropertyDeclaration
	CompletionKindGlobal
	CompletionKindPropertyAccess
	CompletionKindMemberLike
	CompletionKindString
)

type CompletionsTriggerCharacter

type CompletionsTriggerCharacter = string

"." | '"' | "'" | "`" | "/" | "@" | "<" | "#" | " "

type CrossProjectOrchestrator

type CrossProjectOrchestrator interface {
	GetDefaultProject() Project
	GetAllProjectsForInitialRequest() []Project
	GetLanguageServiceForProjectWithFile(ctx context.Context, project Project, uri lsproto.DocumentUri) *LanguageService
	GetProjectsForFile(ctx context.Context, uri lsproto.DocumentUri) ([]Project, error)
	GetProjectsLoadingProjectTree(ctx context.Context, requestedProjectTrees *collections.Set[tspath.Path]) iter.Seq[Project]
}

type DeclarationInfo

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

type Definition

type Definition struct {
	Kind DefinitionKind
	// contains filtered or unexported fields
}

type DefinitionKind

type DefinitionKind int

type ExportInfo

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

type ExportKind

type ExportKind int
const (
	ExportKindNamed        ExportKind = 0
	ExportKindDefault      ExportKind = 1
	ExportKindExportEquals ExportKind = 2
	ExportKindUMD          ExportKind = 3
	ExportKindModule       ExportKind = 4
)

type Host

type Host interface {
	UseCaseSensitiveFileNames() bool
	ReadFile(path string) (contents string, ok bool)
	Converters() *lsconv.Converters
	UserPreferences() *lsutil.UserPreferences
	FormatOptions() *format.FormatCodeSettings
	GetECMALineInfo(fileName string) *sourcemap.ECMALineInfo
	AutoImportRegistry() *autoimport.Registry
}

type ImpExpKind

type ImpExpKind int32
const (
	ImpExpKindUnknown ImpExpKind = iota
	ImpExpKindImport
	ImpExpKindExport
)

type ImportExportSymbol

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

type ImportTracker

type ImportTracker func(exportSymbol *ast.Symbol, exportInfo *ExportInfo, isForRename bool) *ImportsResult

type ImportsResult

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

type KeywordCompletionFilters

type KeywordCompletionFilters int
const (
	KeywordCompletionFiltersNone                         KeywordCompletionFilters = iota // No keywords
	KeywordCompletionFiltersAll                                                          // Every possible kewyord
	KeywordCompletionFiltersClassElementKeywords                                         // Keywords inside class body
	KeywordCompletionFiltersInterfaceElementKeywords                                     // Keywords inside interface body
	KeywordCompletionFiltersConstructorParameterKeywords                                 // Keywords at constructor parameter
	KeywordCompletionFiltersFunctionLikeBodyKeywords                                     // Keywords at function like body
	KeywordCompletionFiltersTypeAssertionKeywords
	KeywordCompletionFiltersTypeKeywords
	KeywordCompletionFiltersTypeKeyword // Literally just `type`
	KeywordCompletionFiltersLast        = KeywordCompletionFiltersTypeKeyword
)

type LanguageService

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

func NewLanguageService

func NewLanguageService(
	projectPath tspath.Path,
	program *compiler.Program,
	host Host,
) *LanguageService

func (*LanguageService) FormatOptions

func (l *LanguageService) FormatOptions() *format.FormatCodeSettings

func (*LanguageService) GetDocumentPositionMapper

func (l *LanguageService) GetDocumentPositionMapper(fileName string) *sourcemap.DocumentPositionMapper

func (*LanguageService) GetECMALineInfo

func (l *LanguageService) GetECMALineInfo(fileName string) *sourcemap.ECMALineInfo

func (*LanguageService) GetProgram

func (l *LanguageService) GetProgram() *compiler.Program

func (*LanguageService) GetSignatureHelpItems

func (l *LanguageService) GetSignatureHelpItems(
	ctx context.Context,
	position int,
	program *compiler.Program,
	sourceFile *ast.SourceFile,
	context *lsproto.SignatureHelpContext,
) *lsproto.SignatureHelp

func (*LanguageService) GetSymbolAtLocation

func (l *LanguageService) GetSymbolAtLocation(ctx context.Context, node *ast.Node) *ast.Symbol

func (*LanguageService) GetSymbolAtPosition

func (l *LanguageService) GetSymbolAtPosition(ctx context.Context, fileName string, position int) (*ast.Symbol, error)

func (*LanguageService) GetTypeOfSymbol

func (l *LanguageService) GetTypeOfSymbol(ctx context.Context, symbol *ast.Symbol) *checker.Type

func (*LanguageService) ProvideCallHierarchyIncomingCalls

func (l *LanguageService) ProvideCallHierarchyIncomingCalls(
	ctx context.Context,
	item *lsproto.CallHierarchyItem,
	orchestrator CrossProjectOrchestrator,
) (lsproto.CallHierarchyIncomingCallsResponse, error)

func (*LanguageService) ProvideCallHierarchyOutgoingCalls

func (l *LanguageService) ProvideCallHierarchyOutgoingCalls(
	ctx context.Context,
	item *lsproto.CallHierarchyItem,
) (lsproto.CallHierarchyOutgoingCallsResponse, error)

func (*LanguageService) ProvideCodeActions

func (l *LanguageService) ProvideCodeActions(ctx context.Context, params *lsproto.CodeActionParams) (lsproto.CodeActionResponse, error)

ProvideCodeActions returns code actions for the given range and context

func (*LanguageService) ProvideCodeLenses

func (l *LanguageService) ProvideCodeLenses(ctx context.Context, documentURI lsproto.DocumentUri) (lsproto.CodeLensResponse, error)

func (*LanguageService) ProvideCompletion

func (l *LanguageService) ProvideCompletion(
	ctx context.Context,
	documentURI lsproto.DocumentUri,
	LSPPosition lsproto.Position,
	context *lsproto.CompletionContext,
) (lsproto.CompletionResponse, error)

func (*LanguageService) ProvideDefinition

func (l *LanguageService) ProvideDefinition(
	ctx context.Context,
	documentURI lsproto.DocumentUri,
	position lsproto.Position,
) (lsproto.DefinitionResponse, error)

func (*LanguageService) ProvideDiagnostics

func (*LanguageService) ProvideDocumentHighlights

func (l *LanguageService) ProvideDocumentHighlights(ctx context.Context, documentUri lsproto.DocumentUri, documentPosition lsproto.Position) (lsproto.DocumentHighlightResponse, error)

func (*LanguageService) ProvideDocumentSymbols

func (l *LanguageService) ProvideDocumentSymbols(ctx context.Context, documentURI lsproto.DocumentUri) (lsproto.DocumentSymbolResponse, error)

func (*LanguageService) ProvideFoldingRange

func (l *LanguageService) ProvideFoldingRange(ctx context.Context, documentURI lsproto.DocumentUri) (lsproto.FoldingRangeResponse, error)

func (*LanguageService) ProvideFormatDocument

func (l *LanguageService) ProvideFormatDocument(
	ctx context.Context,
	documentURI lsproto.DocumentUri,
	options *lsproto.FormattingOptions,
) (lsproto.DocumentFormattingResponse, error)

func (*LanguageService) ProvideFormatDocumentOnType

func (l *LanguageService) ProvideFormatDocumentOnType(
	ctx context.Context,
	documentURI lsproto.DocumentUri,
	options *lsproto.FormattingOptions,
	position lsproto.Position,
	character string,
) (lsproto.DocumentOnTypeFormattingResponse, error)

func (*LanguageService) ProvideFormatDocumentRange

func (l *LanguageService) ProvideFormatDocumentRange(
	ctx context.Context,
	documentURI lsproto.DocumentUri,
	options *lsproto.FormattingOptions,
	r lsproto.Range,
) (lsproto.DocumentRangeFormattingResponse, error)

func (*LanguageService) ProvideHover

func (l *LanguageService) ProvideHover(ctx context.Context, documentURI lsproto.DocumentUri, position lsproto.Position) (lsproto.HoverResponse, error)

func (*LanguageService) ProvideImplementations

func (*LanguageService) ProvideInlayHint

func (l *LanguageService) ProvideInlayHint(
	ctx context.Context,
	params *lsproto.InlayHintParams,
) (lsproto.InlayHintResponse, error)

func (*LanguageService) ProvidePrepareCallHierarchy

func (l *LanguageService) ProvidePrepareCallHierarchy(
	ctx context.Context,
	documentURI lsproto.DocumentUri,
	position lsproto.Position,
) (lsproto.CallHierarchyPrepareResponse, error)

func (*LanguageService) ProvideReferences

func (*LanguageService) ProvideRename

func (*LanguageService) ProvideSelectionRanges

func (*LanguageService) ProvideSignatureHelp

func (l *LanguageService) ProvideSignatureHelp(
	ctx context.Context,
	documentURI lsproto.DocumentUri,
	position lsproto.Position,
	context *lsproto.SignatureHelpContext,
) (lsproto.SignatureHelpResponse, error)

func (*LanguageService) ProvideTypeDefinition

func (l *LanguageService) ProvideTypeDefinition(
	ctx context.Context,
	documentURI lsproto.DocumentUri,
	position lsproto.Position,
) (lsproto.TypeDefinitionResponse, error)

func (*LanguageService) ReadFile

func (l *LanguageService) ReadFile(fileName string) (string, bool)

func (*LanguageService) ResolveCodeLens

func (l *LanguageService) ResolveCodeLens(ctx context.Context, codeLens *lsproto.CodeLens, showLocationsCommandName *string, orchestrator CrossProjectOrchestrator) (*lsproto.CodeLens, error)

func (*LanguageService) ResolveCompletionItem

func (l *LanguageService) ResolveCompletionItem(
	ctx context.Context,
	item *lsproto.CompletionItem,
	data *lsproto.CompletionItemData,
) (*lsproto.CompletionItem, error)

func (*LanguageService) UseCaseSensitiveFileNames

func (l *LanguageService) UseCaseSensitiveFileNames() bool

func (*LanguageService) UserPreferences

func (l *LanguageService) UserPreferences() *lsutil.UserPreferences

type LocationAndSymbol

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

type ModuleReference

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

ModuleReference represents a reference to a module, either via import, <reference>, or implicit reference

type ModuleReferenceKind

type ModuleReferenceKind int32
const (
	ModuleReferenceKindImport ModuleReferenceKind = iota
	ModuleReferenceKindReference
	ModuleReferenceKindImplicit
)

type PossibleTypeArgumentInfo

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

type Project

type Project interface {
	Id() tspath.Path
	GetProgram() *compiler.Program
	HasFile(fileName string) bool
}

type ReferenceEntry

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

type SortText

type SortText string
const (
	SortTextLocalDeclarationPriority         SortText = "10"
	SortTextLocationPriority                 SortText = "11"
	SortTextOptionalMember                   SortText = "12"
	SortTextMemberDeclaredBySpreadAssignment SortText = "13"
	SortTextSuggestedClassMembers            SortText = "14"
	SortTextGlobalsOrKeywords                SortText = "15"
	SortTextAutoImportSuggestions            SortText = "16"
	SortTextClassMemberSnippets              SortText = "17"
	SortTextJavascriptIdentifiers            SortText = "18"
)

func DeprecateSortText

func DeprecateSortText(original SortText) SortText

type SymbolAndEntries

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

func NewSymbolAndEntries

func NewSymbolAndEntries(kind DefinitionKind, node *ast.Node, symbol *ast.Symbol, references []*ReferenceEntry) *SymbolAndEntries

type SymbolAndEntriesData

type SymbolAndEntriesData struct {
	OriginalNode      *ast.Node
	SymbolsAndEntries []*SymbolAndEntries
	Position          int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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