php

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindMethodRange added in v0.0.6

func FindMethodRange(path, methodName string) (protocol.Range, bool)

func PathAt

func PathAt(content string, pos protocol.Position) (string, bool)

func Resolve

func Resolve(className string, autoloadMap config.AutoloadMap, workspaceRoot string) (string, protocol.Range, bool)

func TypeNamesAtOrBefore added in v0.0.6

func TypeNamesAtOrBefore(entries []TypeOccurrence, line int) []string

TypeNamesAtOrBefore collapses the occurrences observed up to the requested line.

func TypeNamesFromOccurrences added in v0.0.6

func TypeNamesFromOccurrences(entries []TypeOccurrence) []string

TypeNamesFromOccurrences deduplicates the types present in the provided occurrences.

func VariableNameFromNode added in v0.0.6

func VariableNameFromNode(node sitter.Node, content []byte) string

VariableNameFromNode extracts the PHP variable identifier from the provided node.

Types

type ByteRange added in v0.0.6

type ByteRange struct {
	Start uint32
	End   uint32
}

ByteRange represents a range of bytes in the source content.

type ClassInfo added in v0.0.6

type ClassInfo struct {
	Name      string
	Namespace string
	FQN       string
	Extends   []string
	StartLine int
	EndLine   int
	StartByte uint32
}

ClassInfo describes a class declaration discovered in the file.

type Document added in v0.0.6

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

Document maintains a parsed PHP syntax tree together with its static analysis index. It owns the tree-sitter parser and decides when static analysis should be re-run.

func NewDocument added in v0.0.6

func NewDocument() *Document

NewDocument constructs a Document ready to track a PHP source file.

func (*Document) Close added in v0.0.6

func (d *Document) Close()

Close releases resources owned by the document.

func (*Document) GetNodeAt added in v0.0.6

func (d *Document) GetNodeAt(pos protocol.Position) (sitter.Node, []byte, IndexedTree, bool)

GetNodeAt returns the syntax node that spans the provided LSP position together with the current file content and static analysis index. The returned content is a copy, ensuring callers cannot mutate the underlying buffer.

func (*Document) Index added in v0.0.6

func (d *Document) Index() IndexedTree

Index returns the most recently computed static analysis index.

func (*Document) Read added in v0.0.6

func (d *Document) Read(fn func(tree *sitter.Tree, content []byte, index IndexedTree))

Read executes the provided function while holding a read lock on the document. The callback must not store the tree, content, or index beyond its scope.

func (*Document) SetAutoloadMap added in v0.0.6

func (d *Document) SetAutoloadMap(autoload config.AutoloadMap)

SetAutoloadMap assigns the Composer autoload map used during static analysis.

func (*Document) SetURI added in v0.0.6

func (d *Document) SetURI(uri string)

SetURI configures the document URI for downstream analysis.

func (*Document) SetWorkspaceRoot added in v0.0.6

func (d *Document) SetWorkspaceRoot(root string)

SetWorkspaceRoot configures the workspace root used for path resolution.

func (*Document) Update added in v0.0.6

func (d *Document) Update(code []byte, change *sitter.InputEdit) error

Update notifies the document about new file contents. If change is nil, the file has been replaced entirely. Incremental edits can be provided via change.

type DocumentStore added in v0.0.6

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

DocumentStore maintains a bounded set of parsed PHP documents.

func NewDocumentStore added in v0.0.6

func NewDocumentStore(max int) *DocumentStore

NewDocumentStore constructs a store with the provided maximum size.

func (*DocumentStore) Close added in v0.0.6

func (s *DocumentStore) Close(path string)

Close marks a document as no longer open. It becomes eligible for eviction.

func (*DocumentStore) Configure added in v0.0.6

func (s *DocumentStore) Configure(autoload config.AutoloadMap, workspaceRoot string)

Configure updates the shared context injected into any stored document.

func (*DocumentStore) Get added in v0.0.6

func (s *DocumentStore) Get(path string) (*Document, error)

Retrieves or loads (and caches) a document for the given path.

func (*DocumentStore) RegisterOpen added in v0.0.6

func (s *DocumentStore) RegisterOpen(path string, doc *Document)

RegisterOpen registers a document as currently open. The document will not be evicted until Close is invoked for the same path.

type FunctionInfo added in v0.0.6

type FunctionInfo struct {
	URI        string
	Name       string
	Range      LineColumnRange
	Parameters LineColumnRange
	Body       LineColumnRange
}

FunctionInfo captures metadata about a function or method declaration.

type FunctionScope added in v0.0.6

type FunctionScope struct {
	Variables map[string][]TypeOccurrence
	StartLine int
	EndLine   int
}

FunctionScope stores all variables indexed for a single function or method.

type IndexedTree added in v0.0.6

type IndexedTree struct {
	Properties         map[string][]TypeOccurrence
	Variables          map[string]FunctionScope
	Types              map[string][]TypeReference
	Classes            map[uint32]ClassInfo
	PrivateFunctions   []FunctionInfo
	ProtectedFunctions []FunctionInfo
	PublicFunctions    []FunctionInfo
}

IndexedTree contains lightweight static analysis metadata for a PHP source file. It tracks properties, the types discovered for them, and variables scoped to functions or methods. A flattened type index is also provided for quick lookups.

type LineColumnRange added in v0.0.6

type LineColumnRange struct {
	StartLine   int
	StartColumn int
	EndLine     int
	EndColumn   int
}

LineColumnRange captures a range using 1-based lines and 0-based columns.

type StaticAnalyzer added in v0.0.6

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

StaticAnalyzer incrementally maintains an IndexedTree for a PHP source file.

func NewStaticAnalyzer added in v0.0.6

func NewStaticAnalyzer() *StaticAnalyzer

NewStaticAnalyzer constructs an analyzer with an empty index.

func (*StaticAnalyzer) Configure added in v0.0.6

func (a *StaticAnalyzer) Configure(uri string, autoload config.AutoloadMap, workspaceRoot string)

Configure sets metadata consumed by the analyzer when producing function information.

func (*StaticAnalyzer) Update added in v0.0.6

func (a *StaticAnalyzer) Update(content *[]byte, tree *sitter.Tree, dirty []ByteRange) IndexedTree

Update recomputes the index, optionally reusing previous state for dirty ranges. When dirty is nil, the index is rebuilt from scratch.

type SymbolKind added in v0.0.6

type SymbolKind string

SymbolKind indicates what kind of PHP symbol is associated with a type reference.

const (
	// SymbolKindProperty marks references that originate from class properties.
	SymbolKindProperty SymbolKind = "property"
	// SymbolKindVariable marks references that originate from function-scoped variables.
	SymbolKindVariable SymbolKind = "variable"
)

type TypeOccurrence added in v0.0.6

type TypeOccurrence struct {
	Type string
	Line int
}

TypeOccurrence captures a single type assignment together with the line where it appears.

type TypeReference added in v0.0.6

type TypeReference struct {
	Symbol string
	Kind   SymbolKind
	Line   int
}

TypeReference ties a type name to the symbol (property or variable) where it was observed.

Jump to

Keyboard shortcuts

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