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

The autosuggestion function does not suggest JDK standard classes after the laptop wakes up from sleep #3793

Open
alexandertsukanov opened this issue Sep 30, 2024 · 4 comments

Comments

@alexandertsukanov
Copy link

The language server fails to suggest JDK classes after the laptop wakes up from sleep mode.

  1. Java 17
  2. macOS 15.1 Beta (24B5055e) but the same happens on the stable macOS 15
  3. VSCode Version: 1.91.1
  4. Language server version 1.35.0 (September 26th, 2024)

Steps to reproduce:

  1. Open VSCode
  2. Leave the laptop until it goes to sleep.
  3. Wake up and try to use some standard class from JDK
  4. Observer the issue

Actually, restart of the VScode makes the language server to work again, but not sure if it is expected.

@alexandertsukanov
Copy link
Author

Seems like the duplicate of #3715

However, I can't be 100% sure since I encounter my issue after my laptop wakes from sleep.

@fp024
Copy link

fp024 commented Oct 1, 2024

I am experiencing the same issue…

Running "Clean Java Language Server Workspace" temporarily resolves the issue, but it reoccurs eventually.

However, there is a peculiar phenomenon.

When the issue occurs, instead of running "Clean Java Language Server Workspace", if I close and reopen VSCode, the import suggestions for standard libraries work fine while the project is loading, but once the loading is complete, the import suggestions stop working.

@alexandertsukanov
Copy link
Author

alexandertsukanov commented Oct 1, 2024

I am wondering if this issue is only related to macOS. Does it affect all operating systems?

@rgrunber
Copy link
Member

rgrunber commented Oct 3, 2024

I have seen similar behaviour (Linux) but it happened maybe once or twice ever. If it's the same issue, it definitely seems to have started happening more frequently (based on users filing it). I was able to capture the code action before when this happened but nothing really stands out :

