-
Notifications
You must be signed in to change notification settings - Fork 0
Plugins
The plugins are what allows for the real-time fetching of search results and Snippet code from the online repository. This page does not only explain the existing plugin but also the general idea behind them.
Plugins are used to create a bridge between the application in which the developer programs in (IDE) and the online snippet repository. At the current moment support only exists for VSCode in one programming language which was chosen to be Python3. The code for this plugin can be found on this Git. Anyone is free to use the API in order to create support for other IDEs and it is also possible to contribute to the existing plugin in order, for example, adding support for more programming languages.
The idea for a plugin is simple. Read the typing of the developer and use this to query the repository. The results are then displayed in the autocomplete list. When the developer finds a suitable Snippet the code is incorporated into the workspace. Currently, this is achieved by creating a dependency file and adding the Snippet code to it. The dependency file is then imported like any other library at the top of the file.
For now, a single plugin exists that enables support for VSCode and Python3. This was motivated by the fact that VSCode not only is one of the most used IDEs but because it also supports cross-platforming. The reason for choosing Python3 is also partially motivated by the same principle. As of 2019 Python was the second most used programming language in the world. The code for the plugin is documented with comments which explain the functioning. These comments can be found in the following files. In this project the plugin functionally is split into five parts:
extension
This file acts as the main file connecting all the other files. Its functionality is enabled by pressing Ctrl+Shift+P and searching for Enable Snippets
. After that, the onDidChangeTextDocument
functionality will fire each time a user presses a key. The getQuery
function will parse out what the developer is trying to search for from the current line. When the query is parsed the search
function will query the online repository for potential Snippets. Using the AutoComplete import, Snippet information will be added to the built-in autocomplete menu found in VSCode.
AutoComplete
This file enables easily adding of Snippets to the native autocomplete functionality found in VSCode. The add
function adds a snippet to the menu and the emptyList
function empties the autocomplete list of Snippets added by the plugin.
AutoCompleteItem
An instance of this class is used to represent a single item in the autocomplete list. It is used to create the functionality which adds the Snippet code to the project. The code found in the create
function is the code that will execute when a user has chosen a snippet. Currently, it will result in the Snippet code being added to an external dependency file along with an import line that will be added to the top of the current document.
DependencyHandler
This file contains functionality that enables adding of Snippet code to the current workspace. It will take a piece of code and its programming language. If the Snippet code is not already added, it will add it to the dependency file. It also contains functionality for adding specifically Python3 code due to the fact that each language will have slightly different ways of importing external code.
If you are interested in contributing please visit this page.
SnippetDepot • Contributor Guide • Our community • Offical Website • Contact
Project Management
Contributing
Documentation