Implementing a VS Code feature: Research & Planning [1/2]
This is the first article in a series where we’ll implement “Copy with Imports” in VS Code’s TypeScript extension.
Previous article: Introduction
Next article: registerDocumentPasteEditProvider
To start with, some basic research:
- The issue we’re looking to fix is TypeScript#50187. This was originally filed as vscode#66236.
- The VS Code API we’ll need to hook into is
registerDocumentPasteEditProvider. - The API is still unstable/proposed, so we can’t publish an extension that uses these APIs, but we can test these changes locally.
The registerDocumentPasteEditProvider API takes three parameters:
- a
DocumentSelectorto specify which documents this provider should be used for - a
DocumentPasteEditProviderwhich is an interface containing two functions:prepareDocumentPaste, which is invoked after the user copies text in a file.provideDocumentPasteEdits, which is invoked when the user pastes text in a file.
metadatawhich is an object that specifies whether the provider should be used for copy or paste
Here’s how I plan to break this down:
- Call
registerDocumentPasteEditProvider, but use a dummy implementation that justconsole.logs the arguments. - Implement the
prepareDocumentPastefunction to copy the imports along with the copied text. - Implement the
provideDocumentPasteEditsfunction to insert the copied imports.