cache

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2020 License: Apache-2.0, BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package cache is the component of the PromQL language server that is responsible for the caching the content and parse results of documents opened in the language client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompiledQuery

type CompiledQuery struct {
	Pos     token.Pos
	Ast     promql.Node
	Err     promql.ParseErrors
	Content string
	Record  string
}

CompiledQuery stores the results of compiling one query.

type DocumentCache

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

DocumentCache caches the documents and compile Results associated with one server-client connection or one REST API instance.

Before a cache instance can be used, Init must be called.

func (*DocumentCache) AddDocument

func (c *DocumentCache) AddDocument(serverLifetime context.Context, doc *protocol.TextDocumentItem) (*DocumentHandle, error)

AddDocument adds a document to the cache.

This triggers async parsing of the document.

func (*DocumentCache) Find added in v0.4.3

func (c *DocumentCache) Find(where *protocol.TextDocumentPositionParams) (there *Location, err error)

Find returns all the information about a given position the cache can provide.

It blocks until the document is fully parsed.

func (*DocumentCache) GetDocument

func (c *DocumentCache) GetDocument(uri protocol.DocumentURI) (*DocumentHandle, error)

GetDocument retrieve a document from the cache.

func (*DocumentCache) Init

func (c *DocumentCache) Init()

Init initializes a Document cache.

func (*DocumentCache) RemoveDocument

func (c *DocumentCache) RemoveDocument(uri protocol.DocumentURI) error

RemoveDocument removes a document from the cache.

type DocumentHandle

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

DocumentHandle bundles a Document together with a context.Context that expires when the document changes.

All exported document access methods must be threadsafe and fail if the associated context has expired, unless otherwise documented.

func (*DocumentHandle) ApplyIncrementalChanges

func (d *DocumentHandle) ApplyIncrementalChanges(changes []protocol.TextDocumentContentChangeEvent, version float64) (string, error)

ApplyIncrementalChanges applies given changes to a given document content. The context in the DocumentHandle is ignored.

func (*DocumentHandle) GetContent

func (d *DocumentHandle) GetContent() (string, error)

GetContent returns the content of a document.

func (*DocumentHandle) GetDiagnostics

func (d *DocumentHandle) GetDiagnostics() ([]protocol.Diagnostic, error)

GetDiagnostics returns the diagnostics created during the compilation of a document.

It blocks until all compile tasks are finished.

func (*DocumentHandle) GetLanguageID

func (d *DocumentHandle) GetLanguageID() string

GetLanguageID returns the language ID of a document.

Since the languageID never changes, it does not block or return errors.

func (*DocumentHandle) GetQueries

func (d *DocumentHandle) GetQueries() ([]*CompiledQuery, error)

GetQueries returns the compiled queries of a document.

It blocks until all compile tasks are finished.

func (*DocumentHandle) GetSubstring

func (d *DocumentHandle) GetSubstring(pos token.Pos, endPos token.Pos) (string, error)

GetSubstring returns a substring of the content of a document.

The parameters are the start and end of the substring, encoded as token.Pos.

func (*DocumentHandle) GetVersion

func (d *DocumentHandle) GetVersion() (float64, error)

GetVersion returns the version of a document.

func (*DocumentHandle) PosToProtocolPosition

func (d *DocumentHandle) PosToProtocolPosition(pos token.Pos) (protocol.Position, error)

PosToProtocolPosition converts a token.Pos to a protocol.Position.

func (*DocumentHandle) SetContent

func (d *DocumentHandle) SetContent(serverLifetime context.Context, content string, version float64, new bool) error

SetContent sets the content of a document.

This triggers async parsing of the document.

type Location added in v0.4.3

type Location struct {
	Doc   *DocumentHandle
	Pos   token.Pos
	Query *CompiledQuery
	Node  promql.Node
}

Location bundles all the context that the cache can provide for a given protocol.Location.

Jump to

Keyboard shortcuts

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