Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve paste edit support across different VS Code versions. #3646

Merged
merged 1 commit into from
May 7, 2024

Conversation

rgrunber
Copy link
Member

@rgrunber rgrunber commented May 6, 2024

- Use VS Code version to determine whether a DocumentPasteEdit vs.
  DocumentPasteEdit[] is returned

Signed-off-by: Roland Grunberg <[email protected]>
@rgrunber rgrunber added this to the End May 2024 milestone May 6, 2024
@rgrunber rgrunber requested a review from datho7561 May 6, 2024 21:13
@@ -62,12 +63,13 @@ class PasteEditProvider implements DocumentPasteEditProvider {
}
}

async provideDocumentPasteEdits?(document: TextDocument, ranges: readonly Range[], dataTransfer: DataTransfer, context: DocumentPasteEditContext, token: CancellationToken): Promise<DocumentPasteEdit[]> {
async provideDocumentPasteEdits?(document: TextDocument, ranges: readonly Range[], dataTransfer: DataTransfer, context: DocumentPasteEditContext, token: CancellationToken): Promise<any> {
Copy link
Member Author

@rgrunber rgrunber May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@datho7561 , specifically is this ok ? The return value for DocumentPasteEditProvider is listed as ProviderResult<T[]> but I'd like to be able to support both DocumentPasteEdit (older) & DocumentPasteEdit[] (newer).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to support older versions. just don't crash

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any types that you use will only exist during compile time, so if it compiles, then you know the type declarations that you are using won't cause a problem. I think that Promise<any> is the right one to use here, because you can't use anything more specific if you want to say that it can also return Promise<DocumentPasteEdit>

Copy link
Member Author

@rgrunber rgrunber May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(After handling the isCancellationRequested failure) :

2024-05-07 10:10:15.057 [error] TypeError: Cannot read properties of undefined (reading 'value')
	at j.providePasteEdits (/tmp/foo/VSCode-linux-x64/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:104:44732)
	at process.processTicksAndRejections (node:internal/process/task_queues:96:5)

The crash occurs at https://github.com/microsoft/vscode/blob/6445d93c81ebe42c4cbd7a60712e0b17d9463e97/src/vs/workbench/api/common/extHostLanguageFeatures.ts#L560 (edit.insertText.value, on VS Code 1.81.0) because insertText is never checked for existence, so it treats the returned array as if it were a single element. I don't see how we would avoid crashing without checking the version and if we do that, we may as well support the full feature by just returning the single element.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me. The other way around this would be to bump the minimum supported version of VS Code, but that might not be good since then the most recent supported release for those versions is faulty.

@rgrunber rgrunber removed this from the End May 2024 milestone May 6, 2024
@rgrunber rgrunber merged commit 2f5094f into redhat-developer:master May 7, 2024
2 checks passed
@rgrunber rgrunber deleted the fix-3631 branch May 7, 2024 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The issue of being unable to use copy and paste occurs in version 1.30.0.
3 participants