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

Incorrect completion in some cases #2626

Closed
mickaelistria opened this issue Apr 27, 2023 · 2 comments · Fixed by #2627
Closed

Incorrect completion in some cases #2626

mickaelistria opened this issue Apr 27, 2023 · 2 comments · Fixed by #2627
Milestone

Comments

@mickaelistria
Copy link
Contributor

In eclipseide-jdtls, I'm trying to complete syser to syserr proposal, but insertion seems to leave one character behind, ie syser is replaced with System.err.println();r.
Here is an example of client <-> server communication


[2023-04-27T18:07:43.091138618+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
Content-Length: 2337


[2023-04-27T18:07:43.091887595+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"1","method":"initialize","params":{"processId":990675,"rootPath":"/home/mistria/sandbox/eclipse-workspace/blah/","rootUri":"file:///home/mistria/sandbox/eclipse-workspace/blah/","initializationOptions":{"settings":{"java":{"project":{"resourceFilters":""},"implementationsCodeLens":{"enabled":false},"referencesCodeLens":{"enabled":false}}},"extendedClientCapabilities":{"debugTrace":false,"classFileContentsSupport":true,"skipTextEventPropagation":true,"skipProjectConfiguration":true,"excludedMarkerTypes":["org.eclipse.lsp4e.diagnostic"]}},"capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","delete","rename"],"failureHandling":"undo"},"symbol":{"dynamicRegistration":true},"executeCommand":{"dynamicRegistration":true},"workspaceFolders":true,"configuration":true},"textDocument":{"synchronization":{"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"completionItem":{"snippetSupport":true,"documentationFormat":["markdown","plaintext"],"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"insertTextModeSupport":{"valueSet":[1,2]}}},"hover":{"contentFormat":["markdown","plaintext"]},"signatureHelp":{},"references":{},"documentHighlight":{},"documentSymbol":{"symbolKind":{"valueSet":[18,17,5,14,9,10,22,24,8,1,12,11,20,6,2,3,21,16,19,25,4,7,15,23,26,13]},"hierarchicalDocumentSymbolSupport":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{},"definition":{"linkSupport":true},"typeDefinition":{"linkSupport":true},"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"dataSupport":true,"resolveSupport":{"properties":["edit"]},"dynamicRegistration":true},"codeLens":{},"documentLink":{},"colorProvider":{},"rename":{"prepareSupport":true},"foldingRange":{},"selectionRange":{},"inlayHint":{}},"window":{"workDoneProgress":true,"showMessage":{},"showDocument":{"support":true}}},"clientInfo":{"name":"Eclipse Platform","version":"0.16.1.202304262334"},"trace":"off","workspaceFolders":[{"uri":"file:///home/mistria/sandbox/eclipse-workspace/blah/","name":"blah"},{"uri":"file:///home/mistria/fosdem/workspace-demo/hello/","name":"hello"}]}}
[2023-04-27T18:07:44.770085650+02:00] LANGUAGE_SERVER_TO_LSP4E com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"1","result":{"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"willSave":true,"willSaveWaitUntil":true,"save":{"includeText":true}},"hoverProvider":true,"completionProvider":{"resolveProvider":true,"triggerCharacters":[".","@","#","*"," "]},"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"typeDefinitionProvider":true,"implementationProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"codeLensProvider":{"resolveProvider":true},"documentRangeFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":";","moreTriggerCharacter":["\n","}"]},"renameProvider":{"prepareProvider":true},"foldingRangeProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":true}},"callHierarchyProvider":true,"selectionRangeProvider":true,"semanticTokensProvider":{"legend":{"tokenTypes":["namespace","class","interface","enum","enumMember","type","typeParameter","method","property","variable","parameter","modifier","keyword","annotation","annotationMember","record","recordComponent"],"tokenModifiers":["abstract","static","readonly","deprecated","declaration","documentation","public","private","protected","native","generic","typeArgument","importDeclaration","constructor"]},"range":false,"full":{"delta":false},"documentSelector":[{"language":"java","scheme":"file"},{"language":"java","scheme":"jdt"}]},"inlayHintProvider":true}}}
[2023-04-27T18:07:44.776218690+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
Content-Length: 52


[2023-04-27T18:07:44.776447476+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","method":"initialized","params":{}}
[2023-04-27T18:07:44.781903048+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
Content-Length: 323


[2023-04-27T18:07:44.782140753+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///home/mistria/sandbox/eclipse-workspace/blah/src/blah/blah.java","languageId":"java","version":1,"text":"package blah;\n\nimport java.util.ArrayList;\nimport java.util.Collection;\n\nclass blah {\n  void f() {\n\t  syser\n  }\n}\n"}}}
[2023-04-27T18:07:44.793435196+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
Content-Length: 166


[2023-04-27T18:07:44.793695458+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"2","method":"textDocument/codeLens","params":{"textDocument":{"uri":"file:///home/mistria/sandbox/eclipse-workspace/blah/src/blah/blah.java"}}}
[2023-04-27T18:07:44.795737871+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
Content-Length: 242


[2023-04-27T18:07:44.795930882+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"3","method":"textDocument/inlayHint","params":{"textDocument":{"uri":"file:///home/mistria/sandbox/eclipse-workspace/blah/src/blah/blah.java"},"range":{"start":{"line":0,"character":0},"end":{"line":10,"character":0}}}}
[2023-04-27T18:07:44.798394754+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
Content-Length: 177


[2023-04-27T18:07:44.798606849+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"4","method":"textDocument/semanticTokens/full","params":{"textDocument":{"uri":"file:///home/mistria/sandbox/eclipse-workspace/blah/src/blah/blah.java"}}}
[2023-04-27T18:07:44.799811182+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
Content-Length: 260


[2023-04-27T18:07:44.800012263+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","method":"workspace/didChangeWorkspaceFolders","params":{"event":{"added":[{"uri":"file:///home/mistria/sandbox/eclipse-workspace/blah/","name":"blah"},{"uri":"file:///home/mistria/fosdem/workspace-demo/hello/","name":"hello"}],"removed":[]}}}
[2023-04-27T18:07:44.797962732+02:00] LANGUAGE_SERVER_TO_LSP4E com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","method":"language/status","params":{"type":"Starting","message":"0% Starting Java Language Server"}}
[2023-04-27T18:07:44.802845189+02:00] LANGUAGE_SERVER_TO_LSP4E com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"1","method":"client/registerCapability","params":{"registrations":[{"id":"37990e54-ea95-4836-bc78-64b69a0a40e7","method":"workspace/symbol"}]}}
[2023-04-27T18:07:44.802860058+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
Content-Length: 211


[2023-04-27T18:07:44.803004823+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"5","method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///home/mistria/sandbox/eclipse-workspace/blah/src/blah/blah.java"},"position":{"line":9,"character":1}}}
[2023-04-27T18:07:44.804024271+02:00] LANGUAGE_SERVER_TO_LSP4E com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"2","method":"client/registerCapability","params":{"registrations":[{"id":"6cab51ad-4569-4be2-b753-a55c65854de4","method":"workspace/didChangeWorkspaceFolders"}]}}
[2023-04-27T18:07:44.804409685+02:00] LANGUAGE_SERVER_TO_LSP4E com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"3","method":"client/registerCapability","params":{"registrations":[{"id":"67cadaab-b710-4c97-850c-faa4cf9a9719","method":"textDocument/formatting"}]}}
[2023-04-27T18:07:44.804649471+02:00] LANGUAGE_SERVER_TO_LSP4E com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"4","method":"client/registerCapability","params":{"registrations":[{"id":"06ed6b98-c8ad-4739-baa0-919635e70dad","method":"workspace/executeCommand","registerOptions":{"commands":["java.edit.organizeImports","java.project.refreshDiagnostics","java.project.import","java.navigate.openTypeHierarchy","java.project.removeFromSourcePath","java.project.listSourcePaths","java.project.resolveStackTraceLocation","java.project.getAll","java.reloadBundles","java.project.isTestFile","java.edit.handlePasteEvent","java.project.getClasspaths","java.navigate.resolveTypeHierarchy","java.edit.stringFormatting","java.project.getSettings","java.project.updateSourceAttachment","java.project.resolveWorkspaceSymbol","java.project.upgradeGradle","java.decompile","java.project.createModuleInfo","java.protobuf.generateSources","java.project.resolveSourceAttachment","java.project.addToSourcePath","java.completion.onDidSelect"]}}]}}
[2023-04-27T18:07:44.804909683+02:00] LANGUAGE_SERVER_TO_LSP4E com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"5","method":"client/registerCapability","params":{"registrations":[{"id":"d591a87c-e267-4a0c-ad18-1e41f5c0f160","method":"textDocument/codeAction","registerOptions":{"codeActionKinds":["quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"],"resolveProvider":true}}]}}
[2023-04-27T18:07:44.805785616+02:00] LANGUAGE_SERVER_TO_LSP4E com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"6","method":"workspace/executeClientCommand","params":{"command":"_java.reloadBundles.command","arguments":[]}}
[2023-04-27T18:07:44.806691947+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
Content-Length: 38


[2023-04-27T18:07:44.806897677+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"6","result":[]}
[2023-04-27T18:07:44.807646661+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
Content-Length: 40


[2023-04-27T18:07:44.807814655+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"2","result":null}
[2023-04-27T18:07:44.807984180+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
Content-Length: 40


[2023-04-27T18:07:44.808167369+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"3","result":null}
[2023-04-27T18:07:44.808360756+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
Content-Length: 40


[2023-04-27T18:07:44.808485977+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"5","result":null}
[2023-04-27T18:07:44.809139875+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
Content-Length: 40


[2023-04-27T18:07:44.809368586+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"1","result":null}
[2023-04-27T18:07:44.810711470+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
Content-Length: 40


[2023-04-27T18:07:44.810918207+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"4","result":null}
[2023-04-27T18:07:44.823896096+02:00] LANGUAGE_SERVER_TO_LSP4E com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","method":"language/status","params":{"type":"ServiceReady","message":"ServiceReady"}}
[2023-04-27T18:07:52.716789197+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"9","method":"textDocument/completion","params":{"textDocument":{"uri":"file:///home/mistria/sandbox/eclipse-workspace/blah/src/blah/blah.java"},"position":{"line":7,"character":8}}}
[2023-04-27T18:07:52.841554341+02:00] LANGUAGE_SERVER_TO_LSP4E com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"9","result":{"isIncomplete":false,"items":[{"label":"syserr","kind":15,"detail":"print to standard err","insertTextFormat":2,"textEdit":{"range":{"start":{"line":7,"character":3},"end":{"line":7,"character":7}},"newText":"System.err.println(${0});"},"command":{"title":"","command":"java.completion.onDidSelect","arguments":["1","0"]},"data":{"rid":"1","COMPLETION_EXECUTION_TIME":"120","pid":"0"}}]}}
[2023-04-27T18:07:52.913453973+02:00] LSP4E_TO_LANGUAGE_SERVER com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"10","method":"completionItem/resolve","params":{"label":"syserr","kind":15,"detail":"print to standard err","insertTextFormat":2,"textEdit":{"range":{"start":{"line":7,"character":3},"end":{"line":7,"character":7}},"newText":"System.err.println(${0});"},"command":{"title":"","command":"java.completion.onDidSelect","arguments":["1","0"]},"data":{"rid":"1","COMPLETION_EXECUTION_TIME":"120","pid":"0"}}}
[2023-04-27T18:07:52.917001074+02:00] LANGUAGE_SERVER_TO_LSP4E com.redhat.eclipseide.jdtlsclient.inProcessServer:
{"jsonrpc":"2.0","id":"10","result":{"label":"syserr","kind":15,"detail":"print to standard err","documentation":{"kind":"markdown","value":"```java\nSystem.err.println();\n```"},"insertTextFormat":2,"textEdit":{"range":{"start":{"line":7,"character":3},"end":{"line":7,"character":7}},"newText":"System.err.println(${0});"},"command":{"title":"","command":"java.completion.onDidSelect","arguments":["1","0"]}}}

The interesting part is the LS response: "textEdit":{"range":{"start":{"line":7,"character":3},"end":{"line":7,"character":7}} does define to replace syse range (since the end is excluded) and thus leaves the trailing r in the document.

@rgrunber
Copy link
Contributor

rgrunber commented Apr 27, 2023

If you're using resolve then the completion items shouldn't have any text edits in the response from textDocument/completion. Maybe you're missing a particular capability ?

I think I see your point though. Why has it been working for VS Code all this time ? @jdneo ?

I have something like :

public class Foo {
 void name() {
  syser|
 }
}
[Trace - 16:33:07] Sending request 'textDocument/completion - (673)'.
Params: {
    "textDocument": {
        "uri": "file:///tmp/foo/Foo.java"
    },
    "position": {
        "line": 2,
        "character": 7
    },
    "context": {
        "triggerKind": 1
    }
}
[Trace - 16:33:07] Received response 'textDocument/completion - (673)' in 18ms.
Result: {
    "isIncomplete": false,
    "items": [
        {
            "label": "syserr",
            "labelDetails": {
                "description": "print to standard err"
            },
            "kind": 15,
            "detail": "print to standard err",
            "insertText": "System.err.println(${0});",
            "insertTextFormat": 2,
            "command": {
                "title": "",
                "command": "java.completion.onDidSelect",
                "arguments": [
                    "21",
                    "0"
                ]
            },
            "data": {
                "rid": "21",
                "COMPLETION_EXECUTION_TIME": "14",
                "pid": "0"
            }
        }
    ],
    "itemDefaults": {}
}
[Trace - 16:33:07] Sending request 'completionItem/resolve - (674)'.
Params: {
    "label": "syserr",
    "labelDetails": {
        "description": "print to standard err"
    },
    "detail": "print to standard err",
    "insertTextFormat": 2,
    "insertText": "System.err.println(${0});",
    "kind": 15,
    "command": {
        "title": "",
        "command": "java.completion.onDidSelect",
        "arguments": [
            "21",
            "0"
        ]
    },
    "data": {
        "rid": "21",
        "COMPLETION_EXECUTION_TIME": "14",
        "pid": "0"
    }
}
[Trace - 16:33:07] Received response 'completionItem/resolve - (674)' in 7ms.
Result: {
    "label": "syserr",
    "labelDetails": {
        "description": "print to standard err"
    },
    "kind": 15,
    "detail": "print to standard err",
    "documentation": {
        "kind": "markdown",
        "value": "```java\nSystem.err.println();\n```"
    },
    "insertText": "System.err.println(${0});",
    "insertTextFormat": 2,
    "textEdit": {
        "range": {
            "start": {
                "line": 2,
                "character": 2
            },
            "end": {
                "line": 2,
                "character": 6
            }
        },
        "newText": "System.err.println(${0});"
    },
    "command": {
        "title": "",
        "command": "java.completion.onDidSelect",
        "arguments": [
            "21",
            "0"
        ]
    }
}

syser is denoted by the range (2,2) .. (2,7), so why would (2,2) .. (2,6) be correct for replacing the snippet ?

@mickaelistria
Copy link
Contributor Author

I imagine VSCode has some tweaks to "fix" such strange cases, intentionally or not. We had the same thing in LSP4E some time ago, with the behavior that was in place to better handle some lowly specified behavior was kept because "why not?", and removing it highlighted issues in some LSs. A similar story can have happened to VSCode.
Note that a test case the issue and a fix is available at #2627 . I didn't verify it for VSCode though.

@rgrunber rgrunber added this to the End May 2023 milestone Apr 28, 2023
rgrunber pushed a commit that referenced this issue Apr 28, 2023
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 a pull request may close this issue.

2 participants