MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / resolve_strategy

Function resolve_strategy

src/formatting.rs:99–185  ·  view source on GitHub ↗

Resolve the formatting strategy from config, Composer metadata, and the workspace root. Resolution rules: - If `config.is_disabled()` (both tools set to `""`) → `Disabled`. - If either tool has an explicit non-empty path in config → `External` with those tools. - If `composer_json` has `friendsofphp/php-cs-fixer` or `squizlabs/php_codesniffer` in `require-dev` → `External`, resolving paths via th

(
    workspace_root: Option<&Path>,
    config: &FormattingConfig,
    composer_json: Option<&crate::composer::ComposerPackage>,
    bin_dir: Option<&str>,
)

Source from the content-addressed store, hash-verified

97/// resolving paths via the Composer bin-dir.
98/// - Otherwise → `BuiltIn`.
99pub(crate) fn resolve_strategy(
100 workspace_root: Option<&Path>,
101 config: &FormattingConfig,
102 composer_json: Option<&crate::composer::ComposerPackage>,
103 bin_dir: Option<&str>,
104) -> FormattingStrategy {
105 if config.is_disabled() {
106 return FormattingStrategy::Disabled;
107 }
108
109 // Check for explicit config overrides first.
110 let fixer_explicit = matches!(config.php_cs_fixer.as_deref(), Some(s) if !s.is_empty());
111 let phpcbf_explicit = matches!(config.phpcbf.as_deref(), Some(s) if !s.is_empty());
112 let pint_explicit = matches!(config.pint.as_deref(), Some(s) if !s.is_empty());
113
114 if fixer_explicit || phpcbf_explicit || pint_explicit {
115 let mut tools = Vec::new();
116 if let Some(cmd) = config.pint.as_deref()
117 && !cmd.is_empty()
118 {
119 tools.push(ResolvedTool {
120 name: "pint",
121 path: PathBuf::from(cmd),
122 });
123 }
124 if let Some(cmd) = config.php_cs_fixer.as_deref()
125 && !cmd.is_empty()
126 {
127 tools.push(ResolvedTool {
128 name: "php-cs-fixer",
129 path: PathBuf::from(cmd),
130 });
131 }
132 if let Some(cmd) = config.phpcbf.as_deref()
133 && !cmd.is_empty()
134 {
135 tools.push(ResolvedTool {
136 name: "phpcbf",
137 path: PathBuf::from(cmd),
138 });
139 }
140 if tools.is_empty() {
141 return FormattingStrategy::Disabled;
142 }
143 return FormattingStrategy::External(tools);
144 }
145
146 // No explicit config — check composer.json require-dev.
147 if let Some(package) = composer_json {
148 let mut tools = Vec::new();
149 let bin = bin_dir.unwrap_or("vendor/bin");
150
151 // Only one of the config values can be Some("") here (disabling
152 // one tool while leaving the other to auto-detect).
153 let fixer_disabled = config.php_cs_fixer.as_deref() == Some("");
154 let phpcbf_disabled = config.phpcbf.as_deref() == Some("");
155 let pint_disabled = config.pint.as_deref() == Some("");
156

Calls 5

has_require_devFunction · 0.85
resolve_from_bin_dirFunction · 0.85
is_disabledMethod · 0.80
pushMethod · 0.80
is_emptyMethod · 0.45