document

package
v0.0.0-...-8f660a8 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NodesToContent

func NodesToContent(doc Document, nodes []*sitter.Node) string

Returns the source content for the (assumed neighboring) nodes. If slice is nil or empty, return the entire document.

func ReadDocument

func ReadDocument(u uri.URI) (contents []byte, err error)

Read the document from the given URI and return its contents. This default implementation of a ReadDocumentFunc only handles file: URIs and returns an error otherwise.

func ResolveURI

func ResolveURI(u uri.URI) (string, error)

ResolveURI is the default resolver function used by the manager. It only supports file: URIs.

Types

type Document

type Document interface {
	Input() []byte
	Content(n *sitter.Node) string
	ContentRange(r sitter.Range) string

	Tree() *sitter.Tree
	Functions() map[string]query.Signature
	Symbols() []query.Symbol
	Diagnostics() []protocol.Diagnostic
	Loads() []LoadStatement
	URI() uri.URI

	Copy() Document

	Close()
}

func NewDocument

func NewDocument(u uri.URI, input []byte, tree *sitter.Tree) Document

type DocumentMap

type DocumentMap map[uri.URI]Document

type LoadStatement

type LoadStatement struct {
	File        string
	Symbols     []LoadSymbol
	Range       protocol.Range
	Diagnostics []protocol.Diagnostic
	// contains filtered or unexported fields
}

type LoadSymbol

type LoadSymbol struct {
	Alias, Name string
	Range       protocol.Range
}

type Manager

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

Manager provides simplified file read/write operations for the LSP server.

func NewDocumentManager

func NewDocumentManager(opts ...ManagerOpt) *Manager

func (*Manager) Initialize

func (m *Manager) Initialize(params *protocol.InitializeParams)

func (*Manager) Keys

func (m *Manager) Keys() []uri.URI

func (*Manager) Read

func (m *Manager) Read(ctx context.Context, u uri.URI) (doc Document, err error)

Read returns the contents of the file for the given URI.

If no file exists at the path or the URI is of an invalid type, an error is returned.

func (*Manager) Remove

func (m *Manager) Remove(u uri.URI)

func (*Manager) Resolve

func (m *Manager) Resolve(u uri.URI) (uri.URI, error)

Resolve the given URI to a file:// URI, or return error if the URI can't be resolved to a file.

func (*Manager) Write

func (m *Manager) Write(ctx context.Context, u uri.URI, input []byte) (diags []protocol.Diagnostic, err error)

Write creates or replaces the contents of the file for the given URI.

type ManagerOpt

type ManagerOpt func(manager *Manager)

func WithNewDocumentFunc

func WithNewDocumentFunc(newDocFunc NewDocumentFunc) ManagerOpt

func WithReadDocumentFunc

func WithReadDocumentFunc(readDocFunc ReadDocumentFunc) ManagerOpt

func WithResolveURIFunc

func WithResolveURIFunc(fn ResolveURIFunc) ManagerOpt

type NewDocumentFunc

type NewDocumentFunc func(u uri.URI, input []byte, tree *sitter.Tree) Document

type ReadDocumentFunc

type ReadDocumentFunc func(uri.URI) ([]byte, error)

type ResolveURIFunc

type ResolveURIFunc func(uri.URI) (string, error)

Jump to

Keyboard shortcuts

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