diff --git a/Cargo.toml b/Cargo.toml index 1fd543e..fe3fa29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zed_php" version = "0.5.0" -edition = "2021" +edition = "2024" publish = false license = "Apache-2.0" diff --git a/src/language_servers/intelephense.rs b/src/language_servers/intelephense.rs index c44738a..2c7ca9c 100644 --- a/src/language_servers/intelephense.rs +++ b/src/language_servers/intelephense.rs @@ -2,7 +2,7 @@ use std::{env, fs}; use zed::{CodeLabel, CodeLabelSpan}; use zed_extension_api::settings::LspSettings; -use zed_extension_api::{self as zed, serde_json, LanguageServerId, Result}; +use zed_extension_api::{self as zed, LanguageServerId, Result, serde_json}; const SERVER_PATH: &str = "node_modules/intelephense/lib/intelephense.js"; const PACKAGE_NAME: &str = "intelephense"; @@ -98,7 +98,7 @@ impl Intelephense { ) -> Result> { let settings = LspSettings::for_worktree("intelephense", worktree) .ok() - .and_then(|lsp_settings| lsp_settings.settings.clone()) + .and_then(|lsp_settings| lsp_settings.settings) .unwrap_or_default(); Ok(Some(serde_json::json!({ @@ -112,17 +112,17 @@ impl Intelephense { match completion.kind? { zed::lsp::CompletionKind::Method => { // __construct method doesn't have a detail - if let Some(ref detail) = completion.detail { - if detail.is_empty() { - return Some(CodeLabel { - spans: vec![ - CodeLabelSpan::literal(label, Some("function.method".to_string())), - CodeLabelSpan::literal("()", None), - ], - filter_range: (0..label.len()).into(), - code: completion.label, - }); - } + if let Some(ref detail) = completion.detail + && detail.is_empty() + { + return Some(CodeLabel { + spans: vec![ + CodeLabelSpan::literal(label, Some("function.method".to_string())), + CodeLabelSpan::literal("()", None), + ], + filter_range: (0..label.len()).into(), + code: completion.label, + }); } let mut parts = completion.detail.as_ref()?.split(":"); @@ -146,18 +146,18 @@ impl Intelephense { }) } zed::lsp::CompletionKind::Constant | zed::lsp::CompletionKind::EnumMember => { - if let Some(ref detail) = completion.detail { - if !detail.is_empty() { - return Some(CodeLabel { - spans: vec![ - CodeLabelSpan::literal(label, Some("constant".to_string())), - CodeLabelSpan::literal(" ", None), - CodeLabelSpan::literal(detail, Some("comment".to_string())), - ], - filter_range: (0..label.len()).into(), - code: completion.label, - }); - } + if let Some(ref detail) = completion.detail + && !detail.is_empty() + { + return Some(CodeLabel { + spans: vec![ + CodeLabelSpan::literal(label, Some("constant".to_string())), + CodeLabelSpan::literal(" ", None), + CodeLabelSpan::literal(detail, Some("comment".to_string())), + ], + filter_range: (0..label.len()).into(), + code: completion.label, + }); } Some(CodeLabel { diff --git a/src/language_servers/phpactor.rs b/src/language_servers/phpactor.rs index 3a57bdf..5d9c4d0 100644 --- a/src/language_servers/phpactor.rs +++ b/src/language_servers/phpactor.rs @@ -24,10 +24,10 @@ impl Phpactor { 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()); - } + if let Some(path) = &self.cached_binary_path + && fs::metadata(path).is_ok_and(|stat| stat.is_file()) + { + return Ok(path.clone()); } zed::set_language_server_installation_status( diff --git a/src/language_servers/phpantom.rs b/src/language_servers/phpantom.rs index 3157638..087c36e 100644 --- a/src/language_servers/phpantom.rs +++ b/src/language_servers/phpantom.rs @@ -29,14 +29,13 @@ impl Phpantom { if let Some(binary) = LspSettings::for_worktree("phpantom", worktree) .ok() .and_then(|settings| settings.binary) + && let Some(path) = binary.path { - if let Some(path) = binary.path { - return Ok(zed::Command { - command: path, - args: binary.arguments.unwrap_or_default(), - env: Default::default(), - }); - } + return Ok(zed::Command { + command: path, + args: binary.arguments.unwrap_or_default(), + env: Default::default(), + }); } Ok(zed::Command { @@ -55,10 +54,10 @@ impl Phpantom { 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()); - } + if let Some(path) = &self.cached_binary_path + && fs::metadata(path).is_ok_and(|stat| stat.is_file()) + { + return Ok(path.clone()); } zed::set_language_server_installation_status( diff --git a/src/language_servers/phptools.rs b/src/language_servers/phptools.rs index 2026333..697a2aa 100644 --- a/src/language_servers/phptools.rs +++ b/src/language_servers/phptools.rs @@ -1,7 +1,7 @@ use std::fs; use zed::{Architecture, Os}; use zed_extension_api::settings::LspSettings; -use zed_extension_api::{self as zed, serde_json, LanguageServerId, Result}; +use zed_extension_api::{self as zed, LanguageServerId, Result, serde_json}; const PACKAGE_NAME: &str = "devsense-php-ls"; @@ -118,7 +118,7 @@ impl PhpTools { ) -> Result> { let settings = LspSettings::for_worktree("phptools", worktree) .ok() - .and_then(|lsp_settings| lsp_settings.settings.clone()) + .and_then(|lsp_settings| lsp_settings.settings) .unwrap_or_default(); Ok(Some(serde_json::json!({ diff --git a/src/php.rs b/src/php.rs index f27a313..ef0f156 100644 --- a/src/php.rs +++ b/src/php.rs @@ -4,8 +4,8 @@ mod xdebug; use std::fs; use zed::CodeLabel; use zed_extension_api::{ - self as zed, serde_json, DebugConfig, DebugScenario, LanguageServerId, Result, - StartDebuggingRequestArgumentsRequest, + self as zed, DebugConfig, DebugScenario, LanguageServerId, Result, + StartDebuggingRequestArgumentsRequest, serde_json, }; use crate::{ @@ -100,15 +100,15 @@ impl zed::Extension for PhpExtension { language_server_id: &LanguageServerId, worktree: &zed::Worktree, ) -> Result> { - if language_server_id.as_ref() == PhpTools::LANGUAGE_SERVER_ID { - if let Some(phptools) = self.phptools.as_mut() { - return phptools.language_server_workspace_configuration(worktree); - } + if language_server_id.as_ref() == PhpTools::LANGUAGE_SERVER_ID + && let Some(phptools) = self.phptools.as_mut() + { + return phptools.language_server_workspace_configuration(worktree); } - if language_server_id.as_ref() == Intelephense::LANGUAGE_SERVER_ID { - if let Some(intelephense) = self.intelephense.as_mut() { - return intelephense.language_server_workspace_configuration(worktree); - } + if language_server_id.as_ref() == Intelephense::LANGUAGE_SERVER_ID + && let Some(intelephense) = self.intelephense.as_mut() + { + return intelephense.language_server_workspace_configuration(worktree); } Ok(None) @@ -143,7 +143,8 @@ impl zed::Extension for PhpExtension { if config.adapter != XDebug::NAME { return Err(format!( "PHP extension does not support unknown adapter in `dap_config_to_scenario`: {} (supported: [{}])", - config.adapter, XDebug::NAME + config.adapter, + XDebug::NAME )); } self.xdebug.dap_config_to_scenario(config) @@ -158,7 +159,8 @@ impl zed::Extension for PhpExtension { if config.adapter != XDebug::NAME { return Err(format!( "PHP extension does not support unknown adapter in `get_dap_binary`: {} (supported: [{}])", - adapter_name, XDebug::NAME + adapter_name, + XDebug::NAME )); } self.xdebug diff --git a/src/xdebug.rs b/src/xdebug.rs index 8b60a1b..94553b1 100644 --- a/src/xdebug.rs +++ b/src/xdebug.rs @@ -1,11 +1,11 @@ use std::{env, path::Path, str::FromStr, sync::OnceLock}; use zed_extension_api::{ - download_file, latest_github_release, node_binary_path, resolve_tcp_template, - serde_json::{self, json, Value}, DebugAdapterBinary, DebugConfig, DebugRequest, DebugScenario, DownloadedFileType, GithubReleaseAsset, GithubReleaseOptions, StartDebuggingRequestArguments, - StartDebuggingRequestArgumentsRequest, TcpArguments, TcpArgumentsTemplate, + StartDebuggingRequestArgumentsRequest, TcpArguments, TcpArgumentsTemplate, download_file, + latest_github_release, node_binary_path, resolve_tcp_template, + serde_json::{self, Value, json}, }; pub(super) struct XDebug {