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

Tracking Issue: Language Extensions #7096

Closed
19 of 20 tasks
maxbrunsfeld opened this issue Jan 30, 2024 · 11 comments
Closed
19 of 20 tasks

Tracking Issue: Language Extensions #7096

maxbrunsfeld opened this issue Jan 30, 2024 · 11 comments
Assignees
Labels
ignore top-ranking issues [ignored label] language An umbrella label for all programming languages syntax behaviors tracking Issue that tracks a group of related issues

Comments

@maxbrunsfeld
Copy link
Collaborator

maxbrunsfeld commented Jan 30, 2024

Problem

Right now, all of the languages that Zed supports are bundled into the binary. This means that users cannot add support for their own languages. It also means that the more languages Zed supports, the longer our compile time becomes.

Proposed Plan

Zed's first form of user-installed extensions will be language extensions. These plugins will have a directory structure similar to the per-language folders in Zed's current languages folder. In addition to the TOML config, and the query files, they will also contain a WASM build of the Tree-sitter parser.

In order to promote sharing of plugins, we'll create a new GitHub repository in the Zed organization that contains some directory of all known plugins. We'll add functionality to zed.dev so that when editing an unsupported language, Zed will be able to query for any known plugins that add support for that file extensions, and automatically download and install them.

Steps

