-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat: add Zed extension and make language server editor-agnostic #125
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
Open
withxat
wants to merge
27
commits into
npmx-dev:main
Choose a base branch
from
withxat:feat/zed-extension
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e6b8b2d
refactor(language-core): add package manager fallback detection
withxat c9e210b
refactor(language-service): support nested config fallbacks
withxat 41d29a8
feat(zed): add dev extension launcher
withxat 8baf11f
refactor(language-service): preserve editor-specific ux
withxat e922aaa
refactor(workspace): adopt package-manager-detector fallback
withxat a4ef65d
refactor(language-server): unify package manager detection
withxat 3601a47
chore(language-server): align detector dependency placement
withxat bd342c7
refactor(language-server): use client feature flags
withxat 5723821
fix(language-service): use unicode hover icons outside vscode
withxat fea3872
refactor(language-service): rename markdown icons option
withxat 2fe4301
style(language-service): use emoji hover icons
withxat e94126d
refactor(language-service): simplify config lookup
withxat 07e5986
docs: update zed extension readmes
withxat fc8da4e
feat: polish the implementation
withxat eaae9c3
chore(zed): mark extension crate private
withxat a4311c0
feat(zed): pass client feature initialization options
withxat 91eebca
fix(language-server): use detector subpath import
withxat 8e6b4eb
fix(language-service): remove duplicate inlay hint spacing
withxat b53f855
feat: sync version with vscode extension
withxat c751f50
ci(workflows): add zed release workflows
withxat aaca028
ci(release): sync zed versions during bump
withxat 9fe8e0c
chore(zed): align version and add license
withxat 5ae5306
ci(workflows): simplify release triggers
withxat 4e5451d
docs(workflows): clarify zed publish TODOs
withxat 055fd84
ci(test): reuse built lsp packages
withxat df9afd9
chore: merge upstream main
withxat 3b31530
ci(release): restore vscode tag trigger
withxat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| /target | ||
| /extension.wasm | ||
| /Cargo.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [package] | ||
| name = "zed-npmx" | ||
| version = "0.0.1" | ||
| edition = "2021" | ||
| license = "MIT" | ||
|
|
||
| [lib] | ||
| crate-type = [ "cdylib" ] | ||
|
|
||
| [dependencies] | ||
| serde_json = "1" | ||
| zed_extension_api = "0.7.0" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # npmx for Zed | ||
|
|
||
| This is the in-repo Zed extension for `npmx`. It runs the shared `npmx-language-server` | ||
| over stdio, so Zed gets the same core package intelligence used by the VS Code extension. | ||
|
|
||
| ## Status | ||
|
|
||
| - Uses the shared `npmx-language-server` | ||
| - Targets local development from this monorepo first | ||
| - Defaults to `packages/language-server/dist/index.cjs` | ||
| - Launches the language server over `--stdio` | ||
| - Supports overriding the launched command through Zed `lsp.npmx.binary` settings | ||
| - Forwards `lsp.npmx.settings` to the language server as `npmx` workspace configuration | ||
|
|
||
| ## Features | ||
|
|
||
| - Hover links to package pages and docs on [npmx.dev](https://npmx.dev) | ||
| - Emoji hover icons for non-VS Code editors | ||
| - Version completion with provenance and prerelease settings | ||
| - Diagnostics for upgrades, deprecations, replacements, vulnerabilities, dist tags, and engine mismatches | ||
| - Document links for package names | ||
| - Workspace-aware dependency resolution for npm, pnpm, yarn, and bun projects | ||
|
|
||
| ## Local Development | ||
|
|
||
| 1. Build the language server from the repo root with `pnpm build`. | ||
| 2. In Zed, install `extensions/zed` as a dev extension. | ||
| 3. If you want a custom launch command, configure `lsp.npmx.binary` in your Zed settings. | ||
|
|
||
| ## Settings | ||
|
|
||
| Zed settings under `lsp.npmx.settings` are forwarded directly to the language server. | ||
| Use scoped npmx settings without the leading `npmx.` prefix: | ||
|
|
||
| ```json | ||
| { | ||
| "lsp": { | ||
| "npmx": { | ||
| "settings": { | ||
| "hover": { | ||
| "enabled": true | ||
| }, | ||
| "completion": { | ||
| "version": "provenance-only", | ||
| "excludePrerelease": true | ||
| }, | ||
| "diagnostics": { | ||
| "upgrade": true, | ||
| "deprecation": true, | ||
| "replacement": true, | ||
| "vulnerability": true, | ||
| "distTag": true, | ||
| "engineMismatch": true | ||
| }, | ||
| "packageLinks": "declared" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| To override the launched language server command: | ||
|
|
||
| ```json | ||
| { | ||
| "lsp": { | ||
| "npmx": { | ||
| "binary": { | ||
| "path": "node", | ||
| "arguments": [ | ||
| "/absolute/path/to/vscode-npmx/packages/language-server/dist/index.cjs", | ||
| "--stdio" | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| - Zed dev extensions require Rust installed via `rustup`; the Zed docs explicitly call out that Homebrew Rust will not work for dev extension compilation. | ||
| - This dev extension expects the repo-local language server bundle at `packages/language-server/dist/index.cjs`, so build the monorepo before installing it in Zed. | ||
| - If you override `lsp.npmx.binary`, make sure the launched server process still receives an LSP transport argument such as `--stdio`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| id = "npmx" | ||
| name = "npmx" | ||
| description = "npmx language support for Zed" | ||
| version = "0.0.1" | ||
| schema_version = 1 | ||
| authors = [ "Xat <i@xat.sh>" ] | ||
| repository = "https://github.com/npmx-dev/vscode-npmx/tree/main/extensions/zed" | ||
|
|
||
| [language_servers.npmx] | ||
| name = "npmx" | ||
| languages = [ | ||
| "JSON", | ||
| "YAML", | ||
| "JavaScript", | ||
| "JSX", | ||
| "TypeScript", | ||
| "TSX", | ||
| "HTML", | ||
| "Vue", | ||
| "Astro", | ||
| "Svelte" | ||
| ] | ||
|
|
||
| [language_servers.npmx.language_ids] | ||
| JSON = "json" | ||
| YAML = "yaml" | ||
| JavaScript = "javascript" | ||
| JSX = "javascriptreact" | ||
| TypeScript = "typescript" | ||
| TSX = "typescriptreact" | ||
| HTML = "html" | ||
| Vue = "vue" | ||
| Astro = "astro" | ||
| Svelte = "svelte" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| use zed_extension_api::{self as zed, serde_json, settings::LspSettings, LanguageServerId}; | ||
|
|
||
| struct NpmxExtension; | ||
|
|
||
| impl NpmxExtension { | ||
| fn language_server_settings( | ||
| language_server_id: &LanguageServerId, | ||
| worktree: &zed::Worktree, | ||
| ) -> LspSettings { | ||
| LspSettings::for_worktree(language_server_id.as_ref(), worktree) | ||
| .ok() | ||
| .unwrap_or_default() | ||
| } | ||
|
|
||
| fn default_server_script() -> String { | ||
| format!( | ||
| "{}/../../packages/language-server/dist/index.cjs", | ||
| env!("CARGO_MANIFEST_DIR") | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| impl zed::Extension for NpmxExtension { | ||
| fn new() -> Self { | ||
| Self | ||
| } | ||
|
|
||
| fn language_server_command( | ||
| &mut self, | ||
| language_server_id: &LanguageServerId, | ||
| worktree: &zed::Worktree, | ||
| ) -> zed::Result<zed::Command> { | ||
| let lsp_settings = Self::language_server_settings(language_server_id, worktree); | ||
| if let Some(binary) = lsp_settings.binary { | ||
| let command = match binary.path { | ||
| Some(path) => path, | ||
| None => zed::node_binary_path()?, | ||
| }; | ||
| let args = binary.arguments.unwrap_or_default(); | ||
| let env = worktree | ||
| .shell_env() | ||
| .into_iter() | ||
| .chain(binary.env.unwrap_or_default()) | ||
| .collect(); | ||
|
|
||
| return Ok(zed::Command { command, args, env }); | ||
| } | ||
|
|
||
| Ok(zed::Command { | ||
| command: zed::node_binary_path()?, | ||
| args: vec![Self::default_server_script(), String::from("--stdio")], | ||
| env: worktree.shell_env().into_iter().collect(), | ||
| }) | ||
| } | ||
|
|
||
| fn language_server_workspace_configuration( | ||
| &mut self, | ||
| language_server_id: &LanguageServerId, | ||
| worktree: &zed::Worktree, | ||
| ) -> zed::Result<Option<serde_json::Value>> { | ||
| let settings = Self::language_server_settings(language_server_id, worktree); | ||
| let workspace_settings = settings.settings.unwrap_or_default(); | ||
|
|
||
| Ok(Some(serde_json::json!({ | ||
| "npmx": workspace_settings | ||
| }))) | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| zed::register_extension!(NpmxExtension); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.