analysis

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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 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 Fix

type Fix struct {
	Title string   `json:"title"`
	Edit  TextEdit `json:"edit"`
}

Fix is one way to correct a diagnostic, by an edit of its file

type Fixes

type Fixes struct {
	Fixes []Fix `json:"fixes"`
}

Fixes are the edits that would correct a diagnostic, offered as quick fixes

type FoldingRange

type FoldingRange struct {
	StartLine int `json:"startLine"`
	EndLine   int `json:"endLine"`
}

FoldingRange is a span of lines an editor can fold; the line that closes it stays visible

type Highlight

type Highlight struct {
	Range Range `json:"range"`
	Kind  int   `json:"kind"`
}

Highlight marks a place in a file that names the same thing as the cursor

type Hover

type Hover struct {
	Contents string `json:"contents"`
	Range    Range  `json:"range"`
}

Hover is the text shown for the name under the cursor, in Markdown

type Location

type Location struct {
	Path  string `json:"path"`
	Range Range  `json:"range"`
}

Location is a range in a file of the workspace

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

type Position struct {
	Line      int `json:"line"`
	Character int `json:"character"`
}

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 Range

type Range struct {
	Start Position `json:"start"`
	End   Position `json:"end"`
}

Range is the text between two positions; End is just past it

type Related struct {
	Location Location `json:"location"`
	Message  string   `json:"message"`
}

Related is a place that explains a diagnostic, such as where a bracket opens

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 TextEdit

type TextEdit struct {
	Range   Range  `json:"range"`
	NewText string `json:"newText"`
}

TextEdit replaces a range of a file

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 NewWorkspace

func NewWorkspace(fsys fs.FS) *Workspace

NewWorkspace reads files from fsys

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

func (w *Workspace) Definition(file string, pos Position) (Location, bool)

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

func (w *Workspace) Highlights(file string, pos Position) []Highlight

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) Hover

func (w *Workspace) Hover(file string, pos Position) (Hover, bool)

Hover describes the name at pos in path

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

func (w *Workspace) PrepareRename(file string, pos Position) (Range, string, error)

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

func (w *Workspace) References(file string, pos Position, includeDecl bool) []Location

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

func (w *Workspace) Runnable(file string) (Runnable, bool)

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

func (w *Workspace) SignatureHelp(file string, pos Position, text string) (SignatureHelp, bool)

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

func (w *Workspace) Symbols(file string) []Symbol

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.

Jump to

Keyboard shortcuts

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