Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
749 changes: 230 additions & 519 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ serde_json = "1.0"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tokio = { version = "1.39", features = ["full"] }
mago-syntax = "=1.29.0"
mago-database = "=1.29.0"
mago-docblock = "=1.29.0"
mago-names = "=1.29.0"
mago-span = "=1.29.0"
mago-type-syntax = "=1.29.0"
mago-formatter = "=1.29.0"
mago-php-version = "=1.29.0"
mago-composer = "=1.29.0"
bumpalo = "3"
mago-syntax = "=1.43.0"
mago-allocator = "=1.43.0"
mago-database = "=1.43.0"
mago-docblock = "=1.42.0"
mago-names = "=1.43.0"
mago-span = "=1.43.0"
mago-type-syntax = "=1.42.0"
mago-formatter = "=1.43.0"
mago-php-version = "=1.43.0"
mago-composer = "=1.43.0"
ignore = "0.4"
globset = "0.4"
regex = "1"
Expand Down
2 changes: 1 addition & 1 deletion src/call_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! This module is the single place that encodes PHP's binding rules so the
//! various consumers stay consistent.

use mago_syntax::ast::{Argument, ArgumentList, Expression};
use mago_syntax::cst::{Argument, ArgumentList, Expression};

use crate::atom::bytes_to_str;
use crate::types::ParameterInfo;
Expand Down
10 changes: 5 additions & 5 deletions src/code_actions/change_visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ use std::collections::HashMap;
use std::sync::Arc;

#[cfg(test)]
use bumpalo::Bump;
use mago_allocator::LocalArena;
use mago_span::HasSpan;
use mago_syntax::ast::class_like::property::Property;
use mago_syntax::ast::modifier::Modifier;
use mago_syntax::cst::class_like::property::Property;
use mago_syntax::cst::modifier::Modifier;
use tower_lsp::lsp_types::*;

