From 2f11640e1437d058834fe529a06aad3a923b1490 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 11 May 2023 13:02:35 -0700 Subject: [PATCH] Update for latest copy paste api Also removes use of `text` instead of `text/plain` --- document-paste/.gitignore | 1 + document-paste/package-lock.json | 109 ++++++++++++++++-- document-paste/package.json | 12 +- document-paste/src/extension.ts | 4 +- .../src/vscode.proposed.documentPaste.d.ts | 70 ----------- drop-on-document/src/extension.ts | 2 +- 6 files changed, 113 insertions(+), 85 deletions(-) delete mode 100644 document-paste/src/vscode.proposed.documentPaste.d.ts diff --git a/document-paste/.gitignore b/document-paste/.gitignore index 5fe00fea..9e69089a 100644 --- a/document-paste/.gitignore +++ b/document-paste/.gitignore @@ -2,3 +2,4 @@ out node_modules .vscode-test/ *.vsix +vscode.*d.ts \ No newline at end of file diff --git a/document-paste/package-lock.json b/document-paste/package-lock.json index 7bb92a7e..3a68950e 100644 --- a/document-paste/package-lock.json +++ b/document-paste/package-lock.json @@ -7,17 +7,19 @@ "": { "name": "document-paste-sample", "version": "0.0.1", + "hasInstallScript": true, "license": "MIT", "devDependencies": { "@types/node": "^16.11.7", - "@types/vscode": "^1.32.0", + "@types/vscode": "^1.77.0", "@typescript-eslint/eslint-plugin": "^5.42.0", "@typescript-eslint/parser": "^5.42.0", "eslint": "^8.26.0", - "typescript": "^5.0.2" + "typescript": "^5.0.2", + "vscode-dts": "^0.3.3" }, "engines": { - "vscode": "^1.69.0" + "vscode": "^1.77.0" } }, "node_modules/@eslint/eslintrc": { @@ -129,9 +131,10 @@ "dev": true }, "node_modules/@types/vscode": { - "version": "1.66.0", - "dev": true, - "license": "MIT" + "version": "1.78.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.78.0.tgz", + "integrity": "sha512-LJZIJpPvKJ0HVQDqfOy6W4sNKUBBwyDu1Bs8chHBZOe9MNuKTJtidgZ2bqjhmmWpUb0TIIqv47BFUcVmAsgaVA==", + "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "5.42.0", @@ -1077,6 +1080,15 @@ "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", "dev": true }, + "node_modules/kleur": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", + "integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", @@ -1157,6 +1169,15 @@ "node": "*" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -1300,6 +1321,19 @@ "node": ">= 0.8.0" } }, + "node_modules/prompts": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", + "integrity": "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==", + "dev": true, + "dependencies": { + "kleur": "^3.0.3", + "sisteransi": "^1.0.5" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", @@ -1434,6 +1468,12 @@ "node": ">=8" } }, + "node_modules/sisteransi": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", + "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==", + "dev": true + }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -1564,6 +1604,20 @@ "punycode": "^2.1.0" } }, + "node_modules/vscode-dts": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/vscode-dts/-/vscode-dts-0.3.3.tgz", + "integrity": "sha512-JfOsWL0NvfVw0UF9bcTjlv1Onz3Ted7cgpPWKWMnHGB+72t/tn8WFDeKLZO42l2k9KJq/NGS9rFC5gZbyI4FTg==", + "dev": true, + "dependencies": { + "minimist": "^1.2.0", + "prompts": "^2.1.0", + "rimraf": "^3.0.0" + }, + "bin": { + "vscode-dts": "index.js" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -1697,7 +1751,9 @@ "dev": true }, "@types/vscode": { - "version": "1.66.0", + "version": "1.78.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.78.0.tgz", + "integrity": "sha512-LJZIJpPvKJ0HVQDqfOy6W4sNKUBBwyDu1Bs8chHBZOe9MNuKTJtidgZ2bqjhmmWpUb0TIIqv47BFUcVmAsgaVA==", "dev": true }, "@typescript-eslint/eslint-plugin": { @@ -2374,6 +2430,12 @@ "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", "dev": true }, + "kleur": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", + "integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==", + "dev": true + }, "levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", @@ -2433,6 +2495,12 @@ "brace-expansion": "^1.1.7" } }, + "minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true + }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -2537,6 +2605,16 @@ "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true }, + "prompts": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", + "integrity": "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==", + "dev": true, + "requires": { + "kleur": "^3.0.3", + "sisteransi": "^1.0.5" + } + }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", @@ -2609,6 +2687,12 @@ "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", "dev": true }, + "sisteransi": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", + "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==", + "dev": true + }, "slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -2699,6 +2783,17 @@ "punycode": "^2.1.0" } }, + "vscode-dts": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/vscode-dts/-/vscode-dts-0.3.3.tgz", + "integrity": "sha512-JfOsWL0NvfVw0UF9bcTjlv1Onz3Ted7cgpPWKWMnHGB+72t/tn8WFDeKLZO42l2k9KJq/NGS9rFC5gZbyI4FTg==", + "dev": true, + "requires": { + "minimist": "^1.2.0", + "prompts": "^2.1.0", + "rimraf": "^3.0.0" + } + }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/document-paste/package.json b/document-paste/package.json index ace93d3c..0674df0d 100644 --- a/document-paste/package.json +++ b/document-paste/package.json @@ -11,11 +11,10 @@ "url": "https://github.com/Microsoft/vscode-extension-samples" }, "enabledApiProposals": [ - "textEditorDrop", "documentPaste" ], "engines": { - "vscode": "^1.69.0" + "vscode": "^1.77.0" }, "categories": [ "Other" @@ -29,14 +28,17 @@ "vscode:prepublish": "npm run compile", "compile": "tsc -p ./", "lint": "eslint \"src/**/*.ts\"", - "watch": "tsc -watch -p ./" + "watch": "tsc -watch -p ./", + "download-api": "vscode-dts main && vscode-dts dev", + "postinstall": "npm run download-api" }, "devDependencies": { "@types/node": "^16.11.7", - "@types/vscode": "^1.32.0", + "@types/vscode": "^1.77.0", "@typescript-eslint/eslint-plugin": "^5.42.0", "@typescript-eslint/parser": "^5.42.0", "eslint": "^8.26.0", - "typescript": "^5.0.2" + "typescript": "^5.0.2", + "vscode-dts": "^0.3.3" } } diff --git a/document-paste/src/extension.ts b/document-paste/src/extension.ts index 409ec0bb..ce61e5c3 100644 --- a/document-paste/src/extension.ts +++ b/document-paste/src/extension.ts @@ -30,7 +30,7 @@ class CopyCountPasteEditProvider implements vscode.DocumentPasteEditProvider { return undefined; } - const textDataTransferItem = dataTransfer.get('text') ?? dataTransfer.get('text/plain'); + const textDataTransferItem = dataTransfer.get('text/plain'); if (!textDataTransferItem) { return undefined; } @@ -42,7 +42,7 @@ class CopyCountPasteEditProvider implements vscode.DocumentPasteEditProvider { const snippet = new vscode.SnippetString(); snippet.appendText(`(copy #${count}) ${text}`); - return { insertText: snippet }; + return new vscode.DocumentPasteEdit(snippet, 'copyCount', "Insert with copy count sample"); } } diff --git a/document-paste/src/vscode.proposed.documentPaste.d.ts b/document-paste/src/vscode.proposed.documentPaste.d.ts deleted file mode 100644 index accae646..00000000 --- a/document-paste/src/vscode.proposed.documentPaste.d.ts +++ /dev/null @@ -1,70 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -declare module 'vscode' { - - // https://github.com/microsoft/vscode/issues/30066/ - - /** - * Provider invoked when the user copies and pastes code. - */ - interface DocumentPasteEditProvider { - - /** - * Optional method invoked after the user copies text in a file. - * - * During {@link prepareDocumentPaste}, an extension can compute metadata that is attached to - * a {@link DataTransfer} and is passed back to the provider in {@link provideDocumentPasteEdits}. - * - * @param document Document where the copy took place. - * @param ranges Ranges being copied in the `document`. - * @param dataTransfer The data transfer associated with the copy. You can store additional values on this for later use in {@link provideDocumentPasteEdits}. - * @param token A cancellation token. - */ - prepareDocumentPaste?(document: TextDocument, ranges: readonly Range[], dataTransfer: DataTransfer, token: CancellationToken): void | Thenable; - - /** - * Invoked before the user pastes into a document. - * - * In this method, extensions can return a workspace edit that replaces the standard pasting behavior. - * - * @param document Document being pasted into - * @param ranges Currently selected ranges in the document. - * @param dataTransfer The data transfer associated with the paste. - * @param token A cancellation token. - * - * @return Optional workspace edit that applies the paste. Return undefined to use standard pasting. - */ - provideDocumentPasteEdits(document: TextDocument, ranges: readonly Range[], dataTransfer: DataTransfer, token: CancellationToken): ProviderResult; - } - - /** - * An operation applied on paste - */ - interface DocumentPasteEdit { - /** - * The text or snippet to insert at the pasted locations. - */ - readonly insertText: string | SnippetString; - - /** - * An optional additional edit to apply on paste. - */ - readonly additionalEdit?: WorkspaceEdit; - } - - interface DocumentPasteProviderMetadata { - /** - * Mime types that `provideDocumentPasteEdits` should be invoked for. - * - * Use the special `files` mimetype to indicate the provider should be invoked if any files are present in the `DataTransfer`. - */ - readonly pasteMimeTypes: readonly string[]; - } - - namespace languages { - export function registerDocumentPasteEditProvider(selector: DocumentSelector, provider: DocumentPasteEditProvider, metadata: DocumentPasteProviderMetadata): Disposable; - } -} diff --git a/drop-on-document/src/extension.ts b/drop-on-document/src/extension.ts index a3f6a8de..541f936c 100644 --- a/drop-on-document/src/extension.ts +++ b/drop-on-document/src/extension.ts @@ -17,7 +17,7 @@ class ReverseTextOnDropProvider implements vscode.DocumentDropEditProvider { token: vscode.CancellationToken ): Promise { // Check the data transfer to see if we have some kind of text data - const dataTransferItem = dataTransfer.get('text') ?? dataTransfer.get('text/plain'); + const dataTransferItem = dataTransfer.get('text/plain'); if (!dataTransferItem) { return undefined; }