Creates an instance of SnippetsProvider with the given snippet service and language configuration.
The SnippetService instance for managing snippets.
An array of language configurations for handling snippets.
The MIME types supported for drag operations in the snippets provider. This is used when snippets are dragged from the provider.
The MIME types supported for drop operations in the snippets provider. This is used when other items are dropped onto the provider.
A function that can be set externally to handle UI updates or events.
Readonly
onEvent that is fired when the tree data changes.
This event is used to trigger an update of the tree view in VSCode when the data changes, such as after adding, removing, or updating a snippet.
Adds a new snippet to the snippet service, optionally associating it with a parent and providing metadata such as a description and language extension.
This method first determines the file extension from the snippet name and attempts to match it with a language configuration. If a matching language is found, it updates the language extension and removes the file extension from the snippet name. The snippet is then added to the snippet service with a unique ID, and the state is synchronized.
The name of the snippet, which may include a file extension.
The content of the snippet.
The ID of the parent snippet or folder.
Optional
description: stringAn optional description for the snippet.
Optional
languageExt: stringAn optional language extension to associate with the snippet.
Optional
gistId: stringAn optional Gist ID for the snippet, if it was shared through GitHub Gist.
Adds a new folder for snippets to the snippet service, associating it with a parent and optionally providing an icon.
This method generates a new unique ID for the folder, then adds the folder to the snippet service with the given name, parent ID, and optional icon. The state is then synchronized to reflect the new folder.
The name of the folder to be added.
The ID of the parent snippet or folder to which this new folder will belong.
Optional
icon: stringAn optional icon to associate with the folder, which can be displayed in the UI.
The unique ID assigned to the newly created folder.
Edits an existing snippet by updating its information in the snippet service and synchronizing the state.
This method updates the snippet with the provided data and ensures that the state is refreshed.
The snippet to be updated.
Edits an existing snippet folder by updating its information in the snippet service and synchronizing the state.
This method updates the snippet folder with the provided data and ensures that the state is refreshed.
The snippet folder to be updated.
Exports the snippets to a specified destination path.
This method exports all snippets, starting from the root parent, to a given destination path.
After exporting, it calls the sync()
method to ensure the snippets' state is updated.
The path where the snippets should be exported.
Fixes corrupted and duplicate snippets within the system.
This method performs the following operations:
An array containing two numbers: the count of fixed duplicate snippets and the count of corrupted snippets.
Returns the children of the given snippet, or the root-level snippets if no element is provided.
This method is used by the TreeDataProvider to load the children of a snippet when expanding a node in the VSCode Tree view. If no snippet is provided, the root-level snippets will be returned.
Optional
element: SnippetThe snippet whose children should be loaded. If not provided, the root snippets will be returned.
A promise that resolves to an array of Snippet objects, representing the children of the provided snippet or the root snippets.
Returns the vscode.TreeItem representation of the given snippet.
This method is used by the TreeDataProvider to convert a snippet into a tree item that can be displayed in the VSCode Tree view.
The snippet that should be converted into a tree item.
The vscode.TreeItem representation of the snippet.
Optional
handleHandles the drag event and sets the necessary MIME type data on the dataTransfer object.
A promise that resolves when the drag operation is complete, or void if no additional action is needed.
Optional
handleHandles the drop event for the snippets provider, managing how snippets are moved within the tree structure.
This method is invoked when a user drops a snippet onto another snippet or folder. It validates the drop action, handles moving snippets, and ensures that folder hierarchy constraints are respected.
The target snippet or folder where the snippet is being dropped. If undefined, the root of the tree is considered.
The vscode.DataTransfer object containing the dragged data (snippets).
A vscode.CancellationToken to cancel the operation if needed.
A promise that resolves when the drop operation is completed or void if no action is taken.
Imports snippets from a specified source path.
This method imports snippets from a given destination path and returns whether the import was successful.
It checks if the root element has children after the import, returning true if there are children.
After importing, it calls the sync()
method to update the snippets' state.
The path from which to import snippets.
A boolean indicating whether the import was successful (i.e., if the root element has children after import).
Moves a snippet down in the list of snippets by adjusting its position and synchronizing the state.
This method changes the position of the snippet by one step downwards and ensures that the state is updated.
The snippet to be moved down.
Moves a snippet up in the list of snippets by adjusting its position and synchronizing the state.
This method changes the position of the snippet by one step upwards and ensures that the state is updated.
The snippet to be moved up.
Refreshes the tree data by calling the refresh method of the snippet service and firing the change event.
This method updates the tree view to reflect any changes that may have occurred in the snippet data. It is typically called when data in the snippet service is updated or refreshed.
Sorts the snippets in a specific folder or category and synchronizes the state.
This method organizes the snippets in a desired order within their category and ensures the state is refreshed.
The folder or category containing the snippets to be sorted.
Saves the current state of snippets and then refreshes the tree data.
This method first persists the current snippets state by saving it through the snippet service,
then it refreshes the tree view by calling the refresh
method. If a callback function is provided,
it is executed after the sync operation.
Provides snippets for the editor and manages drag-and-drop functionality. Implements vscode.TreeDataProvider and vscode.TreeDragAndDropController for snippet data and interaction.