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 ¶
- type CompiledQuery
- type DocumentCache
- func (c *DocumentCache) AddDocument(serverLifetime context.Context, doc *protocol.TextDocumentItem) (*DocumentHandle, error)
- func (c *DocumentCache) Find(where *protocol.TextDocumentPositionParams) (there *Location, err error)
- func (c *DocumentCache) GetDocument(uri protocol.DocumentURI) (*DocumentHandle, error)
- func (c *DocumentCache) Init()
- func (c *DocumentCache) RemoveDocument(uri protocol.DocumentURI) error
- type DocumentHandle
- func (d *DocumentHandle) ApplyIncrementalChanges(changes []protocol.TextDocumentContentChangeEvent, version float64) (string, error)
- func (d *DocumentHandle) GetContent() (string, error)
- func (d *DocumentHandle) GetDiagnostics() ([]protocol.Diagnostic, error)
- func (d *DocumentHandle) GetLanguageID() string
- func (d *DocumentHandle) GetQueries() ([]*CompiledQuery, error)
- func (d *DocumentHandle) GetSubstring(pos token.Pos, endPos token.Pos) (string, error)
- func (d *DocumentHandle) GetVersion() (float64, error)
- func (d *DocumentHandle) PosToProtocolPosition(pos token.Pos) (protocol.Position, error)
- func (d *DocumentHandle) SetContent(serverLifetime context.Context, content string, version float64, new bool) error
- type Location
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) 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 ¶
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 ¶
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.