use super::cursor_context::{CursorContext, MemberContext, find_cursor_context};
Expand Down Expand Up @@ -548,7 +548,7 @@ fn find_visibility_from_context(ctx: &CursorContext<'_>, cursor: u32) -> Option<
/// For constructor methods, check if the cursor is on a promoted
/// parameter with a visibility modifier.
fn find_promoted_param_visibility(
method: &mago_syntax::ast::class_like::method::Method<'_>,
method: &mago_syntax::cst::class_like::method::Method<'_>,
cursor: u32,
) -> Option<VisibilityHit> {
use mago_span::HasSpan;
Expand Down Expand Up @@ -602,7 +602,7 @@ mod tests {

/// Helper: parse PHP and find visibility at a given byte offset.
fn find_vis(php: &str, offset: u32) -> Option<VisibilityHit> {
let arena = Bump::new();
let arena = LocalArena::new();
let file_id = mago_database::file::FileId::new(b"input.php");
let program = mago_syntax::parser::parse_file_content(&arena, file_id, php.as_bytes());
let ctx = find_cursor_context(&program.statements, offset);
Expand Down
4 changes: 2 additions & 2 deletions src/code_actions/convert_switch_to_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use std::collections::HashMap;

use mago_span::HasSpan;
use mago_syntax::ast::*;
use mago_syntax::cst::*;
use tower_lsp::lsp_types::*;

use crate::Backend;
Expand Down Expand Up @@ -430,7 +430,7 @@ mod tests {
use super::*;

fn try_convert(php: &str) -> Option<String> {
let arena = bumpalo::Bump::new();
let arena = mago_allocator::LocalArena::new();
let file_id = mago_database::file::FileId::new(b"test.php");
let program = mago_syntax::parser::parse_file_content(&arena, file_id, php.as_bytes());

Expand Down
8 changes: 4 additions & 4 deletions src/code_actions/convert_to_arrow_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use std::collections::HashMap;

use mago_span::HasSpan;
use mago_syntax::ast::access::Access;
use mago_syntax::ast::call::Call;
use mago_syntax::ast::*;
use mago_syntax::cst::access::Access;
use mago_syntax::cst::call::Call;
use mago_syntax::cst::*;
use tower_lsp::lsp_types::*;

use crate::Backend;
Expand Down Expand Up @@ -451,7 +451,7 @@ mod tests {
use super::*;

fn find_conversion(php: &str) -> Option<String> {
let arena = bumpalo::Bump::new();
let arena = mago_allocator::LocalArena::new();
let file_id = mago_database::file::FileId::new(b"input.php");
let program = mago_syntax::parser::parse_file_content(&arena, file_id, php.as_bytes());

Expand Down
16 changes: 10 additions & 6 deletions src/code_actions/convert_to_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use std::collections::{HashMap, HashSet};

use mago_span::HasSpan;
use mago_syntax::ast::access::Access;
use mago_syntax::ast::call::Call;
use mago_syntax::ast::*;
use mago_syntax::cst::access::Access;
use mago_syntax::cst::call::Call;
use mago_syntax::cst::*;
use tower_lsp::lsp_types::*;

use crate::Backend;
Expand Down Expand Up @@ -491,7 +491,9 @@ fn find_arrow_in_expression(
Expression::AnonymousClass(anon) => {
if let Some(args) = &anon.argument_list {
for a in args.arguments.iter() {
find_arrow_in_expression(a.value(), cursor, content, best);
if let Some(value) = a.value() {
find_arrow_in_expression(value, cursor, content, best);
}
}
}
}
Expand Down Expand Up @@ -801,7 +803,9 @@ fn collect_variables_in_expression(
Expression::AnonymousClass(anon) => {
if let Some(args) = &anon.argument_list {
for a in args.arguments.iter() {
collect_variables_in_expression(a.value(), content, param_names, out);
if let Some(value) = a.value() {
collect_variables_in_expression(value, content, param_names, out);
}
}
}
}
Expand Down Expand Up @@ -834,7 +838,7 @@ mod tests {
use super::*;

fn find_conversion(php: &str) -> Option<String> {
let arena = bumpalo::Bump::new();
let arena = mago_allocator::LocalArena::new();
let file_id = mago_database::file::FileId::new(b"input.php");
let program = mago_syntax::parser::parse_file_content(&arena, file_id, php.as_bytes());

Expand Down
10 changes: 5 additions & 5 deletions src/code_actions/convert_to_instance_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
use std::collections::HashMap;

use mago_span::HasSpan;
use mago_syntax::ast::class_like::member::ClassLikeMember;
use mago_syntax::ast::class_like::method::MethodBody;
use mago_syntax::ast::class_like::property::Property;
use mago_syntax::ast::sequence::Sequence;
use mago_syntax::ast::*;
use mago_syntax::cst::class_like::member::ClassLikeMember;
use mago_syntax::cst::class_like::method::MethodBody;
use mago_syntax::cst::class_like::property::Property;
use mago_syntax::cst::sequence::Sequence;
use mago_syntax::cst::*;
use tower_lsp::lsp_types::*;

use crate::Backend;
Expand Down
16 changes: 8 additions & 8 deletions src/code_actions/cursor_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
//! namespace → class-like → member traversal.

use mago_span::HasSpan;
use mago_syntax::ast::class_like::constant::ClassLikeConstant;
use mago_syntax::ast::class_like::member::ClassLikeMember;
use mago_syntax::ast::class_like::method::Method;
use mago_syntax::ast::class_like::property::Property;
use mago_syntax::ast::function_like::function::Function;
use mago_syntax::ast::*;
use mago_syntax::cst::class_like::constant::ClassLikeConstant;
use mago_syntax::cst::class_like::member::ClassLikeMember;
use mago_syntax::cst::class_like::method::Method;
use mago_syntax::cst::class_like::property::Property;
use mago_syntax::cst::function_like::function::Function;
use mago_syntax::cst::*;

// ── Public types ────────────────────────────────────────────────────────────

Expand Down Expand Up @@ -204,15 +204,15 @@ fn find_member_at_cursor<'a>(
#[cfg(test)]
mod tests {
use super::*;
use bumpalo::Bump;
use mago_allocator::LocalArena;

/// Helper: parse PHP and find cursor context at a given byte offset.
fn ctx_at(php: &str, offset: u32) -> CursorContext<'_> {
// SAFETY: We leak the arena so the returned CursorContext (which
// borrows from the Program) lives long enough for the test
// assertions. This is fine in tests — the memory is reclaimed
// when the process exits.
let arena = Box::leak(Box::new(Bump::new()));
let arena = Box::leak(Box::new(LocalArena::new()));
let file_id = mago_database::file::FileId::new(b"input.php");
let program = mago_syntax::parser::parse_file_content(arena, file_id, php.as_bytes());
find_cursor_context(&program.statements, offset)
Expand Down
4 changes: 2 additions & 2 deletions src/code_actions/extract_constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use std::collections::HashMap;

use mago_span::HasSpan;
use mago_syntax::ast::class_like::member::ClassLikeMember;
use mago_syntax::ast::*;
use mago_syntax::cst::class_like::member::ClassLikeMember;
use mago_syntax::cst::*;
use tower_lsp::lsp_types::*;

use crate::Backend;
Expand Down
2 changes: 1 addition & 1 deletion src/code_actions/extract_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! variable-type resolution pipeline.

use mago_span::HasSpan;
use mago_syntax::ast::*;
use mago_syntax::cst::*;
use std::collections::HashMap;
use std::sync::Arc;
use tower_lsp::lsp_types::*;
Expand Down
34 changes: 17 additions & 17 deletions src/code_actions/generate_constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
use std::collections::HashMap;

#[cfg(test)]
use bumpalo::Bump;
use mago_allocator::LocalArena;
use mago_span::HasSpan;
use mago_syntax::ast::class_like::member::ClassLikeMember;
use mago_syntax::ast::class_like::property::{Property, PropertyItem};
use mago_syntax::ast::modifier::Modifier;
use mago_syntax::ast::*;
use mago_syntax::cst::class_like::member::ClassLikeMember;
use mago_syntax::cst::class_like::property::{Property, PropertyItem};
use mago_syntax::cst::modifier::Modifier;
use mago_syntax::cst::*;
use tower_lsp::lsp_types::*;

use super::cursor_context::{CursorContext, MemberContext, find_cursor_context};
Expand Down Expand Up @@ -828,7 +828,7 @@ mod tests {

#[test]
fn detects_existing_constructor() {
let arena = Box::leak(Box::new(Bump::new()));
let arena = Box::leak(Box::new(LocalArena::new()));
let file_id = mago_database::file::FileId::new(b"input.php");
let php = "<?php\nclass Foo {\n public function __construct() {}\n}";
let program = mago_syntax::parser::parse_file_content(arena, file_id, php.as_bytes());
Expand All @@ -844,7 +844,7 @@ mod tests {

#[test]
fn detects_no_constructor() {
let arena = Box::leak(Box::new(Bump::new()));
let arena = Box::leak(Box::new(LocalArena::new()));
let file_id = mago_database::file::FileId::new(b"input.php");
let php = "<?php\nclass Foo {\n public string $name;\n}";
let program = mago_syntax::parser::parse_file_content(arena, file_id, php.as_bytes());
Expand All @@ -859,7 +859,7 @@ mod tests {

#[test]
fn detects_constructor_case_insensitive() {
let arena = Box::leak(Box::new(Bump::new()));
let arena = Box::leak(Box::new(LocalArena::new()));
let file_id = mago_database::file::FileId::new(b"input.php");
let php = "<?php\nclass Foo {\n public function __CONSTRUCT() {}\n}";
let program = mago_syntax::parser::parse_file_content(arena, file_id, php.as_bytes());
Expand All @@ -876,7 +876,7 @@ mod tests {

#[test]
fn collects_non_static() {
let arena = Box::leak(Box::new(Bump::new()));
let arena = Box::leak(Box::new(LocalArena::new()));
let file_id = mago_database::file::FileId::new(b"input.php");
let php = "<?php\nclass Foo {\n public string $name;\n private int $age;\n}";
let program = mago_syntax::parser::parse_file_content(arena, file_id, php.as_bytes());
Expand Down Expand Up @@ -912,7 +912,7 @@ mod tests {

#[test]
fn skips_static_properties() {
let arena = Box::leak(Box::new(Bump::new()));
let arena = Box::leak(Box::new(LocalArena::new()));
let file_id = mago_database::file::FileId::new(b"input.php");
let php = "<?php\nclass Foo {\n public string $name;\n public static int $count;\n}";
let program = mago_syntax::parser::parse_file_content(arena, file_id, php.as_bytes());
Expand All @@ -929,7 +929,7 @@ mod tests {

#[test]
fn includes_readonly_properties() {
let arena = Box::leak(Box::new(Bump::new()));
let arena = Box::leak(Box::new(LocalArena::new()));
let file_id = mago_database::file::FileId::new(b"input.php");
let php = "<?php\nclass Foo {\n public string $name;\n public readonly int $id;\n}";
let program = mago_syntax::parser::parse_file_content(arena, file_id, php.as_bytes());
Expand Down Expand Up @@ -957,7 +957,7 @@ mod tests {

#[test]
fn extracts_default_values() {
let arena = Box::leak(Box::new(Bump::new()));
let arena = Box::leak(Box::new(LocalArena::new()));
let file_id = mago_database::file::FileId::new(b"input.php");
let php = "<?php\nclass Foo {\n public string $status = 'active';\n}";
let program = mago_syntax::parser::parse_file_content(arena, file_id, php.as_bytes());
Expand All @@ -975,7 +975,7 @@ mod tests {

#[test]
fn extracts_docblock_type_when_no_native_hint() {
let arena = Box::leak(Box::new(Bump::new()));
let arena = Box::leak(Box::new(LocalArena::new()));
let file_id = mago_database::file::FileId::new(b"input.php");
let php = "<?php\nclass Foo {\n /** @var string */\n public $name;\n}";
let program = mago_syntax::parser::parse_file_content(arena, file_id, php.as_bytes());
Expand All @@ -1000,7 +1000,7 @@ mod tests {

#[test]
fn skips_compound_docblock_type() {
let arena = Box::leak(Box::new(Bump::new()));
let arena = Box::leak(Box::new(LocalArena::new()));
let file_id = mago_database::file::FileId::new(b"input.php");
let php = "<?php\nclass Foo {\n /** @var int|string */\n public $id;\n}";
let program = mago_syntax::parser::parse_file_content(arena, file_id, php.as_bytes());
Expand All @@ -1021,7 +1021,7 @@ mod tests {

#[test]
fn preserves_nullable_native_type() {
let arena = Box::leak(Box::new(Bump::new()));
let arena = Box::leak(Box::new(LocalArena::new()));
let file_id = mago_database::file::FileId::new(b"input.php");
let php = "<?php\nclass Foo {\n public ?string $name;\n}";
let program = mago_syntax::parser::parse_file_content(arena, file_id, php.as_bytes());
Expand All @@ -1045,7 +1045,7 @@ mod tests {

#[test]
fn preserves_union_native_type() {
let arena = Box::leak(Box::new(Bump::new()));
let arena = Box::leak(Box::new(LocalArena::new()));
let file_id = mago_database::file::FileId::new(b"input.php");
let php = "<?php\nclass Foo {\n public int|string $id;\n}";
let program = mago_syntax::parser::parse_file_content(arena, file_id, php.as_bytes());
Expand All @@ -1069,7 +1069,7 @@ mod tests {

#[test]
fn captures_declaration_span() {
let arena = Box::leak(Box::new(Bump::new()));
let arena = Box::leak(Box::new(LocalArena::new()));
let file_id = mago_database::file::FileId::new(b"input.php");
let php = "<?php\nclass Foo {\n public string $name;\n}\n";
let program = mago_syntax::parser::parse_file_content(arena, file_id, php.as_bytes());
Expand Down
16 changes: 8 additions & 8 deletions src/code_actions/generate_getter_setter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
use std::collections::HashMap;

#[cfg(test)]
use bumpalo::Bump;
use mago_allocator::LocalArena;
use mago_span::HasSpan;
use mago_syntax::ast::class_like::member::ClassLikeMember;
use mago_syntax::ast::class_like::property::Property;
use mago_syntax::ast::modifier::Modifier;
use mago_syntax::ast::*;
use mago_syntax::cst::class_like::member::ClassLikeMember;
use mago_syntax::cst::class_like::property::Property;
use mago_syntax::cst::modifier::Modifier;
use mago_syntax::cst::*;
use tower_lsp::lsp_types::*;

use super::cursor_context::{CursorContext, MemberContext, find_cursor_context};
Expand Down Expand Up @@ -944,7 +944,7 @@ mod tests {
}

fn parse_and_collect(php: &str) -> Vec<AccessorProperty> {
let arena = Box::leak(Box::new(Bump::new()));
let arena = Box::leak(Box::new(LocalArena::new()));
let file_id = mago_database::file::FileId::new(b"input.php");
let program = mago_syntax::parser::parse_file_content(arena, file_id, php.as_bytes());

Expand Down Expand Up @@ -1070,7 +1070,7 @@ mod tests {
#[test]
fn skips_hooked_property() {
let php = "<?php\nclass Foo {\n public string $name { get => $this->name; }\n}";
let arena = Box::leak(Box::new(Bump::new()));
let arena = Box::leak(Box::new(LocalArena::new()));
let file_id = mago_database::file::FileId::new(b"input.php");
let program = mago_syntax::parser::parse_file_content(arena, file_id, php.as_bytes());

Expand All @@ -1094,7 +1094,7 @@ mod tests {

#[test]
fn finds_existing_methods() {
let arena = Box::leak(Box::new(Bump::new()));
let arena = Box::leak(Box::new(LocalArena::new()));
let file_id = mago_database::file::FileId::new(b"input.php");
let php = "<?php\nclass Foo {\n public string $name;\n public function getName(): string { return $this->name; }\n public function setName(string $name): self { $this->name = $name; return $this; }\n}";
let program = mago_syntax::parser::parse_file_content(arena, file_id, php.as_bytes());
Expand Down
Loading
Loading