# Semantic
`deft/stdext/semantic` (`sm`) is the symbol-index cache: it extracts
symbols with the native `editor/semantic` token-accurate extractor and
persists/reads them through the metadata DB. It backs the editor
save hook, the symbols panel, and cross-file symbol lookup (including
the help app's contextual tab).
import "deft/stdext/semantic" as sm
## API
| Def | Signature | Description |
|---|---|---|
| `semantic-index-file!` | `{| filepath lines |}` | Extract from `lines` and persist; returns `%{ file mtime indexed-at symbols }` |
| `semantic-get-symbols` | `{| filepath |}` | Cached symbol vector, or nil |
| `semantic-fresh?` | `{| filepath |}` | True when the cache mtime is at least as new as the file |
| `semantic-indexed-at` | `{| filepath |}` | Indexed-at timestamp (ms), or 0 |
| `semantic-find-symbol` | `{| filepath name |}` | Exact-name lookup within one file |
| `semantic-find-symbol-anywhere` | `{| name |}` | Exact-name lookup across all indexed files |
| `semantic-norm-path` | `{| p |}` | Normalize to an absolute path (`""` for nil/empty) |
Importing the module opens `.deft/meta.db` as a side effect and registers
a shutdown hook to close it. If SQLite is unavailable, every function
degrades safely while `semantic-index-file!` still returns the extracted
symbols.
## Example
[sm/semantic-index-file! $filepath $buffer~lines] if [sm/semantic-fresh? $filepath] { set sym [sm/semantic-find-symbol $filepath $name] } set def [sm/semantic-find-symbol-anywhere "html-escape"]
Writes use `BEGIN IMMEDIATE … COMMIT` around delete+insert so the
editor's debounced indexing and the symbols panel refreshing at the same
time cannot duplicate rows. Freshness is mtime-based.
## See Also
- Meta — storage, tables, query helpers
- Symbols app help — the panel built on this index
- Editor app help — debounced indexing integration