Is it possible for a snippet to insert a dynamically computed completion or snippet in Visual Studio Code?
I would like a snippet for inserting date and time strings of various formats. For example if you type date
, the current date in ISO format would automatically be expanded.
There is a facility in Sublime Text to do this in the python API via the on_query_completions
method in the EventListener
class. There the implementation would be very simple:
def on_query_completions(self, view, prefix, locations):
if prefix == 'date':
val = datetime.now().strftime('%Y-%m-%d')
return [(prefix, prefix, val)] if val else []
I have read the documentation on User Defined Snippets, but it appears that one can only insert pre-defined text with tab-stops and variables that the user fills in.
If this isn't possible with the functionality exposed by the snippet API, would I be able to implement something similar with via a lower-level plugin/extension API?
I do realize that there is an existing extension called Insert Date and Time but this works via the command pallet instead of a dynamic expansion.