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

Unable to start adapter: Unable to connect to LSP client (timed out) #216

Open
o-oconnell opened this issue Apr 22, 2023 · 8 comments
Open

Comments

@o-oconnell
Copy link

o-oconnell commented Apr 22, 2023

Debugger: 0.10.1
LSP: 1.23.0
LSP-jdtls: 2.1.0

Steps to reproduce:

  1. Install all three of the above packages.
  2. LSP: enable language server in project -> jdtls
  3. Debugger: add or select configuration -> Add configuration -> java -> Java: launch program

My sublime-project:

{
	"folders":
	[
		{
			"path": ".",
		}
	],
	"settings":
	{
		"LSP":
		{
			"jdtls":
			{
				"enabled": true,
			},
		},
	},
	"debugger_configurations":
	[
		{
			"type": "java",
			"name": "Launch Java Program",
			"request": "launch",
			"mainClass": "test"
		},
	],
}
/

(there is a file test.java in my project with contents:
public class test { public static void main() { System.out.println("hello"); } }

Autocompletion / syntax highlighting are working fine with LSP-jdtls in this file, as evidenced by LSP: toggle log panel:

:: [21:07:40.791] <<< jdtls (15) (duration: 16ms): [{'kind': 'source.organizeImports', 'diagnostics': [], 'title': 'Organize imports', 'data': {'rid': '7', 'pid': '0'}}, {'kind': 'source.generate.toString', 'diagnostics': [], 'title': 'Generate toString()', 'data': {'rid': '7', 'pid': '1'}}]
:: [21:07:40.936] <<< jdtls (14) (duration: 164ms): {'contents': {'value': 'void java.io.PrintStream.println(String x)', 'language': 'java'}}
:: [21:07:42.281] --> jdtls textDocument/codeAction (16): {'textDocument': {'uri': 'file:///home/hjkl/2java/test.java'}, 'range': {'start': {'line': 1, 'character': 11}, 'end': {'line': 1, 'character': 11}}, 'context': {'triggerKind': 1, 'only': ['refactor', 'source'], 'diagnostics': []}}
:: [21:07:42.283] <-- jdtls workspace/configuration (26): {'items': [{'scopeUri': 'file:///home/hjkl/2java/test.java', 'section': 'java.format.tabSize'}, {'scopeUri': 'file:///home/hjkl/2java/test.java', 'section': 'java.format.insertSpaces'}]}
:: [21:07:42.285] >>> jdtls (26) (duration: 1ms): [4, False]
:: [21:07:42.293] <<< jdtls (16) (duration: 11ms): [{'kind': 'source.organizeImports', 'diagnostics': [], 'title': 'Organize imports', 'data': {'rid': '8', 'pid': '0'}}, {'kind': 'source.generate.toString', 'diagnostics': [], 'title': 'Generate toString()', 'data': {'rid': '8', 'pid': '1'}}]
:: [21:08:12.373] --> jdtls textDocument/codeAction (17): {'textDocument': {'uri': 'file:///home/hjkl/2java/test.java'}, 'range': {'start': {'line': 1, 'character': 11}, 'end': {'line': 1, 'character': 11}}, 'context': {'triggerKind': 2, 'diagnostics': []}}
:: [21:08:12.378] <-- jdtls workspace/configuration (27): {'items': [{'scopeUri': 'file:///home/hjkl/2java/test.java', 'section': 'java.format.tabSize'}, {'scopeUri': 'file:///home/hjkl/2java/test.java', 'section': 'java.format.insertSpaces'}]}
:: [21:08:12.382] >>> jdtls (27) (duration: 4ms): [4, False]
:: [21:08:12.399] <<< jdtls (17) (duration: 25ms): [{'kind': 'source.organizeImports', 'diagnostics': [], 'title': 'Organize imports', 'data': {'rid': '9', 'pid': '0'}}, {'kind': 'source.generate.toString', 'diagnostics': [], 'title': 'Generate toString()', 'data': {'rid': '9', 'pid': '1'}}]
:: [21:08:26.580] --> jdtls textDocument/codeAction (18): {'textDocument': {'uri': 'file:///home/hjkl/2java/test.java'}, 'range': {'start': {'line': 1, 'character': 11}, 'end': {'line': 1, 'character': 11}}, 'context': {'triggerKind': 1, 'only': ['refactor', 'source'], 'diagnostics': []}}
:: [21:08:26.582] <-- jdtls workspace/configuration (28): {'items': [{'scopeUri': 'file:///home/hjkl/2java/test.java', 'section': 'java.format.tabSize'}, {'scopeUri': 'file:///home/hjkl/2java/test.java', 'section': 'java.format.insertSpaces'}]}
:: [21:08:26.583] >>> jdtls (28) (duration: 1ms): [4, False]
:: [21:08:26.596] <<< jdtls (18) (duration: 16ms): [{'kind': 'source.organizeImports', 'diagnostics': [], 'title': 'Organize imports', 'data': {'rid': '10', 'pid': '0'}}, {'kind': 'source.generate.toString', 'diagnostics': [], 'title': 'Generate toString()', 'data': {'rid': '10', 'pid': '1'}}]

Sublime console log:

plugins loaded
Debugger: [startup]
Debugger: [finished]
Package Control: Skipping automatic upgrade, last run at 2023-04-21 20:10:57, next run at 2023-04-21 21:10:57 or after
reloading settings Packages/User/Package Control.sublime-settings
Traceback (most recent call last):
  File "/home/xxxxxxxx/.config/sublime-text/Packages/Debugger/modules/debugger.py", line 62, in get
    instance = Debugger(window, skip_project_check=skip_project_check)
  File "/home/xxxxxxxx/.config/sublime-text/Packages/Debugger/modules/debugger.py", line 97, in __init__
    self.project = Project(window, skip_project_check)
  File "/home/xxxxxxxx/.config/sublime-text/Packages/Debugger/modules/project.py", line 23, in __init__
    raise core.Error("Debugger must be run inside a sublime project")
Debugger.modules.core.error.Error: Debugger must be run inside a sublime project

Unable to open /home/xxxxxxxx/.config/sublime-text/Packages/Default/Default (Linux).sublime-keymap
Unable to open /home/xxxxxxxx/.config/sublime-text/Packages/User/Default (Linux).sublime-keymap
Debugger: ProjectConfiguration.reload
Debugger: error: Unable to start adapter: Unable to connect to LSP client (timed out)
Traceback (most recent call last):
  File "/home/xxxxxxxx/.config/sublime-text/Packages/Debugger/modules/dap/session.py", line 192, in _launch
    transport = await self.adapter_configuration.start(log=self.log, configuration=self.configuration)
  File "/home/xxxxxxxx/.config/sublime-text/Packages/Debugger/modules/adapters/java.py", line 36, in start
    configuration['mainClass'], configuration['projectName'] = await self._get_mainclass_project_name(None if _is_undefined('mainClass') else configuration['mainClass'])
  File "/home/xxxxxxxx/.config/sublime-text/Packages/Debugger/modules/adapters/java.py", line 61, in _get_mainclass_project_name
    mainclasses = await self.lsp_execute_command('vscode.java.resolveMainClass')
  File "/home/xxxxxxxx/.config/sublime-text/Packages/Debugger/modules/adapters/java.py", line 136, in lsp_execute_command
    return await self.lsp_request('workspace/executeCommand', {
  File "/home/xxxxxxxx/.config/sublime-text/Packages/Debugger/modules/adapters/java.py", line 142, in lsp_request
    return await util.lsp.request('jdtls', method, params)
  File "/home/xxxxxxxx/.config/sublime-text/Packages/Debugger/modules/adapters/util/lsp.py", line 10, in request
    raise core.Error('Unable to connect to LSP client (timed out)') from None
Debugger.modules.core.error.Error: Unable to connect to LSP client (timed out)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/xxxxxxxx/.config/sublime-text/Packages/Debugger/modules/dap/session.py", line 162, in launch
    await self.launching_async
  File "/home/xxxxxxxx/.config/sublime-text/Packages/Debugger/modules/dap/session.py", line 194, in _launch
    raise core.Error(f'Unable to start adapter: {e}')
Debugger.modules.core.error.Error: Unable to start adapter: Unable to connect to LSP client (timed out)

Protocol log:

-- platform: linux-x64
-- theme: auto
-- color_scheme: Mariana.sublime-color-scheme
-- font_face: Monospace
-- font_size: 10

-- adapter: type=java version=0.49.1

It is clear that Debugger cannot connect to LSP-jdtls, so I assume it is an incorrect param or something since the language server is working. I also tried downgrading to Debugger 0.9.3 and LSP-jdtls 2.0.0, same bug. It is a timeout but I cannot get any more detail beyond that. Since it's a sublime command being run (https://github.com/daveleroy/SublimeDebugger/blob/master/modules/adapters/util/bridge.py#L33) maybe sublime has some sort of log that would give more info? I have not found it yet if so.

I was able to reproduce this with @LDAP 's fix: https://github.com/LDAP/sublime_debugger/tree/fix/false-lsp-object, essentially the same except you get an asyncio.cancelledError.

@o-oconnell
Copy link
Author

@o-oconnell
Copy link
Author

I noticed that https://github.com/LDAP/sublime_debugger/blob/b96bd290b71c64d0024bd800246603491aba6af2/modules/adapters/util/lsp.py#L22 and https://github.com/daveleroy/SublimeDebugger/blob/master/modules/adapters/util/lsp.py#L8

have switched the command from "debugger_lsp_bridge_request" to "debugger_bridge_lsp_request" but that doesn't seem to fix it- could be related?

Do you know if there is a way to view a log of commands sent to sublime text via sublime.active_window().run_command(command, data)? Could be an error in there but I can't find a log.

@LDAP
Copy link
Contributor

LDAP commented Apr 22, 2023

Yes you can log commands by executing sublime.log_commands(True) in the console.

Maybe try deleting the folder Debugger33 in the Packages folder and restarting sublime.

@quot
Copy link

quot commented Apr 26, 2023

Maybe try deleting the folder Debugger33 in the Packages folder and restarting sublime.

This worked for me. Thanks. I have a new error for my config, but at least that's my fault.

@o-oconnell
Copy link
Author

Yes that solved this issue for me as well thanks, I'll put a more complete list of the bugs I had after that and how I solved them when my school is finished, cheers.

@o-oconnell
Copy link
Author

Two more bugs I have found are the adapter failing to resolve the project name (#221) and a "failed to resolve main class". The main class cannot be resolved if there is no string passed to its main method. If you change the java code in examples to:

class Main {
	public static void main(){
		System.out.println("Test");
	}
}

You will get:

Debugger: error: Unable to start adapter: Mainclass Main not found. Check your debugger configuration or leave "mainClass" empty to detect the mainclass automatically
Traceback (most recent call last):
  File "/home/xxxx/.config/sublime-text/Packages/Debugger/modules/dap/session.py", line 192, in _launch
    transport = await self.adapter_configuration.start(log=self.log, configuration=self.configuration)
  File "/home/xxxx/.config/sublime-text/Packages/Debugger/modules/adapters/java.py", line 36, in start
    configuration['mainClass'], configuration['projectName'] = await self._get_mainclass_project_name(None if _is_undefined('mainClass') else configuration['mainClass'])
  File "/home/xxxx/.config/sublime-text/Packages/Debugger/modules/adapters/java.py", line 71, in _get_mainclass_project_name
    raise core.Error('Mainclass {} not found. Check your debugger configuration or leave "mainClass" empty to detect the mainclass automatically'.format(preferred_mainclass))
Debugger.modules.core.error.Error: Mainclass Main not found. Check your debugger configuration or leave "mainClass" empty to detect the mainclass automatically

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/xxxx/.config/sublime-text/Packages/Debugger/modules/dap/session.py", line 162, in launch
    await self.launching_async
  File "/home/xxxx/.config/sublime-text/Packages/Debugger/modules/dap/session.py", line 194, in _launch
    raise core.Error(f'Unable to start adapter: {e}')
Debugger.modules.core.error.Error: Unable to start adapter: Mainclass Main not found. Check your debugger configuration or leave "mainClass" empty to detect the mainclass automatically

However this works fine:

class Main {
	public static void main(String[] args){
		System.out.println("Test");
	}
}

@LDAP
Copy link
Contributor

LDAP commented May 14, 2023

@o-oconnell

The main class cannot be resolved if there is no string passed to its main method.

This is just how Java works (the signature of a main method is clearly defined as public static void main(String[])), that has nothing to do with the JDTLS or Debugger.

@daveleroy The only issue remaining is that sometimes the Debugger33 package gets corrupted. In my case, the plugin file was empty and was not updated by Debugger.

@daveleroy
Copy link
Owner

@daveleroy The only issue remaining is that sometimes the Debugger33 package gets corrupted. In my case, the plugin file was empty and was not updated by Debugger.

Debugger33 only gets updated if it was removed in plugin_unloaded so if you aren't reloading the plugin it might never get updated.

I guess it could just always remove/install it in plugin_loaded since plugin_unloaded isn't called reliably.

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

4 participants