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
DocumentSelector
to specify which documents this provider should be used for - a
DocumentPasteEditProvider
which 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.
metadata
which 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.log
s the arguments. - Implement the
prepareDocumentPaste
function to copy the imports along with the copied text. - Implement the
provideDocumentPasteEdits
function to insert the copied imports.