Class: Snippets
core/Snippets.Snippets
Handles all cursorless snippets, including core, third-party and user-defined. Merges these collections and allows looking up snippets by name.
Constructors
constructor
• new Snippets(graph
)
Parameters
Name | Type |
---|---|
graph | Graph |
Defined in
core/Snippets.ts:53
Properties
coreSnippets
• Private
coreSnippets: SnippetMap
Defined in
core/Snippets.ts:25
directoryErrorMessage
• Private
directoryErrorMessage: undefined
| null
| DirectoryErrorMessage
= null
If the user has misconfigured their snippet dir, then we keep track of it so that we can show them the error message if we can't find a snippet later, and so that we don't show them the same error message every time we try to poll the directory.
Defined in
core/Snippets.ts:50
maxSnippetMtimeMs
• Private
maxSnippetMtimeMs: number
= -1
The maximum modification time of any snippet in user snippets dir.
This variable will be set to -1 if no user snippets have yet been read or if the user snippets path has changed.
This variable will be set to 0 if the user has no snippets dir configured and we've already set userSnippets to {}.
Defined in
core/Snippets.ts:42
mergedSnippets
• Private
mergedSnippets: SnippetMap
Defined in
core/Snippets.ts:29
thirdPartySnippets
• Private
thirdPartySnippets: Record
<string
, SnippetMap
> = {}
Defined in
core/Snippets.ts:26
userSnippets
• Private
userSnippets: SnippetMap
Defined in
core/Snippets.ts:27
userSnippetsDir
• Private
Optional
userSnippetsDir: string
Defined in
core/Snippets.ts:31
Methods
getSnippetStrict
▸ getSnippetStrict(snippetName
): Snippet
Looks in merged collection of snippets for a snippet with key
snippetName
. Throws an exception if the snippet of the given name could
not be found
Parameters
Name | Type | Description |
---|---|---|
snippetName | string | The name of the snippet to look up |
Returns
The named snippet
Defined in
core/Snippets.ts:247
init
▸ init(): Promise
<void
>
Returns
Promise
<void
>
Defined in
core/Snippets.ts:79
mergeSnippets
▸ Private
mergeSnippets(): void
Merge core, third-party, and user snippets, with precedence user > third party > core.
Returns
void
Defined in
core/Snippets.ts:209
registerThirdPartySnippets
▸ registerThirdPartySnippets(extensionId
, snippets
): void
Allows extensions to register third-party snippets. Calling this function twice with the same extensionId will replace the older snippets.
Note that third-party snippets take precedence over core snippets, but user snippets take precedence over both.
Parameters
Name | Type | Description |
---|---|---|
extensionId | string | The id of the extension registering the snippets. |
snippets | SnippetMap | The snippets to be registered. |
Returns
void
Defined in
core/Snippets.ts:200
updateUserSnippets
▸ updateUserSnippets(): Promise
<void
>
Returns
Promise
<void
>
Defined in
core/Snippets.ts:116
updateUserSnippetsPath
▸ Private
updateUserSnippetsPath(): boolean
Updates the userSnippetsDir field if it has change, returning a boolean indicating whether there was an update. If there was an update, resets the maxSnippetMtime to -1 to ensure snippet update.
Returns
boolean
Boolean indicating whether path has changed
Defined in
core/Snippets.ts:99