code action difference
--- response_good.txt	2024-08-14 10:46:30.022031338 -0400
+++ response_bad.txt	2024-08-14 10:43:11.265681603 -0400
@@ -1,12 +1,12 @@
 {
-  message: "[Trace - 14:18:26] Received response 'textDocument/codeAction - (28)' in 750ms.",
+  message: "[Trace - 14:16:15] Received response 'textDocument/codeAction - (2477)' in 85ms.",
   level: 'info',
-  timestamp: '2024-08-13 14:18:26.557'
+  timestamp: '2024-08-13 14:16:15.226'
 }
 {
   message: 'Result: [\n' +
     '    {\n' +
-    `        "title": "Import 'JsonArray' (com.google.gson)",\n` +
+    `        "title": "Create class 'JsonArray'",\n` +
     '        "kind": "quickfix",\n' +
     '        "diagnostics": [\n' +
     '            {\n' +
@@ -50,11 +50,11 @@
     '        ],\n' +
     '        "data": {\n' +
     '            "pid": "0",\n' +
-    '            "rid": "0"\n' +
+    '            "rid": "257"\n' +
     '        }\n' +
     '    },\n' +
     '    {\n' +
-    '        "title": "Add all missing imports",\n' +
+    `        "title": "Create enum 'JsonArray'",\n` +
     '        "kind": "quickfix",\n' +
     '        "diagnostics": [\n' +
     '            {\n' +
@@ -98,11 +98,11 @@
     '        ],\n' +
     '        "data": {\n' +
     '            "pid": "1",\n' +
-    '            "rid": "0"\n' +
+    '            "rid": "257"\n' +
     '        }\n' +
     '    },\n' +
     '    {\n' +
-    `        "title": "Create class 'JsonArray'",\n` +
+    `        "title": "Create interface 'JsonArray'",\n` +
     '        "kind": "quickfix",\n' +
     '        "diagnostics": [\n' +
     '            {\n' +
@@ -146,11 +146,11 @@
     '        ],\n' +
     '        "data": {\n' +
     '            "pid": "2",\n' +
-    '            "rid": "0"\n' +
+    '            "rid": "257"\n' +
     '        }\n' +
     '    },\n' +
     '    {\n' +
-    `        "title": "Create enum 'JsonArray'",\n` +
+    `        "title": "Add type parameter 'JsonArray' to 'BuildWorkspaceHandler'",\n` +
     '        "kind": "quickfix",\n' +
     '        "diagnostics": [\n' +
     '            {\n' +
@@ -194,11 +194,11 @@
     '        ],\n' +
     '        "data": {\n' +
     '            "pid": "3",\n' +
-    '            "rid": "0"\n' +
+    '            "rid": "257"\n' +
     '        }\n' +
     '    },\n' +
     '    {\n' +
-    `        "title": "Create interface 'JsonArray'",\n` +
+    `        "title": "Add type parameter 'JsonArray' to 'buildWorkspace(boolean, IProgressMonitor)'",\n` +
     '        "kind": "quickfix",\n' +
     '        "diagnostics": [\n' +
     '            {\n' +
@@ -242,125 +242,104 @@
     '        ],\n' +
     '        "data": {\n' +
     '            "pid": "4",\n' +
-    '            "rid": "0"\n' +
+    '            "rid": "257"\n' +
     '        }\n' +
     '    },\n' +
     '    {\n' +
-    `        "title": "Add type parameter 'JsonArray' to 'BuildWorkspaceHandler'",\n` +
-    '        "kind": "quickfix",\n' +
-    '        "diagnostics": [\n' +
-    '            {\n' +
-    '                "range": {\n' +
-    '                    "start": {\n' +
-    '                        "line": 99,\n' +
-    '                        "character": 4\n' +
-    '                    },\n' +
-    '                    "end": {\n' +
-    '                        "line": 99,\n' +
-    '                        "character": 13\n' +
-    '                    }\n' +
-    '                },\n' +
-    '                "severity": 1,\n' +
-    '                "code": "16777218",\n' +
-    '                "source": "Java",\n' +
-    '                "message": "JsonArray cannot be resolved to a type",\n' +
-    '                "data": [\n' +
-    '                    "JsonArray"\n' +
-    '                ]\n' +
-    '            },\n' +
-    '            {\n' +
-    '                "range": {\n' +
-    '                    "start": {\n' +
-    '                        "line": 99,\n' +
-    '                        "character": 25\n' +
-    '                    },\n' +
-    '                    "end": {\n' +
-    '                        "line": 99,\n' +
-    '                        "character": 34\n' +
-    '                    }\n' +
-    '                },\n' +
-    '                "severity": 1,\n' +
-    '                "code": "16777218",\n' +
-    '                "source": "Java",\n' +
-    '                "message": "JsonArray cannot be resolved to a type",\n' +
-    '                "data": [\n' +
-    '                    "JsonArray"\n' +
-    '                ]\n' +
-    '            }\n' +
-    '        ],\n' +
+    '        "title": "Add Javadoc comment",\n' +
+    '        "kind": "quickassist",\n' +
     '        "data": {\n' +
     '            "pid": "5",\n' +
-    '            "rid": "0"\n' +
+    '            "rid": "257"\n' +
     '        }\n' +
     '    },\n' +
     '    {\n' +
-    `        "title": "Add type parameter 'JsonArray' to 'buildWorkspace(boolean, IProgressMonitor)'",\n` +
-    '        "kind": "quickfix",\n' +
-    '        "diagnostics": [\n' +
-    '            {\n' +
-    '                "range": {\n' +
-    '                    "start": {\n' +
-    '                        "line": 99,\n' +
-    '                        "character": 4\n' +
-    '                    },\n' +
-    '                    "end": {\n' +
-    '                        "line": 99,\n' +
-    '                        "character": 13\n' +
-    '                    }\n' +
-    '                },\n' +
-    '                "severity": 1,\n' +
-    '                "code": "16777218",\n' +
-    '                "source": "Java",\n' +
-    '                "message": "JsonArray cannot be resolved to a type",\n' +
-    '                "data": [\n' +
-    '                    "JsonArray"\n' +
-    '                ]\n' +
-    '            },\n' +
-    '            {\n' +
-    '                "range": {\n' +
-    '                    "start": {\n' +
-    '                        "line": 99,\n' +
-    '                        "character": 25\n' +
-    '                    },\n' +
-    '                    "end": {\n' +
-    '                        "line": 99,\n' +
-    '                        "character": 34\n' +
-    '                    }\n' +
-    '                },\n' +
-    '                "severity": 1,\n' +
-    '                "code": "16777218",\n' +
-    '                "source": "Java",\n' +
-    '                "message": "JsonArray cannot be resolved to a type",\n' +
-    '                "data": [\n' +
-    '                    "JsonArray"\n' +
-    '                ]\n' +
-    '            }\n' +
-    '        ],\n' +
+    `        "title": "Add final modifier for 'uris'",\n` +
+    '        "kind": "quickassist",\n' +
+    '        "diagnostics": [],\n' +
     '        "data": {\n' +
     '            "pid": "6",\n' +
-    '            "rid": "0"\n' +
+    '            "rid": "257"\n' +
     '        }\n' +
     '    },\n' +
     '    {\n' +
-    '        "title": "Add Javadoc comment",\n' +
-    '        "kind": "quickassist",\n' +
+    '        "title": "Organize imports",\n' +
+    '        "kind": "source.organizeImports",\n' +
+    '        "diagnostics": [],\n' +
     '        "data": {\n' +
     '            "pid": "7",\n' +
-    '            "rid": "0"\n' +
+    '            "rid": "257"\n' +
     '        }\n' +
     '    },\n' +
     '    {\n' +
-    `        "title": "Add final modifier for 'uris'",\n` +
-    '        "kind": "quickassist",\n' +
+    '        "title": "Add all missing imports",\n' +
+    '        "kind": "source",\n' +
     '        "diagnostics": [],\n' +
     '        "data": {\n' +
     '            "pid": "8",\n' +
-    '            "rid": "0"\n' +
+    '            "rid": "257"\n' +
     '        }\n' +
     '    },\n' +
     '    {\n' +
-    '        "title": "Organize imports",\n' +
-    '        "kind": "source.organizeImp'... 15248 more characters,
+    '        "title": "Generate Getters",\n' +
+    '        "kind": "source.generate.accessors",\n' +
+    '        "diagnostics": [],\n' +
+    '        "data": {\n' +
+    '            "pid": "9",\n' +
+    '            "rid": "257"\n' +
+    '        }\n' +
+    '    },\n' +
+    '    {\n' +
+    '        "title": "Generate Constructors...",\n' +
+    '        "kind": "source.generate.constructors",\n' +
+    '        "diagnostics": [],\n' +
+    '        "command": {\n' +
+    '            "title": "Generate Constructors...",\n' +
+    '            "command": "java.action.generateConstructorsPrompt",\n' +
+    '            "arguments": [\n' +
+    '                {\n' +
+    '                    "textDocument": {\n' +
+    '                        "uri": "file:///home/rgrunber/git/eclipse.jdt.ls/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BuildWorkspaceHandler.java"\n' +
+    '                    },\n' +
+    '                    "range": {\n' +
+    '                        "start": {\n' +
+    '                            "line": 99,\n' +
+    '                            "character": 37\n' +
+    '                        },\n' +
+    '                        "end": {\n' +
+    '                            "line": 99,\n' +
+    '                            "character": 37\n' +
+    '                        }\n' +
+    '                    },\n' +
+    '                    "context": {\n' +
+    '                        "diagnostics": [\n' +
+    '                            {\n' +
+    '                                "range": {\n' +
+    '                                    "start": {\n' +
+    '                                        "line": 99,\n' +
+    '                                        "character": 4\n' +
+    '                                    },\n' +
+    '                                    "end": {\n' +
+    '                                        "line": 99,\n' +
+    '                                        "character": 13\n' +
+    '                                    }\n' +
+    '                                },\n' +
+    '                                "severity": 1,\n' +
+    '                                "code": "16777218",\n' +
+    '                                "source": "Java",\n' +
+    '                                "message": "JsonArray cannot be resolved to a type",\n' +
+    '                                "data": [\n' +
+    '                                    "JsonArray"\n' +
+    '                                ]\n' +
+    '                            },\n' +
+    '                            {\n' +
+    '                                "range": {\n' +
+    '                                    "start": {\n' +
+    '                                        "line": 99,\n' +
+    '                                        "character": 25\n' +
+    '                                    },\n' +
+    '                                    "end": {\n' +
+    '                                        "line":'... 12557 more characters,
   level: 'info',
-  timestamp: '2024-08-13 14:18:26.557'
+  timestamp: '2024-08-13 14:16:15.226'
 }

The interesting part is that code actions continue to work. It's just the ones relating to the type (that can no longer be detected) that are removed.

For those that are encountering this, a few things to try that might help narrow this down a bit. Immediately after you see this happening :

  • At the bottom left corner, there should be a Java status icon. Is it in the "Ready" state ?
    image
  • At the bottom right corner there should be a Java language mode icon. Does it clearly indicate a Java execution environment version ?
    image
  • Are there any errors in the problems view ? Maybe relating to the import of the project ?
  • If you go to the command palette and call the command Java: Open Java Language Server Log File, are there any errors/something strange being logged around the time this occurs ?
  • If you bring up the workspace symbol search (ctrl + t or Go -> Go To Symbol In Workspace), are you able to search for the missing type, or any other types on the classpath ?
  • If "Import 'SomeType'" doesn't show up, do you see "Add all missing imports" or "Organize Imports" ? Do any of those work ?

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

No branches or pull requests

3 participants