Documentation
¶
Overview ¶
Package analysis checks Evie code without running it and answers what an editor asks about it: errors, an outline, where a name is declared and used, hover text and completions. It is the core of Evie's language server.
Files are read through an fs.FS whose paths are slash-separated and relative to the workspace root, so an editor can serve its unsaved documents.
Index ¶
- Constants
- func HasErrors(diags []Diagnostic) bool
- type Completion
- type Diagnostic
- type DocumentLink
- type Fix
- type Fixes
- type FoldingRange
- type Highlight
- type Hover
- type Location
- type ParameterInformation
- type Position
- type Range
- type Related
- type Runnable
- type SignatureHelp
- type SignatureInformation
- type Symbol
- type SymbolInformation
- type TextEdit
- type Workspace
- func (w *Workspace) Complete(file string, pos Position, text string) []Completion
- func (w *Workspace) Definition(file string, pos Position) (Location, bool)
- func (w *Workspace) Folding(file string) []FoldingRange
- func (w *Workspace) Highlights(file string, pos Position) []Highlight
- func (w *Workspace) Hover(file string, pos Position) (Hover, bool)
- func (w *Workspace) Links(file string) []DocumentLink
- func (w *Workspace) PrepareRename(file string, pos Position) (Range, string, error)
- func (w *Workspace) References(file string, pos Position, includeDecl bool) []Location
- func (w *Workspace) Rename(file string, pos Position, newName string) (map[string][]TextEdit, error)
- func (w *Workspace) Runnable(file string) (Runnable, bool)
- func (w *Workspace) SignatureHelp(file string, pos Position, text string) (SignatureHelp, bool)
- func (w *Workspace) Symbols(file string) []Symbol
- func (w *Workspace) Update(path string) map[string][]Diagnostic
- func (w *Workspace) WorkspaceSymbols(query string) []SymbolInformation
Constants ¶
const ( SeverityError = 1 SeverityHint = 4 )
Diagnostic severities and tags, as the Language Server Protocol numbers them
Variables ¶
This section is empty.
Functions ¶
func HasErrors ¶
func HasErrors(diags []Diagnostic) bool
HasErrors reports whether diags hold an error, rather than only hints
Types ¶
type Completion ¶
type Completion struct {
Label string `json:"label"`
Kind int `json:"kind"`
Detail string `json:"detail,omitempty"`
Documentation string `json:"documentation,omitempty"` // Markdown
}
Completion is a word that can go where the cursor is
type Diagnostic ¶
type Diagnostic struct {
Range Range `json:"range"`
Severity int `json:"severity"`
Source string `json:"source"`
Message string `json:"message"`
Related []Related `json:"relatedInformation,omitempty"`
Tags []int `json:"tags,omitempty"`
Data *Fixes `json:"data,omitempty"`
}
Diagnostic is an error in a file, or a hint about it, the way the Language Server Protocol describes one
type DocumentLink ¶
type DocumentLink struct {
Range Range `json:"range"`
Target string `json:"target"` // a path of the workspace
Tooltip string `json:"tooltip,omitempty"`
}
DocumentLink makes a span of a file a link to another file, as an import path is to the file or folder it imports
type Fixes ¶
type Fixes struct {
Fixes []Fix `json:"fixes"`
}
Fixes are the edits that would correct a diagnostic, offered as quick fixes
type FoldingRange ¶
FoldingRange is a span of lines an editor can fold; the line that closes it stays visible
type ParameterInformation ¶
type ParameterInformation struct {
Label [2]int `json:"label"`
}
ParameterInformation is a parameter, by where its name is in the label, counted in UTF-16 code units
type Position ¶
Position is a place in a document the way editors count it: a zero-based line, and a zero-based character offset in UTF-16 code units
type Runnable ¶
type Runnable struct {
Range Range `json:"range"` // the name of fn main, or the start of a script
Target string `json:"target"` // the file, or for a project its folder
Project bool `json:"project"` // the target is a folder of main files
}
Runnable is a program a file starts: where to offer to run it, and what to give evie to run it
type SignatureHelp ¶
type SignatureHelp struct {
Signatures []SignatureInformation `json:"signatures"`
ActiveSignature int `json:"activeSignature"`
ActiveParameter int `json:"activeParameter"`
}
SignatureHelp shows the parameters of the call the cursor is in, with the one being written marked
type SignatureInformation ¶
type SignatureInformation struct {
Label string `json:"label"`
Documentation string `json:"documentation,omitempty"` // Markdown
Parameters []ParameterInformation `json:"parameters"`
}
SignatureInformation is a callable's signature
type Symbol ¶
type Symbol struct {
Name string `json:"name"`
Detail string `json:"detail,omitempty"`
Kind int `json:"kind"`
Range Range `json:"range"`
SelectionRange Range `json:"selectionRange"`
Children []Symbol `json:"children,omitempty"`
}
Symbol is an entry of a file's outline
type SymbolInformation ¶
type SymbolInformation struct {
Name string `json:"name"`
Kind int `json:"kind"`
Location Location `json:"location"`
ContainerName string `json:"containerName,omitempty"`
}
SymbolInformation is a function, class, method or binding found by a search of the whole workspace
type Workspace ¶
type Workspace struct {
// contains filtered or unexported fields
}
Workspace answers questions about the Evie files of a folder. It keeps, for every file, the latest analysis that covered it and the latest one in which it parsed, so that while code is being typed and does not parse, going to a definition or completing a name still works from the last good version.
func (*Workspace) Complete ¶
func (w *Workspace) Complete(file string, pos Position, text string) []Completion
Complete lists what can be written at pos in path, where text is the document as it is now, which may not parse: members after `pkg.` or `this.`, and otherwise keywords and the names in scope
func (*Workspace) Definition ¶
Definition is where the name at pos in path is declared
func (*Workspace) Folding ¶
func (w *Workspace) Folding(file string) []FoldingRange
Folding lists the bracketed blocks of a file that span lines: bodies, switches, and object and array literals. A file with syntax errors folds as far as it parsed.
func (*Workspace) Highlights ¶
Highlights marks every place in file that names what the name at pos names; its declaration counts as a write, its uses as reads
func (*Workspace) Links ¶
func (w *Workspace) Links(file string) []DocumentLink
Links makes the import paths of a file links to what they import: the file, or for a folder its first file. A path of the standard library or of the host is not a link.
func (*Workspace) PrepareRename ¶
PrepareRename tells whether the name at pos can be renamed, and gives its range and current text, or the reason it cannot
func (*Workspace) References ¶
References are the places in the workspace that name what the name at pos in path names, with its declaration when includeDecl is set. Every program of the workspace is searched, so the uses of a package's function are found in every program that imports it.
func (*Workspace) Rename ¶
func (w *Workspace) Rename(file string, pos Position, newName string) (map[string][]TextEdit, error)
Rename gives the edits, per file, that rename what the name at pos names to newName everywhere in the workspace. It refuses when the code that uses the name has errors, and when the renamed code would mean something else, as when the new name is taken or shadows another: the renamed code is checked before the edits are given.
func (*Workspace) Runnable ¶
Runnable tells whether file starts a program: a script, or a main file that declares fn main. A main file that is part of a project runs the project's folder, as evie does with a folder.
func (*Workspace) SignatureHelp ¶
SignatureHelp shows the parameters of the call that the cursor at pos is in, where text is the document as it is now, which may not parse
func (*Workspace) Symbols ¶
Symbols outlines a file: its functions, classes with their fields and methods, and top-level bindings. A file with syntax errors is outlined as far as it parsed.
func (*Workspace) Update ¶
func (w *Workspace) Update(path string) map[string][]Diagnostic
Update analyzes the program or package that the file at path belongs to, and returns the diagnostics of every file the analysis covered; a file without any has an empty list, so an editor can clear old ones
func (*Workspace) WorkspaceSymbols ¶
func (w *Workspace) WorkspaceSymbols(query string) []SymbolInformation
WorkspaceSymbols finds the declarations of every file of the workspace whose names hold the letters of query in order, ignoring case: the functions, classes and top-level bindings, and the fields and methods of classes. Files are only parsed, so this is quick and works on broken code.