-
Notifications
You must be signed in to change notification settings - Fork 30
Add PHPantom language server #128
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
Merged
MrSubidubi
merged 4 commits into
zed-extensions:main
from
roxblnfk:add-phpantom-language-server
Jul 20, 2026
+155
−1
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| mod intelephense; | ||
| mod phpactor; | ||
| mod phpantom; | ||
| mod phptools; | ||
|
|
||
| pub use intelephense::*; | ||
| pub use phpactor::*; | ||
| pub use phpantom::*; | ||
| pub use phptools::*; |
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,140 @@ | ||
| use std::fs; | ||
|
|
||
| use zed_extension_api::settings::LspSettings; | ||
| use zed_extension_api::{self as zed, LanguageServerId, Result}; | ||
|
|
||
| const REPO: &str = "AJenbo/phpantom_lsp"; | ||
| const BINARY_NAME: &str = "phpantom_lsp"; | ||
|
|
||
| pub struct Phpantom { | ||
| cached_binary_path: Option<String>, | ||
| } | ||
|
|
||
| impl Phpantom { | ||
| pub const LANGUAGE_SERVER_ID: &'static str = "phpantom"; | ||
|
|
||
| pub fn new() -> Self { | ||
| Self { | ||
| cached_binary_path: None, | ||
| } | ||
| } | ||
|
|
||
| pub fn language_server_command( | ||
| &mut self, | ||
| language_server_id: &LanguageServerId, | ||
| worktree: &zed::Worktree, | ||
| ) -> Result<zed::Command> { | ||
| // Allow users to point at their own build via | ||
| // `lsp.phpantom.binary.{path,arguments}` in the settings. | ||
| if let Some(binary) = LspSettings::for_worktree("phpantom", worktree) | ||
| .ok() | ||
| .and_then(|settings| settings.binary) | ||
| { | ||
| if let Some(path) = binary.path { | ||
| return Ok(zed::Command { | ||
| command: path, | ||
| args: binary.arguments.unwrap_or_default(), | ||
| env: Default::default(), | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| Ok(zed::Command { | ||
| command: self.language_server_binary_path(language_server_id, worktree)?, | ||
| args: vec![], | ||
| env: Default::default(), | ||
| }) | ||
| } | ||
|
|
||
| fn language_server_binary_path( | ||
| &mut self, | ||
| language_server_id: &LanguageServerId, | ||
| worktree: &zed::Worktree, | ||
| ) -> Result<String> { | ||
| if let Some(path) = worktree.which(BINARY_NAME) { | ||
| return Ok(path); | ||
| } | ||
|
|
||
| if let Some(path) = &self.cached_binary_path { | ||
| if fs::metadata(path).is_ok_and(|stat| stat.is_file()) { | ||
| return Ok(path.clone()); | ||
| } | ||
| } | ||
|
|
||
| zed::set_language_server_installation_status( | ||
| language_server_id, | ||
| &zed::LanguageServerInstallationStatus::CheckingForUpdate, | ||
| ); | ||
| let release = zed::latest_github_release( | ||
| REPO, | ||
| zed::GithubReleaseOptions { | ||
| require_assets: true, | ||
| pre_release: false, | ||
| }, | ||
| )?; | ||
|
|
||
| let (platform, arch) = zed::current_platform(); | ||
|
|
||
| let (os_str, ext) = match platform { | ||
| zed::Os::Mac => ("apple-darwin", "tar.gz"), | ||
| zed::Os::Linux => ("unknown-linux-gnu", "tar.gz"), | ||
| zed::Os::Windows => ("pc-windows-msvc", "zip"), | ||
| }; | ||
|
|
||
| let arch_str = match arch { | ||
| zed::Architecture::Aarch64 => "aarch64", | ||
| zed::Architecture::X8664 => "x86_64", | ||
| _ => return Err(format!("unsupported architecture: {arch:?}")), | ||
| }; | ||
|
|
||
| let asset_name = format!("{BINARY_NAME}-{arch_str}-{os_str}.{ext}"); | ||
| let asset = release | ||
| .assets | ||
| .iter() | ||
| .find(|asset| asset.name == asset_name) | ||
| .ok_or_else(|| { | ||
| format!( | ||
| "no release asset found matching {asset_name:?} — you may need to build \ | ||
| {BINARY_NAME} from source for your platform" | ||
| ) | ||
| })?; | ||
|
|
||
| let version_dir = format!("{BINARY_NAME}-{}", release.version); | ||
| fs::create_dir_all(&version_dir).map_err(|e| format!("failed to create directory: {e}"))?; | ||
|
|
||
| let binary_path = match platform { | ||
| zed::Os::Windows => format!("{version_dir}/{BINARY_NAME}.exe"), | ||
| _ => format!("{version_dir}/{BINARY_NAME}"), | ||
| }; | ||
|
|
||
| if !fs::metadata(&binary_path).is_ok_and(|stat| stat.is_file()) { | ||
| zed::set_language_server_installation_status( | ||
| language_server_id, | ||
| &zed::LanguageServerInstallationStatus::Downloading, | ||
| ); | ||
|
|
||
| let file_type = match ext { | ||
| "tar.gz" => zed::DownloadedFileType::GzipTar, | ||
| "zip" => zed::DownloadedFileType::Zip, | ||
| _ => unreachable!(), | ||
| }; | ||
|
|
||
| zed::download_file(&asset.download_url, &version_dir, file_type) | ||
| .map_err(|e| format!("failed to download file: {e}"))?; | ||
|
|
||
| zed::make_file_executable(&binary_path)?; | ||
|
|
||
| let entries = | ||
| fs::read_dir(".").map_err(|e| format!("failed to list working directory: {e}"))?; | ||
| for entry in entries { | ||
| let entry = entry.map_err(|e| format!("failed to load directory entry: {e}"))?; | ||
| if entry.file_name().to_str() != Some(&version_dir) { | ||
| fs::remove_dir_all(entry.path()).ok(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| self.cached_binary_path = Some(binary_path.clone()); | ||
| Ok(binary_path) | ||
| } | ||
| } | ||
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
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.