-
Notifications
You must be signed in to change notification settings - Fork 456
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
Conversation
rgrunber
commented
May 6, 2024
- Use VS Code version to determine whether a DocumentPasteEdit vs. DocumentPasteEdit[] is returned
- Fixes The issue of being unable to use copy and paste occurs in version 1.30.0. #3631
- Use VS Code version to determine whether a DocumentPasteEdit vs. DocumentPasteEdit[] is returned Signed-off-by: Roland Grunberg <[email protected]>
@@ -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> { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.