vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

editor paste lags in response after large uptime

Open kraabrsg opened this issue 11 months ago • 6 comments

Hi, sometimes after quite of time working on a maven quarkus project the pasting of text (e.g. from one file into another) takes a quite amount of time to finish.

In this example one string should be replaced by another string (the one which is selected)

Image

Image

The new string was visible after 4-5 seconds.

We are on the newest extension version 1.40 (happend also before).

JAVASE 21 for language Server, JAVASE 17 for the project (runtime). WIN 10.

Further settings in workspace:

    "java.import.gradle.enabled": false,
    "java.import.gradle.annotationProcessing.enabled": false,
    "java.configuration.detectJdksAtStart": false,
    "java.compile.nullAnalysis.mode": "automatic",
    "java.jdt.ls.androidSupport.enabled": "off",
    "java.jdt.ls.protobufSupport.enabled": false,

Is this from the eclipse language Server, or is this coming from this extension ?

Thank you!

kraabrsg avatar Jan 29 '25 05:01 kraabrsg

vscode-java has a custom paste event handler that can automatically escape the content of Strings that are pasted within "...", attempt to fill in missing imports from pasted code, as well as properly set up project structure when pasting a block of code.

As a workaround, you could disable the Java extension's custom paste support by setting :

"[java]": {
   "editor.pasteAs.enabled": false
},

Just to confirm. Does it always take 4-5 seconds when performing the exact same action, or only after working on the project for a long time. It would help if you set "java.trace.server": "verbose". This will generate quite a bit of logging so maybe not desired to have enabled at all times. When the problem happens again, I would open the command palette and select Java: Open Java Language Server Log File. Do you see any errors reported around the time of that 4-5s delay ? Also, if you just open the Output view, there should be a Language Support For Java entry from the dropdown (ignore the Syntax Server one). I'd be interested in any of the messages that sent a workspace/executeCommand request, with a command of java.edit.handlePasteEvent. There should be a response to that request and it would probably indicate how long the language server took to respond.

Otherwise, I am aware of some general odd behaviour the language server has where after running for some time, certain requests temporarily take longer, but often recover.

rgrunber avatar Feb 05 '25 21:02 rgrunber

Hi @rgrunber thanks for getting back on this. I have set this setting and activated the trace. When i stumble upon this behaviour again (and i can provide more information) i will report here again...

kraabrsg avatar Feb 07 '25 12:02 kraabrsg

Just be aware that

"[java]": {
   "editor.pasteAs.enabled": false
},

would be expected to make the issue completely go away as it disables our paste contribution. The other setting/instructions I mentioned are more to learn more about potentially where the slowdown happens when the above setting is not present (custom paste enabled).

rgrunber avatar Feb 07 '25 14:02 rgrunber

Hi, I'm also running into this issue, see the log traces below. The logs don't seem to provide anything useful to figure out the root cause of this though. If there's anything I can do to help, let me know.

Either way the paste handler should:

  • determine as quickly as possible whether it can be of any use and if not, abort immediately
  • time out after 1 second. There is the little cross to cancel, but the paste handler should give up much faster itself. I shouldn't have to be bothered to click the cross because the paste handler has a bug that causes it to take half a minute to do nothing different than "dumb paste" would've done
[Trace - 12:36:10 PM] Sending request 'workspace/executeCommand - (4183)'.
Params: {
    "command": "java.edit.handlePasteEvent",
    "arguments": [
        "{\"location\":{\"range\":{\"start\":{\"line\":22,\"character\":8},\"end\":{\"line\":22,\"character\":8}},\"uri\":\"file:///c%3A/Users/.../Resources.java\"},\"text\":\"sha256:b59327fe979b1de9294b9eca3c84bcf77874e6e1b17f35b9a2da420dc3edfd76\",\"formattingOptions\":{\"insertSpaces\":true,\"tabSize\":4}}"
    ]
}

[Trace - 12:36:40 PM] Received response 'workspace/executeCommand - (4183)' in 30861ms.
No result returned.

[Trace - 12:36:11 PM] Sending request 'workspace/executeCommand - (4187)'.
Params: {
    "command": "java.edit.handlePasteEvent",
    "arguments": [
        "{\"location\":{\"range\":{\"start\":{\"line\":22,\"character\":8},\"end\":{\"line\":22,\"character\":8}},\"uri\":\"file:///c%3A/Users/.../Resources.java\"},\"text\":\"sha256:b59327fe979b1de9294b9eca3c84bcf77874e6e1b17f35b9a2da420dc3edfd76\",\"formattingOptions\":{\"insertSpaces\":true,\"tabSize\":4}}"
    ]
}

[Trace - 12:36:40 PM] Received response 'workspace/executeCommand - (4187)' in 29919ms.
No result returned.

anthonyvdotbe avatar Jun 17 '25 10:06 anthonyvdotbe

@anthonyvdotbe , does this happen consistently in the same file ? At the same spot ? Are you able to share the source file where this happens ?

rgrunber avatar Jun 17 '25 12:06 rgrunber

@rgrunber I'm no longer able to reproduce with the same string in the same file (I don't remember the exact spot). When it happens again I'll share the file exactly as it was at the time of the paste, though I doubt the bug is deterministic, i.e. that the combination of (source code, pasted text, cursor location) always reproduces the issue.

anthonyvdotbe avatar Jun 17 '25 12:06 anthonyvdotbe

@rgrunber here's an example with the source code exactly as it was (I marked the cursor position with <cursor>). However, as expected, once it has occurred, it doesn't reproduce anymore: right after it occurred I pressed Ctrl+Z and Ctrl+V, but this time the result was instant.

[Trace - 6:10:59 PM] Sending request 'workspace/executeCommand - (16661)'.
Params: {
    "command": "java.edit.handlePasteEvent",
    "arguments": [
        "{\"location\":{\"range\":{\"start\":{\"line\":20,\"character\":12},\"end\":{\"line\":20,\"character\":12}},\"uri\":\"file:///c%3A/Users/.../ListChangedModules.java\"},\"text\":\"\\\"%s-%s\\\".formatted(path.getName(2), path.getName(3))\",\"copiedDocumentUri\":\"file:///c%3A/Users/.../ListChangedModules.java\",\"formattingOptions\":{\"insertSpaces\":true,\"tabSize\":4}}"
    ]
}

[Trace - 6:11:02 PM] Received response 'workspace/executeCommand - (16661)' in 2915ms.
No result returned.
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;

public class ListChangedModules {

    record ChangedModule(String argoCdEnvironment, String argoCdAppName) {}

    public static void main(String... args) {
        Files.lines(Path.of(args[0]))
            .flatMap(ListChangedModules::extractArgoCdAppName)
            .distinct()
            .sorted()
            .forEachOrdered(null);
    }

    private static Stream<String> extractArgoCdAppName(String line) {
        var path = Path.of(line.substring(3, line.indexOf('\0')));
        return path.getRoot().startsWith("environment")
            ? Stream.of(new ChangedModule(line, 
            <cursor>))
            : Stream.empty();
    }
}

anthonyvdotbe avatar Jun 20 '25 16:06 anthonyvdotbe

UX around this could definitely be improved. I was confused as to why simple text pastes were taking so long, so I tried Ctrl-Shift-V instead, which as we all know is a common "just paste the clipboard without extra magic" shortcut. That avoids the paste delay ✅, but apparently also re-organizes the imports?! 💀 I've been falsely accusing poor Copilot of these crimes for weeks while restoring imports for my PRs from git history...

srstsavage avatar Aug 29 '25 22:08 srstsavage