-
Notifications
You must be signed in to change notification settings - Fork 476
Format content pasted into string literals #2703
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
Format content pasted into string literals #2703
Conversation
In order to use this PR:
|
Please make sure this doesn't affect text blocks (eg. |
src/pasteEventHandler.ts
Outdated
* @param context the extension context | ||
*/ | ||
export function registerPasteEventHandlers(context: ExtensionContext) { | ||
if (languages["registerDocumentPasteEditProvider"]){ |
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 @fbricon Looking at https://github.com/eclipse-theia/theia/blob/7abca9d57c966d621f2acc26008cf1a9e454949b/packages/plugin-ext/src/plugin/plugin-context.ts#L674 , I don't see registerDocumentPasteEditProvider
, so doesn't that imply this check would safely handle the case in such clients ?
@datho7561 , can you confirm the extension installs just fine on Theia with enableProposedApi
set the way we do here. If so I would think it should be fine.
Update : Nearly forgot, to truly test this, we can't use VS Code Insiders, because that's not what Theia would use. Just the released VS Code. While it seems it does contain the proposed API, David mentioned he couldn't actually get it working there, while in VS Code Insiders it works just fine. So it would be difficult to test this thoroughly, which is why I suggested just checking if it can install without issue.
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.
languages["registerDocumentPasteEditProvider"]
is probably correct, but yeah the concern is what's the behavior of theia when enableProposedApi is on
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.
From my testing in Theia, no warnings appear and the language server starts as normal, but none of the features I introduced are present (paste works exactly as it did before my change).
436e114
to
df3fa47
Compare
df3fa47
to
70b6930
Compare
Thanks for the review @CsCherrYY ! |
e418663
to
79c724f
Compare
I just checked the behaviours in different VS Code versions: 1.65.2 (the olderest version matches engine): 1.73.1 (newest stable): in the next stable release (suppose 1.74.0) our extension will work with the paste handler and there should not be any error. I'm considering if it's possible to update the engine in the extension, to restrict the new version is only available to new engine users. Is there any consideration from Theia side? @rgrunber |
looks like the newest VS Code release (1.74.0) includes the allowance of the proposed API of redhat.java, @datho7561 could you please help verify if this PR works as expected? |
79c724f
to
7a9cc40
Compare
As is, paste events don't seem to work with this PR in VS Code 1.74.0. I don't get any error pop ups or logs to the extension host complaining, but the pasted content doesn't get modified. I've rebased my PRs to make it easier to test out. I'll try a few things like changing the engine version to see if that makes a difference. |
I tried updating the engine version, but that didn't help. I also confirmed that the product.json contains the change to allow vscode-java to use the proposed api. |
7a9cc40
to
58d9fbb
Compare
It looks like the Markdown paste feature (where when you paste an image, it creates the image file in the workspace folder and adds a markdown image tag that references the file) also only works on Insiders. |
Did you set |
Nope, I forgot. Thanks for your help, it's working! |
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.
LGTM!
src/pasteEventHandler.ts
Outdated
} | ||
}; | ||
|
||
const pasteResponse: PDocumentPasteEdit = await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.HANDLE_PASTE_EVENT, pasteEventParams); |
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.
Calling JSON.stringify(pasteEventParams)
will save some code on the language server side deserialization. If you look around the codebase, you'll see we use this in many places. I can make the change.
- Invoke jdt.ls's `java.edit.handlePasteEvent` command when vscode-java receives a paste event Requires eclipse-jdtls/eclipse.jdt.ls#2349 Closes redhat-developer#1249 Signed-off-by: David Thompson <davthomp@redhat.com>
58d9fbb
to
5575d68
Compare
Testing this PR requires using
vscode-insiders
(until VS Code 1.74.0 is released).Uses the proposed API to modify pasted strings. It invokes jdt.ls's
java.edit.handlePasteEvent
command when vscode-java receives a paste event. When pasting into a string literal, jdt.ls modifies the content that's inserted so that the string content reflects the original value of the copied text. It uses string concatenation instead of the newer Java multiline string feature to represent multiline text.Requires eclipse-jdtls/eclipse.jdt.ls#2349
Closes #1249