Filesystem
Snippet Cache Module
In-memory cache for parsed extension snippets.
Provides lazy-loading snippet caching without file watchers. File watching belongs in the VSCode extension layer.
Classes
Snippet Parsing Module
Parsing for _snippets.json files.
Provides functions to find, parse, and read Quarto extension snippet files.
Interfaces
Variables
Functions
SnippetCache
Defined in: packages/snippets/src/filesystem/snippet-cache.ts:19
Cache for parsed extension snippets. Snippets are loaded lazily on first access.
Constructors
Constructor
TypeScript
new SnippetCache(): SnippetCache;Returns
SnippetCache
Methods
get()
TypeScript
get(extensionDir): SnippetCollection | null;Defined in: packages/snippets/src/filesystem/snippet-cache.ts:31
Get the snippets for an extension directory. Loads and caches the snippets on first access.
Parameters
| Parameter | Type | Description |
|---|---|---|
extensionDir |
string |
Path to the extension directory. |
Returns
SnippetCollection | null
Parsed snippet collection or null if no snippet file exists.
getError()
TypeScript
getError(extensionDir): string | null;Defined in: packages/snippets/src/filesystem/snippet-cache.ts:65
Get the parse error for snippets in the given directory, if any.
Parameters
| Parameter | Type | Description |
|---|---|---|
extensionDir |
string |
Path to the extension directory. |
Returns
string | null
Error message or null if no error occurred.
has()
TypeScript
has(extensionDir): boolean;Defined in: packages/snippets/src/filesystem/snippet-cache.ts:75
Check whether snippets are cached for the given directory.
Parameters
| Parameter | Type | Description |
|---|---|---|
extensionDir |
string |
Path to the extension directory. |
Returns
boolean
True if snippets are cached.
invalidate()
TypeScript
invalidate(extensionDir): void;Defined in: packages/snippets/src/filesystem/snippet-cache.ts:84
Invalidate the cached snippets for a specific extension directory.
Parameters
| Parameter | Type | Description |
|---|---|---|
extensionDir |
string |
Path to the extension directory. |
Returns
void
invalidateAll()
TypeScript
invalidateAll(): void;Defined in: packages/snippets/src/filesystem/snippet-cache.ts:93
Invalidate all cached snippets.
Returns
void
findSnippetFile
TypeScript
function findSnippetFile(directory): string | null;Defined in: packages/snippets/src/filesystem/snippets.ts:34
Find the snippet file in a directory.
Parameters
| Parameter | Type | Description |
|---|---|---|
directory |
string |
Directory to search. |
Returns
string | null
Path to the snippet file or null if not found.
parseSnippetContent
TypeScript
function parseSnippetContent(content, sourcePath?): SnippetCollection;Defined in: packages/snippets/src/filesystem/snippets.ts:78
Parse snippet content from a JSON string. Entries missing prefix or body are silently skipped.
Parameters
| Parameter | Type | Description |
|---|---|---|
content |
string |
JSON content string. |
sourcePath? |
string |
Source path for error messages (optional). |
Returns
Parsed snippet collection.
Throws
SnippetError if the JSON is invalid or the root is not an object.
parseSnippetFile
TypeScript
function parseSnippetFile(snippetPath): SnippetCollection;Defined in: packages/snippets/src/filesystem/snippets.ts:110
Parse a snippet file from a path.
Parameters
| Parameter | Type | Description |
|---|---|---|
snippetPath |
string |
Full path to the snippet file. |
Returns
Parsed snippet collection.
Throws
SnippetError if reading or parsing fails.
readSnippets
TypeScript
function readSnippets(directory): SnippetReadResult | null;Defined in: packages/snippets/src/filesystem/snippets.ts:131
Read snippets from an extension directory.
Parameters
| Parameter | Type | Description |
|---|---|---|
directory |
string |
Directory containing the snippet file. |
Returns
SnippetReadResult | null
SnippetReadResult or null if no snippet file found.
SnippetReadResult
Defined in: packages/snippets/src/filesystem/snippets.ts:21
Result of reading a snippet file.
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
snippetPath |
string |
Full path to the snippet file. | packages/snippets/src/filesystem/snippets.ts:25 |
snippets |
SnippetCollection |
Parsed snippet collection. | packages/snippets/src/filesystem/snippets.ts:23 |
SNIPPET_FILENAME
TypeScript
const SNIPPET_FILENAME: "_snippets.json" = "_snippets.json";Defined in: packages/snippets/src/filesystem/snippets.ts:16
The snippet filename convention.