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

How to debug with the new documentation? #469

Open
noklam opened this issue Jun 5, 2024 · 4 comments
Open

How to debug with the new documentation? #469

noklam opened this issue Jun 5, 2024 · 4 comments

Comments

@noklam
Copy link
Contributor

noklam commented Jun 5, 2024

https://pygls.readthedocs.io/en/latest/howto/use-the-pygls-playground.html

There are new instructions for differetion VSCode versions now:

  1. VSCode v1.89+
  2. VSCode v1.88 and older

For 1, It doesn't seem to work for me when I add debugger I see the server get restarted but the breakpoint is not triggered (LSP working normally).

For 2, am I suppose to launch a debugger separately? and how do I attach the debugger properly?

p.s. I have autosave enable so it's quite annoying everytime I type something in a file it restart my LSP.

@noklam
Copy link
Contributor Author

noklam commented Jun 5, 2024

I do remember that I used to borrow configuration from somewhere else, so it may not be the change of documentations. (unfortunately I lost my launch.json)

But I still struggle with debugging following https://pygls.readthedocs.io/en/latest/howto/use-the-pygls-playground.html, I have "pygls.server.debug": true

I am using the hover.py example, this is what I experienced.
debug0fail

@alcarney
Copy link
Collaborator

alcarney commented Jun 5, 2024

When it comes to debugging, there shouldn't be any difference between 1+2 (as it's the same extension), just the steps to get VSCode into a state where you can enable the playground itself are different.

Of course that's the theory, there maybe something I've overlooked 😅

The good(?) news is that I see the same behaviour as your gif, almost everything is working except that the breakpoints aren't working. Removing the following lines from .vscode/launch.json fixed the issue for me (I'm using VSCode v1.89)

  "pathMappings": [
      {
          "localRoot": "${workspaceFolder}",
          "remoteRoot": "."
      }
  ],

Does that work for you? (I really don't understand what this option does, or why we added it in the first place...)

p.s. I have autosave enable so it's quite annoying everytime I type something in a file it restart my LSP.

Yes, I can imagine! 😅, it should be easy enough to add an option to the playground to disable that.

@noklam
Copy link
Contributor Author

noklam commented Jun 6, 2024

Does that work for you? (I really don't understand what this option does, or why we added it in the first place...)

I suspect this is related but I am also very confused with how debugging work in VSCode in general.

I have two different errors:

  1. Sometimes it's looking for the wrong interpreter even if I set it properly.
Exception has occurred: FileNotFoundError
[Errno 2] No such file or directory: '/Users/Nok_Lam_Chan/.local/lib/python3.10'
  1. Sometimes it's a weird Blocking error
Exception has occurred: BlockingIOError
[Errno 35] Resource temporarily unavailable
  File "/Users/Nok_Lam_Chan/miniconda3/envs/lsp/lib/python3.10/asyncio/selector_events.py", line 115, in _read_from_self
    data = self._ssock.recv(4096)
  File "/Users/Nok_Lam_Chan/miniconda3/envs/lsp/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/Users/Nok_Lam_Chan/miniconda3/envs/lsp/lib/python3.10/asyncio/base_events.py", line 1909, in _run_once
    handle._run()
  File "/Users/Nok_Lam_Chan/miniconda3/envs/lsp/lib/python3.10/asyncio/base_events.py", line 603, in run_forever
    self._run_once()
  File "/Users/Nok_Lam_Chan/miniconda3/envs/lsp/lib/python3.10/asyncio/base_events.py", line 636, in run_until_complete
    self.run_forever()
  File "/Users/Nok_Lam_Chan/miniconda3/envs/lsp/lib/python3.10/site-packages/pygls/server.py", line 258, in start_io
    self.loop.run_until_complete(
  File "/Users/Nok_Lam_Chan/dev/demo/pygls/examples/servers/hover.py", line 87, in <module>
    server.start_io()
  File "/Users/Nok_Lam_Chan/miniconda3/envs/lsp/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/Nok_Lam_Chan/miniconda3/envs/lsp/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
BlockingIOError: [Errno 35] Resource temporarily unavailable

I cannot make it work yet, but this settings work for my extension, borrow from the Microsoft template.
https://github.com/kedro-org/vscode-kedro/blob/main/.vscode/launch.json

I notice they have this configuration

            "env": {
                "USE_DEBUGPY": "True"
            },

@alcarney
Copy link
Collaborator

alcarney commented Jun 6, 2024

Sometimes it's looking for the wrong interpreter even if I set it properly.

That's annoying, I know @tombh has had issues like that in the past, I wish I knew why... unfortunately/fortunately for me, these things tend to just work for me, so I don't have many ideas on what to try :/

So that we can focus on the debugging bit first, you can try setting the pygls.server.pythonPath option in .vscode/settings.json to skip the interpreter selection code for now.

Sometimes it's a weird Blocking error

That is weird... is that something you only see when trying to debug? Or can it happen in non-debug mode also?

I notice they have this configuration

"env": {
  "USE_DEBUGPY": "True"
},

Looking at the code, I think that is an option specific to the template, looks like they launch a dedicated debug script...

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

2 participants