Tree-sitter

  • Enhance the Tree-sitter library to support loading Wasm files (tree-sitter#1864, tree-sitter#2840)
  • Improve tooling for compiling Tree-sitter parsers to WASM (tree-sitter#2897)
    • Indicate when external scanners are using unsupported libc functions
    • Add any additional libc functions needed by external scanners in community parsers
  • Land upstream wasmtime changes, so that we can publish a new Tree-sitter CLI to crates.io, and people can easily use the new WASM build tooling (wasmtime#7837, wasmtime#7872)

Zed Extension Support

Convenient Extension Installation

  • Create an extensions repository to which we can add submodules, in order to automatically package community extensions and provide them to Zed.
  • Add a zed.dev API for searching extensions by name
  • Add an extension installation view to Zed (Add an extensions installation view #7689)
  • One by one, verify that all of these languages successfully build and load via the wasm system
  • Add a zed.dev API that searches extensions by file extensions
  • Add logic for automatically searching for extensions when editing files with unsupported extensions

Language Server Extensions

@maxbrunsfeld maxbrunsfeld self-assigned this Jan 30, 2024
@JosephTLyons JosephTLyons added meta language An umbrella label for all programming languages syntax behaviors labels Jan 30, 2024
@mikayla-maki mikayla-maki added the tracking Issue that tracks a group of related issues label Jan 30, 2024
@mikayla-maki mikayla-maki pinned this issue Jan 30, 2024
maxbrunsfeld added a commit that referenced this issue Jan 31, 2024
Part of #7096

* [x] Load all queries for language plugins, not just highlight query
* [x] Auto-reload languages when changing the `plugins` directory
* [x] Bump Tree-sitter for language loading and unloading fixes
* [x] Figure out code signing

Release Notes:

- N/A

---------

Co-authored-by: Antonio <antonio@zed.dev>
Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
@foxkdev
Copy link
Contributor

foxkdev commented Feb 8, 2024

@maxbrunsfeld what are difference between plugins and extensions?

Other Question, this topic:

  • Add logic in Zed to automatically download and install these extensions
    Design included? Same VSCODE but with Zed Style?
    Captura de pantalla 2024-02-08 a las 9 07 47

Can I try to implement this? Im know we need API definition but I can fake and when have API, we modify definition.
Im assume API will have this similar structure:

{
    "extensions": [
        {
            "name": "Test-Extension",
            "repostiory": "https://github.com/zed/extension/test-extension",
            "version": "1.0.0",
            "description": "This is a test extension",
            "author": "Zed"
        }
    ]
}

Give me feedback and if you want I can try to implement.

@chiddekel chiddekel mentioned this issue Feb 8, 2024
12 tasks
@maxbrunsfeld
Copy link
Collaborator Author

@foxkdev My plan is to start with the backend part of this API. We'll be adding REST APIs to zed.dev for this. I'm not sure exactly how the API will look, and we're going to be making changes rapidly, but you are welcome to take a shot at.

In general, we'll be working in the language extensions channel in Zed. You're welcome to join.

maxdeviant added a commit that referenced this issue Feb 13, 2024
This PR adds a view for installing extensions within Zed.

My subtasks:

- [X] Page Extensions and assign in App Menu
- [X] List extensions 
- [X] Button to Install/Uninstall
- [x] Search Input to search in extensions registry API
- [x] Get Extensions from API
- [x] Action install to download extension and copy in /extensions
folder
- [x] Action uninstall to remove from /extensions folder
- [x] Filtering
- [x] Better UI Design

Open to collab!

Release Notes:

- Added an extension installation view. Open it using the `zed:
extensions` action in the command palette
([#7096](#7096)).

---------

Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
Co-authored-by: Marshall <marshall@zed.dev>
Co-authored-by: Carlos <foxkdev@gmail.com>
Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
Co-authored-by: Max <max@zed.dev>
@claytonrcarter
Copy link
Contributor

I was just playing w/ creating an extension for Laravel Blade files. It went OK following the example at https://github.com/zed-extensions/nu and also the stuff in https://github.com/zed-industries/zed/tree/main/crates/zed/src/languages. I did get it working, at least to the extent that that tree-sitter parser allowed, but I have a few quick comments:

  • debug output was non-existent in the log, which made it hard to figure out what I was doing wrong when things weren't working
    • in my case, I had a few things (wrong filename for the wasm blob, various small issues w/ the injections and highlights files) that I was surpised didn't cause any error/warnings in the logs
  • it's not clear how to tell the editor that one language should "beat" another, or how to disambiguate file extensions
    • in the case of Blade, the extension is .blade.php, and Zed is treating such files as PHP (which makes sense), and it wasn't clear how to tell it other wise
    • selecting "Laravel Blade" in the language selector works fine, and using a bogus but non-conflicting extension will also work fine
  • prettier support ... I see how to configure the prettier parser in the toml, but it looks like the only way to define which prettier plugin to load is in a Rust file
    • Example w/ Svelte: parser in toml and plugin in Rust
    • maybe this will come w/ LSP support in extensions, but – at least for something like Blade – there are a few prettier plugins, but LSPs not so much

Thank you! It was fun playing with this and getting it set up.

@brookback
Copy link

Seconded on Clayton's comment above regarding debug logs. I'm trying — for fun — to add support for SQL grammar (based on https://github.com/DerekStride/tree-sitter-sql), but I can't for my life get it to work 😄

I've mimicked a bunch of existing Zed language extensions, but it's very hard without any logs telling me why it's not working properly. The repo: https://github.com/johanbrook/zed-sql

My woes

"SQL" shows up in the language selector when I bring it up manually, but it's not:

  • associating my SQL language with .sql files automatically, even though I've configured it to.
  • picking up any syntax highlighting or grammar. I might've messed up the WASM generation part locally, but who knows 🔮

@joshrutkowski
Copy link

What work is remaining to support language servers via extensions? I see my PR #8384 was closed in favor of this ongoing work - looking at where I can help out 😄

@jianghoy
Copy link

For anyone who's late to the party, right now the language folder is this: https://github.com/zed-industries/zed/tree/main/crates/languages/src (correct me if I'm wrong)

@jianghoy
Copy link

I was just playing w/ creating an extension for Laravel Blade files. It went OK following the example at https://github.com/zed-extensions/nu and also the stuff in https://github.com/zed-industries/zed/tree/main/crates/zed/src/languages. I did get it working, at least to the extent that that tree-sitter parser allowed, but I have a few quick comments:

  • debug output was non-existent in the log, which made it hard to figure out what I was doing wrong when things weren't working

    • in my case, I had a few things (wrong filename for the wasm blob, various small issues w/ the injections and highlights files) that I was surpised didn't cause any error/warnings in the logs
  • it's not clear how to tell the editor that one language should "beat" another, or how to disambiguate file extensions

    • in the case of Blade, the extension is .blade.php, and Zed is treating such files as PHP (which makes sense), and it wasn't clear how to tell it other wise
    • selecting "Laravel Blade" in the language selector works fine, and using a bogus but non-conflicting extension will also work fine
  • prettier support ... I see how to configure the prettier parser in the toml, but it looks like the only way to define which prettier plugin to load is in a Rust file

    • Example w/ Svelte: parser in toml and plugin in Rust
    • maybe this will come w/ LSP support in extensions, but – at least for something like Blade – there are a few prettier plugins, but LSPs not so much

Thank you! It was fun playing with this and getting it set up.

Based on my findings in the above issue, I believe today Zed doesn't reconcile multiple language matches. I propose simply reconciling using the length of longest longest-matched suffix of each language extension.

@MrTact MrTact mentioned this issue Mar 13, 2024
1 task
ConradIrwin added a commit that referenced this issue Mar 19, 2024
Follow-up from #9138

Release Notes:

- Adds suggested extensions for some filetypes
([#7096](#7096)).

---------

Co-authored-by: Felix Zeller <felixazeller@gmail.com>
@Feel-ix-343
Copy link
Contributor

Note for linux users: Make sure you have a xdg FileChooser, else add dev extension will not work. Hyprland does not have a file chooser in xdg-desktop-portal; you must install one.

Also, this error is not too apparent and I needed to modify the source code to log it. Zed should log errors like this? relevant is linux/platform.rs ~line 230

pjlast pushed a commit to pjlast/zed that referenced this issue Mar 26, 2024
Follow-up from zed-industries#9138

Release Notes:

- Adds suggested extensions for some filetypes
([zed-industries#7096](zed-industries#7096)).

---------

Co-authored-by: Felix Zeller <felixazeller@gmail.com>
@maxbrunsfeld
Copy link
Collaborator Author

Language extensions work now.

@maxbrunsfeld maxbrunsfeld unpinned this issue Apr 18, 2024
@gopeter
Copy link

gopeter commented Apr 23, 2024

Before opening a new issue: does Zed support multiple LSPs at once for one language? I came across that TypeScript autocompletion does not work when using the Biome extension: biomejs/biome-zed#10

@maxdeviant
Copy link
Member

Before opening a new issue: does Zed support multiple LSPs at once for one language? I came across that TypeScript autocompletion does not work when using the Biome extension: biomejs/biome-zed#10

There are currently some issues when there are two language servers running for a given language.

I'm looking to address that with #10906.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ignore top-ranking issues [ignored label] language An umbrella label for all programming languages syntax behaviors tracking Issue that tracks a group of related issues
Projects
None yet
Development

No branches or pull requests