pub(crate) mod add_iterable_type;
mod add_override;
pub(crate) mod add_return_type_will_change;
pub(crate) mod add_throws;
pub(crate) mod fix_phpdoc_type;
pub(crate) mod fix_prefixed_class;
pub(crate) mod fix_return_type;
mod ignore;
pub(crate) mod new_static;
pub(crate) mod remove_assert;
pub(crate) mod remove_override;
mod remove_throws;
pub(crate) mod remove_unreachable;
pub(crate) mod remove_unused_return_type;
use tower_lsp::lsp_types::*;
use crate::Backend;
pub(crate) fn split_phpstan_tip(message: &str) -> (&str, Option<&str>) {
match message.split_once('\n') {
Some((msg, tip)) => (msg, Some(tip)),
None => (message, None),
}
}
impl Backend {
pub(crate) fn collect_phpstan_actions(
&self,
uri: &str,
content: &str,
params: &CodeActionParams,
out: &mut Vec<CodeActionOrCommand>,
) {
self.collect_phpstan_ignore_actions(uri, content, params, out);
self.collect_add_throws_actions(uri, content, params, out);
self.collect_remove_throws_actions(uri, content, params, out);
self.collect_add_override_actions(uri, content, params, out);
self.collect_remove_override_actions(uri, content, params, out);
self.collect_add_return_type_will_change_actions(uri, content, params, out);
self.collect_new_static_actions(uri, content, params, out);
self.collect_fix_phpdoc_type_actions(uri, content, params, out);
self.collect_fix_prefixed_class_actions(uri, content, params, out);
self.collect_remove_assert_actions(uri, content, params, out);
self.collect_fix_return_type_actions(uri, content, params, out);
self.collect_remove_unused_return_type_actions(uri, content, params, out);
self.collect_add_iterable_type_actions(uri, content, params, out);
self.collect_remove_unreachable_actions(uri, content, params, out);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn splits_message_with_tip() {
let (msg, tip) = split_phpstan_tip("Some error.\nUse #[Override] to fix.");
assert_eq!(msg, "Some error.");
assert_eq!(tip, Some("Use #[Override] to fix."));
}
#[test]
fn returns_none_when_no_tip() {
let (msg, tip) = split_phpstan_tip("Some error.");
assert_eq!(msg, "Some error.");
assert_eq!(tip, None);
}
#[test]
fn empty_tip_after_newline() {
let (msg, tip) = split_phpstan_tip("Some error.\n");
assert_eq!(msg, "Some error.");
assert_eq!(tip, Some(""));
}
}