Add paste as default settings and enable js/ts paste with imports by default (#233031)

Fixes #184871
For #30066

Adds new settings that let you configure the default way to paste/drop.

Also enables js/ts paste with imports by default for 5.7+. However will not apply by default. Instead it will be shown as an option after pasting. You can then use the `editor.pasteAs.preferences` setting to make it apply automatically or use the `javascript.updateImportsOnPaste.enabled` settings to disable the feature entirely
This commit is contained in:
Matt Bierner
2024-11-04 16:30:09 -08:00
committed by GitHub
parent 49907c09c4
commit 54d81cd618
11 changed files with 277 additions and 96 deletions

View File

@@ -38,7 +38,7 @@ class CopyMetadata {
}
}
const settingId = 'experimental.updateImportsOnPaste';
const enabledSettingId = 'updateImportsOnPaste.enabled';
class DocumentPasteProvider implements vscode.DocumentPasteEditProvider {
@@ -127,6 +127,8 @@ class DocumentPasteProvider implements vscode.DocumentPasteEditProvider {
}
const edit = new vscode.DocumentPasteEdit('', vscode.l10n.t("Paste with imports"), DocumentPasteProvider.kind);
edit.yieldTo = [vscode.DocumentDropOrPasteEditKind.Empty.append('text', 'plain')];
const additionalEdit = new vscode.WorkspaceEdit();
for (const edit of response.body.edits) {
additionalEdit.set(this._client.toResource(edit.fileName), edit.textChanges.map(typeConverters.TextEdit.fromCodeEdit));
@@ -146,7 +148,7 @@ class DocumentPasteProvider implements vscode.DocumentPasteEditProvider {
private isEnabled(document: vscode.TextDocument) {
const config = vscode.workspace.getConfiguration(this._modeId, document.uri);
return config.get(settingId, false);
return config.get(enabledSettingId, false);
}
}
@@ -154,7 +156,7 @@ export function register(selector: DocumentSelector, language: LanguageDescripti
return conditionalRegistration([
requireSomeCapability(client, ClientCapability.Semantic),
requireMinVersion(client, API.v570),
requireGlobalConfiguration(language.id, settingId),
requireGlobalConfiguration(language.id, enabledSettingId),
], () => {
return vscode.languages.registerDocumentPasteEditProvider(selector.semantic, new DocumentPasteProvider(language.id, client), {
providedPasteEditKinds: [DocumentPasteProvider.kind],