redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.07k stars 433 forks source link

Copy paste will not escape content when code has error #3761

Closed jdneo closed 3 weeks ago

jdneo commented 3 weeks ago

https://github.com/user-attachments/assets/33bfdf76-f971-4285-b437-3c8986f29e3c

rgrunber commented 3 weeks ago

When the error is on the same line, there may be issues recovering the statement by the AST Parser. Ultimately, StringRangeFinder (which is just an AST Visitor) fails to visit the StringLiteral (never recovered).

Easy fix seems to be to call parser.setStatementsRecovery(true); around https://github.com/eclipse-jdtls/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/PasteEventHandler.java#L225-L226 . It might not recover every case, but it certainly does a better job. I can put together a PR.