Skip to content

Make the pygls-playground extension a workspace local extension#458

Merged
alcarney merged 6 commits into
openlawlibrary:mainfrom
alcarney:local-extension
May 24, 2024
Merged

Make the pygls-playground extension a workspace local extension#458
alcarney merged 6 commits into
openlawlibrary:mainfrom
alcarney:local-extension

Conversation

@alcarney

@alcarney alcarney commented May 12, 2024

Copy link
Copy Markdown
Collaborator

Description (e.g. "Related to ...", etc.)

image

With the latest version of VSCode (v1.89), there is now the concept of a workspace local extension. Any valid VSCode extension underneath the .vscode/extensions directory of a project are recognised by the UI and can be installed as you would any other extension.

This PR converts the pygls-playground extension to be workspace local which should make it a lot easier to get up and running with the example servers.

  • The user still has to install dependencies and build the extension as before
  • From there however, they should be able to install the extension as they would any other and use the playground directly from their main VSCode instance.

What about older VSCode versions?

The extension is still compatible with older versions of VSCode, using the old 2-window approach. Assuming I've not missed anything, the only difference should be the folder from which the 2nd debug session is launched from.

Code review checklist (for code reviewer to complete)

  • Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR)
  • Title summarizes what is changing
  • Commit messages are meaningful (see this for details)
  • Tests have been included and/or updated, as appropriate
  • Docstrings have been included and/or updated, as appropriate
  • Standalone docs have been updated accordingly

@alcarney alcarney requested a review from tombh May 12, 2024 18:09
@tombh

tombh commented May 12, 2024

Copy link
Copy Markdown
Collaborator

Is it easy to try this out? I see this extension available at the moment in my VSCode
image
It's by "noklam", is that you?

@alcarney

Copy link
Copy Markdown
Collaborator Author

I see this extension available at the moment in my VSCode

Hmm, looks like someone (not me) has published a version of the extension to the marketplace....

Is it easy to try this out?

Hopefully, it's easier than it used to be!

While you still have to build the extension yourself (steps are in the extension's README), once it's built you should be able to hit the Install Workspace Extension button, like in my screenshot above and have the playground Just WorkTM - no need to open multiple VSCode windows anymore.

@alcarney

Copy link
Copy Markdown
Collaborator Author

image

I've bumped the version number of the local extension so it should be easier to tell when you've found the right instance of it

@tombh

tombh commented May 16, 2024

Copy link
Copy Markdown
Collaborator

I'm getting stuck again I'm afraid 😞 I think it's just that I'm not familiar with VSCode. Here's some general notes:

  • Would npm install --no-save be better so as not to modify the package-lock.json files?
  • The instructions in pygls-playground/README are really good, the only thing was when it came to playing with a language server: it doesn't say that the examples are at examples/servers/...
  • I couldn't find Pygls > Client: Document Selector in the command pallete.
  • It wasn't immediately clear to me that "pygls.client.documentSelector" is in .vscode/settings.json.
  • How are the workspace files associated with the example servers? Eg how would I know how to play with workspace/table.txt?
  • I got an an error launching the Pygls server 🥺 Error: spawn /home/tombh/Workspace/pygls/env/bin/python ENOENT, see screenshot.
  • I get ECONNREFUSED when launching the debug server.

image

@alcarney

Copy link
Copy Markdown
Collaborator Author
  • Would npm install --no-save be better so as not to modify the package-lock.json files?

Sure, didn't realise that was an option! :)

it doesn't say that the examples are at examples/servers/...

Good catch, I've added a note to the README.

  • I couldn't find Pygls > Client: Document Selector in the command pallete.
  • It wasn't immediately clear to me that "pygls.client.documentSelector" is in .vscode/settings.json.

Ah, I can see how that could be misleading, Pygls > Client: Document Selector was actually referring to a location in the Settings UI.
I've removed it in favour of "pygls.client.documentSelector" since you can't configure it via the UI anyway

  • How are the workspace files associated with the example servers? Eg
    how would I know how to play with workspace/table.txt?

The only way to know is to look at the table in examples/servers/README.md and see which file is listed in the "Works With" column...

  • I got an an error launching the Pygls server 🥺 Error: spawn /home/tombh/Workspace/pygls/env/bin/python ENOENT, see screenshot.

Looks like the extension chose the wrong working directory so Python wasn't finding the server...
Rather than have the extension try to "guess", I've included it in the default options in .vscode/settings.json. Hopefully that approach is more robust 🤞

  • I get ECONNREFUSED when launching the debug server.

Probably a side effect of it choosing the wrong working directory.

@alcarney alcarney force-pushed the local-extension branch 3 times, most recently from 0334f0b to 4da4112 Compare May 17, 2024 21:22
@tombh

tombh commented May 19, 2024

Copy link
Copy Markdown
Collaborator
  • Great updates to the README.

  • The only way to know is to look at the table in examples/servers/README.md and see which file is listed in the "Works With" column

    Oh, yes I didn't notice!

  • You were right about the working directory, but your fix didn't work for me. When I manually changed it to: "pygls.server.cwd": "/home/tombh/Workspace/pygls/examples/servers", everything worked 🎉

@alcarney

Copy link
Copy Markdown
Collaborator Author

You were right about the working directory, but your fix didn't work for me.

Interesting... was it completely broken? Or was the ${workspaceFolder} "variable" expanding to the wrong dir?

@tombh

tombh commented May 20, 2024

Copy link
Copy Markdown
Collaborator

Ah right, it appear it didn't expand it:
image

@alcarney

Copy link
Copy Markdown
Collaborator Author

To ask a potentially silly question 😅 .... did you restart VSCode after recompiling the extension? I don't think it's smart enough yet to detect changes to the extension after it's initially loaded.

@tombh

tombh commented May 24, 2024

Copy link
Copy Markdown
Collaborator

Ah no, so the extension needs recompiling after changing settings.json? Or just when the pygls.server.cwd field changes?

Either way, I ran npm run compile and restarted VSCode and still the ${workspaceFolder} doesn't get expanded.

@alcarney

Copy link
Copy Markdown
Collaborator Author

so the extension needs recompiling after changing settings.json?

No, the issue is that extensions (for some reason 🤷) don't get variables like ${workspaceFolder} for free, so the recompile was to pull in additional code changes from 5fe2e7c which add support for the ${workspaceFolder} variable.

I'm assuming, since you have the updated config that you also have the latest code? In which case I'm not sure why it's not working for you... 🤔

@tombh

tombh commented May 24, 2024

Copy link
Copy Markdown
Collaborator

Okay, I uninstalled the extension and reinstalled and ${workspaceFolder} was expanded 🥳 Niiice.

@alcarney alcarney merged commit 56a2624 into openlawlibrary:main May 24, 2024
@alcarney alcarney deleted the local-extension branch May 24, 2024 20:35
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 this pull request may close these issues.

2 participants