Documentation
¶
Overview ¶
Package anchor resolves which line of a dependency manifest declares a given package.
This is the piece the SCA path needs and nothing else in the codebase provides. parse.ScopedPackage records the manifest a package came from but no position within it, and rangefix.Columns only refines columns on a line that is already known. Without an anchor a dependency finding has nowhere to go.
Resolution is textual rather than parser-derived on purpose:
- It works on the editor's unsaved buffer, which is the whole point in a language server. The user is typing a version number when they most want to know it is vulnerable.
- Several of the underlying parsers cannot help even in principle. BurntSushi/toml exposes no positions, so Cargo.toml would need this fallback regardless.
The expected anchors are pinned per ecosystem in the extension's fixture at test/fixtures/vulnetix-fixture-app/.vulnetix/expected.json ("anchors"), which is the acceptance spec for this package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Confidence ¶
type Confidence string
Confidence describes how the line was derived, so the editor can render an approximate anchor as approximate rather than implying a precision it does not have.
The vocabulary is deliberately the one the fixture uses. rangefix has its own three-value scale for column synthesis; Narrow maps between them so the two do not drift apart.
const ( // ConfidenceExact means the line declares this package and only this // package: a key in a JSON dependency block, a requirements.txt line, a // gem call. ConfidenceExact Confidence = "exact" // ConfidenceToken means the line was found by scanning for a token rather // than by structure, or the anchor is the enclosing block rather than the // declaration itself — a <dependency> element in a pom, a table-scoped // regex hit in a TOML file. ConfidenceToken Confidence = "token" )
type Result ¶
type Result struct {
// Line is 1-based, matching the fixture and every parser in the tree. LSP
// positions are 0-based; convert at the protocol boundary, not here.
Line int
Confidence Confidence
// Snippet is the text to hand rangefix so it can narrow the range to the
// package name rather than underlining the whole line.
Snippet string
}
Result is one resolved anchor.
func Find ¶
Find returns the line declaring name in a manifest of the given type.
manifestType uses the same keys as parse.ParseManifest, so a caller that parsed a file can pass the same string straight through. Returns false when the package cannot be located, which is not an error: a transitive package genuinely is not declared in the manifest that pulled it in, and inventing a line for it would put a red squiggle on unrelated code.