71 / vscode-tree-sitter-api

Exposing Tree Sitter parsers and queries to VS Code extensions (with caching & more utilities).
Mozilla Public License 2.0
14 stars 2 forks source link

Convert to web extension? #3

Closed haberdashPI closed 1 month ago

haberdashPI commented 1 month ago

Having played around with this for a little bit, something I've noticed in trying to get this to play nicely with one of my extensions is it appears to be pretty non-trivial to convert this to a web extension (and as best I can tell, if I want to get the API object from another web extension, this extension would have to also be a web extension).

Since you set up the build process here, I thought it might be possible you know how one might go about doing that. The obvious things I tried seemed to fail: happy to give more details about what I tried if you think it'd be helpful.

A longer-term problem here seems to be that depending on where an extension resides (e.g. vscode local or remote machine), and whether it is a web or desktop extension, impacts what other extensions it can access when calling getExtension. Seems like there would need to be e.g. an vscode-tree-sitter-api-desktop and vscode-tree-sitter-api-web extension.

71 commented 1 month ago

The extension only uses builtin VS Code APIs so it should directly work in the browser.

I haven't tried building it to .vsix (as I'm not sure how to test these in the browser without publishing them to the marketplace), but I can get it working locally:

  1. Add the following to package.json:

     "main": "./out/extension.js",
    + "browser": "./out/extension.js",
  2. Serve the extension:

    $ deno run -A npm:serve -l 5001 --cors`.
  3. Visit vscode.dev, run Developer: Install Extension from Location..., and enter http://localhost:5001.

At this point I can directly run Tree Sitter: Inspect Scopes to make sure that the extension works (which requires being in a supported file, like a JS file), or better yet I can use it through Dance by adding the following snippet to the user configuration:

    "dance.menus": {
        "object": {
            "items": {
                "f": {
                    "text": "function",
                    "command": "dance.seek.object",
                    "args": [{
                          "input": "(?#textobject=function)"
                    }],
                }
            }
        }
    }

Then pressing a-i f in a function.

The instructions above also work when replacing vscode.dev with the test app served with

$ deno run -A npm:@vscode/test-web --extensionDevelopmentPath=.

Note that you may need to reload the window after installing the extension in case Dance doesn't pick up on it being available, or if it somehow doesn't load.

haberdashPI commented 1 month ago

Mmm... okay. Thanks for the tips. I'll keep puttering away at this.

Having eliminated the differences in extension type, there were some other issues I eventually found with my setup, so it's possible that now that I have those resolved this problem will be easier to fix. (But I think I'll first get what I have working without the web vs. desktop issues).

haberdashPI commented 1 month ago

I'll close for now, and if I find a more specific/precise issue and/or MWE I'll post again.