Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Include and library resolution

How spice-lsp resolves .model, .subckt, and related symbols across .include / .inc and HSPICE .lib files.

Goals

CapabilityBehavior
Follow .include / .incLoad the target file and merge its model/subcircuit definitions into resolution
Follow .lib 'file' entryLoad only the named .LIB entry.ENDL section from the library file
Unknown model/subcktspice/unknown-model is suppressed when the name is defined in a reachable include or lib section
Go to definition (symbol)Jumps to the defining .model / .subckt in the included or library file
Go to definition (path / entry)Cursor on an include/lib path opens that file; cursor on a .lib entry name jumps to the .lib entry section header
Missing pathspice/include-not-found (or spice/lib-section-not-found) on the include/lib directive

Outline (documentSymbol) stays file-local. Find references stays in the open buffer today (cross-file references may expand later).

Directive shapes

FormMeaning
.include path / .inc pathInsert the whole file
.lib 'path' entryCall the named section in a library file (HSPICE-style)
.lib entry.endlSection delimiters inside a library file (not a file call)

Paths may be single-quoted, double-quoted, or bare. Relative paths resolve against the including file’s directory, then against spiceLsp.libraryPaths.

Resolution algorithm

analyze(root)
  → parse + local Index + IncludeRef list
  → for each IncludeRef (depth-limited, cycle-safe):
        resolve path (relative → libraryPaths → fail)
        load text (open buffer if present, else disk)
        if LibCall: keep only lines inside matching .LIB entry … .ENDL
        else: use full file
        build Index for that slice
        recurse into nested includes
  → merge external definitions
  → drop spice/unknown-model when name exists in merge
  → emit spice/include-not-found / spice/lib-section-not-found

Default max nesting depth is 16 (aligned with common HSPICE nested-.LIB limits).

Search path

  1. Absolute path as written
  2. Relative to the directory of the file that contains the .include / .lib call
  3. Each entry in spiceLsp.libraryPaths (workspace or absolute folders)

LSP integration

RequestCross-file behavior
publishDiagnosticsUses include graph when publishing for an open document
textDocument/definitionMay return a Location in another file URI (model/subckt, include/lib path, or .lib entry section)
textDocument/referencesSame-buffer only
textDocument/documentSymbolSame-buffer only
textDocument/hoverFile-local symbols still prefer the open buffer; dialect corpus unchanged

Open buffers win over disk content when the resolved path matches an open document (so edits to an included file are visible before save).

Configuration

SettingTypeDefaultPurpose
spiceLsp.libraryPathsstring[][]Extra directories for resolving include/lib paths
spiceLsp.include.maxDepthnumber16Cap on nested include/lib depth

Diagnostics

CodeWhen
spice/include-not-foundPath does not resolve under search rules
spice/lib-section-not-foundFile loads but the requested .LIB entry is missing
spice/include-cycleInclude/lib graph would revisit a file already on the stack
spice/unknown-modelModel/subckt still missing after the include closure is merged

Limits

  • No workspace-wide workspace/symbol yet
  • No automatic PDK discovery beyond libraryPaths
  • LTspice / Ngspice .lib quirks beyond the HSPICE call/section pattern are best-effort
  • Nested .lib section selection inside an already-filtered section follows nested includes normally