FractalBoy / perl-language-server

100 stars 12 forks source link

Support for "has" attributes #139

Open mbuc82 opened 1 year ago

mbuc82 commented 1 year ago

Hello,

it would be great, if PLS would support the "has" attribute definitions from the Moose/Moo/Mo implementations of Perl, to be usable in the outline part of VSCode.

Moose

has 'node' => (is => 'rw', isa => 'Any');

has 'children' => (
    is      => 'ro',
    isa     => 'ArrayRef',
    default => sub { [] }
);

has 'parent' => (
    is          => 'rw',
    isa         => 'Tree',
    weak_ref    => 1,
    handles     => {
        parent_node => 'node',
        siblings    => 'children',
    }
);

Moo

has taste => (
  is => 'ro',
);

has brand => (
  is  => 'ro',
  isa => sub {
    die "Only SWEET-TREATZ supported!" unless $_[0] eq 'SWEET-TREATZ'
  },
);

has pounds => (
  is  => 'rw',
  isa => sub { die "$_[0] is too much cat food!" unless $_[0] < 15 },
);

Mo

has name1 => ( default => sub { 'Joe' } );
has name2 => ( builder => 'name_builder' );
has name3 => ( coerce => sub {$_[0]} );
has name4 => ( is => 'ro' );
has name4 => ( required => 1 );

Apart from that, the step to Perl's Cor implementation would also be a bit smaller.

FractalBoy commented 1 year ago

Thanks for the suggestion. You're right, there should be some handling for commonly used OO systems in Perl.

I'll probably wait until it's a bit more mature before working on feature 'class'