Skip to content

Workspace Indexing

slang-server's indexing system provides fast symbol lookup and navigation across large SystemVerilog codebases by building and maintaining an index of top level symbols.

The indexer uses multithreading to rapidly index your repo. Crawling a file system actually often takes longer than parsing in large unconfigured repos, so make sure your indexing config is as specific as possible.

Configured external roots supplement the default workspace scan. An explicit workspace directory, an ancestor covering the workspace, or an empty dirs entry suppresses the default. Each entry's exclusions apply to its own roots. Auto-configure uses the same rule to add a separate workspace entry alongside external-only roots, including external roots inherited from user or local configuration.

In each syntax tree parsed, it indexes the top level symbols like moduldes, packages, etc, as well as references to other top level symbols. If no top level symbols were found, it'll instead index the macros defined in that file.

The index also tracks filenames, including headers that contain fragments of a class or package. Auto-configure derives candidate include directories from existing quoted include spellings with a unique matching file. Includes resolved relative to their own file do not suggest search directories for other files. Matching uses the entire relative include path: detail/types.svh matches a file ending in detail/types.svh.

Available include filenames are a snapshot of the last full indexing pass. A separate index maps the filenames in gathered include strings to their containing files, without resolving those strings or checking their targets on disk. Gathered references, symbols, macros, and header declarations track file changes. Saving an includer indexes declarations originating in that file, including declarations generated by macros invoked there; declarations from its headers retain their own file identity.

When a header needs a compilation context, only references with its filename are resolved, using local paths before the nearest indexed matches. Results are cached until index or parsed-buffer updates. Actual parsed relationships override gathered references, including when parsing confirms that a source has no active includes. Macro-only headers skip this resolution. Workspace include-directory suggestions are computed and logged only by auto-configure.

The logs report parsing and metadata indexing and the overall workspace-indexing time, which includes the filename index. Directory discovery and explicit include-directory inference have their own timings.

Auto-configure checks the filename snapshot, crawled directories, and existing exact exclusions against Git ignore rules. It reads Git's tracked paths and submodule entries, then sends workspace paths to git check-ignore --no-index in a null-delimited batch, without another filesystem crawl. Ignored folders without tracked files or re-included indexed sources become plain directory-name exclusions on each applicable workspace index entry. Repeated names are deduplicated. Names that would hide protected directories retain specific path exclusions instead. Existing exact exclusions covered by a name are removed, and obsolete wildcard exclusions are replaced. Normal indexing uses linear lookup for short exclusion lists and hashing for larger lists. Specific paths are matched at directory boundaries, including ancestors of explicitly indexed roots. Git wildcard matching runs only during discovery. The index drops excluded cached symbols and filenames before choosing directory suggestions, then adds inferred exclusions only to entries whose final roots overlap those folders. Ignored siblings outside narrowed roots are omitted. Existing configured exclusions are preserved. File-only matches and folders covered by inherited or legacy settings remain available for manual review, with matching rules logged. Submodules and external index roots are outside the query. Git handles nested ignore files and negations. This runs only for the explicit command and is skipped if Git is unavailable.

The Auto-configure command refreshes the index and appends nonconflicting directory suggestions to incdirs in .slang/server.json. If indexing uses the default workspace scan or a workspace index directory is ., it also chooses nonoverlapping directories covering every indexed .sv, .svh, .v, and .vh file within the workspace. Its existing directory crawl records entry counts only for this explicit command. For each source-containing branch, it compares selecting the parent against the selected child directories, minimizing visited entries plus a penalty per configured root of 5% of the workspace crawl (at least 32 entries). Scaling the penalty keeps large workspaces from producing long lists for small marginal savings. Dense trees stay together, and sparse trees can split at different depths. Separate top-level source branches are selected independently; source files directly in the workspace root prevent narrowing. External index roots do not constrain workspace suggestions or contribute to the penalty. Replacing . preserves its entry's exclusions and other directories; inherited and legacy indexing settings are preserved. Opening, editing, and reindexing do not change the configuration.

For shallow editor analysis, the server derives additional include directories from the nearest indexed matches for unresolved quoted includes. These paths belong only to that syntax tree's options; the shared source manager and configuration are unchanged. Distance is measured from the file containing each include, and nested headers can contribute additional paths. Equally close matches are resolved in canonical path order; filesystem aliases of the same file count as one match. Existing configured and file-local resolutions take precedence. Because a syntax tree has one search order, inferred paths are skipped if they would select conflicting headers within that tree. Files supplied through build files and system includes (<...>) keep normal include lookup.

For duplicate module, interface, or package names, hover and go-to-definition show the nearest declarations by directory distance, including every tie at the minimum distance. References and rename follow those bindings; a tied reference connects its candidate declarations into one reference group. Package-member references are checked against their resolved declarations as well. Shallow compilation and completion keep a deterministic canonical-path choice when they need a single definition.

The Add include quick fix inserts an include for an unresolved macro or a declaration found in a header. Each matching header is offered separately, preferring a spelling that resolves through configured search paths or the current file's directory, then trying an explicit relative path. A unique filename alone does not justify shortening the include path. Macro includes follow the last include before the usage, preserving existing include order and leading file comments. Declaration includes precede the enclosing member in its package or module scope, keeping earlier imports and declarations available; references in a module header are handled before the module declaration. Existing includes are not duplicated.

Files with potential includers are eligible for include-context lookup regardless of extension. Files containing only macro definitions remain standalone and do not show include-context CodeLenses. Context discovery uses the filename index and parsed reverse include relationships without scanning the workspace. An opened file shares an enclosing source file's shallow compilation. When several contexts are available, the server defaults to the first active context in canonical source-path order; an explicit selection on an include list also guides its nested headers. For a package that includes a list of class files, opening either the list or a class file uses the package's imports, macros, and declaration order. Include relationships update with parsing and saves; file indexing invalidates outdated relationships and refreshes the gathered references.

ShallowCompilation owns the syntax trees, active-design context, elaboration, and cached diagnostics. Each open file has a ShallowAnalysis with its own buffer, token and symbol indexes, and outline; published diagnostics are filtered to that file. Editing an included file invalidates the shared compilation; files without an active enclosing context retain standalone analysis.

Expand Macros expands invocations in the selected file using the definitions active at each invocation, including definitions inherited from its includer. It preserves that file's comments, whitespace, and include directives.

Included files show an Included by filename:line CodeLens at the top of the file. Clicking it opens the include directive in the immediate parent file. When multiple contexts are available, a second And N others CodeLens opens a picker showing their include sites and enclosing sources. Selecting a context switches the file's shared compilation, updates diagnostics and editor annotations, and keeps the editor in place. The choice survives document edits and configuration reloads; if it is no longer available, analysis falls back to another active context. Repeated includes within one source can be selected separately. Include relationships use canonical filesystem paths, so directory aliases do not create duplicate contexts.