Coder Social home page Coder Social logo

Comments (10)

borisdaeppen avatar borisdaeppen commented on July 22, 2024

I just noticed, that PLS probably is not responsible for the highlighting?

from perl-language-server.

FractalBoy avatar FractalBoy commented on July 22, 2024

Correct, highlighting is built into VSCode - you'd have to take it up with them.

from perl-language-server.

raiph avatar raiph commented on July 22, 2024

Hi @borisdaeppen,

I recommend you reach out to Damian Conway and explain to him what you're hoping for Perl and your students.

If you need more reason to do so than just me saying so, please watch, or at least fast forward through, these two of his presentations:

  • "Three Little Words". This demonstrates his mastery of many things, but in particular the engine that underlies both highlighting and extensions to the Perl language. (Regexes. Damian must surely be one of the leading experts in the world on regexes.)

  • "Small matter of programming". This shows his 2020 work, which builds on the work shown in his "Three Little Words" presentation, but is narrowly focused on making his development environment of choice do VS-Code like things. He's built it in a deliberately editor-agnostic fashion, one that should work nicely with the Language Server Protocol (which PLS implements).

I don't know the path from Damian's work to getting something that works for you and your students, but I do know that it can't do harm for you to reach out to Damian to see what he suggests.

from perl-language-server.

FractalBoy avatar FractalBoy commented on July 22, 2024

Putting aside syntax highlighting, you could implement this if you would like, however I think it would be somewhat difficult.

This is how PPI parses your example code:

mreisner@blacklodgetop:~$ cat << 'EOF' | perl -MPPI -MData::Dumper -e 'my $code = do { local $/; <> }; my $doc = PPI::Document->new(\$code); print Dumper $doc'
use Function::Parameters 'method';
use English;
use Try::Tiny;

method reply ($option) {
}
EOF
$VAR1 = bless( {
                 'readonly' => '',
                 'filename' => undef,
                 'children' => [
                                 bless( {
                                          'children' => [
                                                          bless( {
                                                                   'content' => 'use'
                                                                 }, 'PPI::Token::Word' ),
                                                          bless( {
                                                                   'content' => ' '
                                                                 }, 'PPI::Token::Whitespace' ),
                                                          bless( {
                                                                   'content' => 'Function::Parameters'
                                                                 }, 'PPI::Token::Word' ),
                                                          bless( {
                                                                   'content' => ' '
                                                                 }, 'PPI::Token::Whitespace' ),
                                                          bless( {
                                                                   'separator' => '\'',
                                                                   'content' => '\'method\''
                                                                 }, 'PPI::Token::Quote::Single' ),
                                                          bless( {
                                                                   'content' => ';'
                                                                 }, 'PPI::Token::Structure' )
                                                        ]
                                        }, 'PPI::Statement::Include' ),
                                 bless( {
                                          'content' => '
'
                                        }, 'PPI::Token::Whitespace' ),
                                 bless( {
                                          'children' => [
                                                          bless( {
                                                                   'content' => 'use'
                                                                 }, 'PPI::Token::Word' ),
                                                          bless( {
                                                                   'content' => ' '
                                                                 }, 'PPI::Token::Whitespace' ),
                                                          bless( {
                                                                   'content' => 'English'
                                                                 }, 'PPI::Token::Word' ),
                                                          bless( {
                                                                   'content' => ';'
                                                                 }, 'PPI::Token::Structure' )
                                                        ]
                                        }, 'PPI::Statement::Include' ),
                                 bless( {
                                          'content' => '
'
                                        }, 'PPI::Token::Whitespace' ),
                                 bless( {
                                          'children' => [
                                                          bless( {
                                                                   'content' => 'use'
                                                                 }, 'PPI::Token::Word' ),
                                                          bless( {
                                                                   'content' => ' '
                                                                 }, 'PPI::Token::Whitespace' ),
                                                          bless( {
                                                                   'content' => 'Try::Tiny'
                                                                 }, 'PPI::Token::Word' ),
                                                          bless( {
                                                                   'content' => ';'
                                                                 }, 'PPI::Token::Structure' )
                                                        ]
                                        }, 'PPI::Statement::Include' ),
                                 bless( {
                                          'content' => '
'
                                        }, 'PPI::Token::Whitespace' ),
                                 bless( {
                                          'content' => '
'
                                        }, 'PPI::Token::Whitespace' ),
                                 bless( {
                                          'children' => [
                                                          bless( {
                                                                   'content' => 'method'
                                                                 }, 'PPI::Token::Word' ),
                                                          bless( {
                                                                   'content' => ' '
                                                                 }, 'PPI::Token::Whitespace' ),
                                                          bless( {
                                                                   'content' => 'reply'
                                                                 }, 'PPI::Token::Word' ),
                                                          bless( {
                                                                   'content' => ' '
                                                                 }, 'PPI::Token::Whitespace' ),
                                                          bless( {
                                                                   'finish' => bless( {
                                                                                        'content' => ')'
                                                                                      }, 'PPI::Token::Structure' ),
                                                                   'children' => [
                                                                                   bless( {
                                                                                            'children' => [
                                                                                                            bless( {
                                                                                                                     'content' => '$option'
                                                                                                                   }, 'PPI::Token::Symbol' )
                                                                                                          ]
                                                                                          }, 'PPI::Statement::Expression' )
                                                                                 ],
                                                                   'start' => bless( {
                                                                                       'content' => '('
                                                                                     }, 'PPI::Token::Structure' )
                                                                 }, 'PPI::Structure::List' ),
                                                          bless( {
                                                                   'content' => ' '
                                                                 }, 'PPI::Token::Whitespace' ),
                                                          bless( {
                                                                   'start' => bless( {
                                                                                       'content' => '{'
                                                                                     }, 'PPI::Token::Structure' ),
                                                                   'children' => [
                                                                                   bless( {
                                                                                            'content' => '
'
                                                                                          }, 'PPI::Token::Whitespace' )
                                                                                 ],
                                                                   'finish' => bless( {
                                                                                        'content' => '}'
                                                                                      }, 'PPI::Token::Structure' )
                                                                 }, 'PPI::Structure::Block' )
                                                        ]
                                        }, 'PPI::Statement' ),
                                 bless( {
                                          'content' => '
'
                                        }, 'PPI::Token::Whitespace' )
                               ],
                 'tab_width' => 1
               }, 'PPI::Document' );

So, to implement, in addition to recognizing methods by sub <method name>, you could look for the Function::Parameters import, and if it is present, look for a pattern similar to the above and consider it to be a method.

I don't plan on adding this functionality myself, so if you don't feel up to the challenge, I will go ahead and close this issue.

from perl-language-server.

borisdaeppen avatar borisdaeppen commented on July 22, 2024

@raiph thx for your suggestions. I do know about Damian, will see if I can go the path you suggested. Maybe I'll also see what 'reddit' thinks... it seems to be a very general problem, that if you use any kind of "language extension", then the syntax highlighting is broken... kind of an ugly thing and limiting the TIMTOWTDI-approach of Perl!

@FractalBoy Since my problem is just "polishing", and my knowledge and experience wit "parsing Perl" is limited, I will probably not be able to prioritise my time to this. But we'll see. Your hints will be very helpful if I or anyone else will want to give this a shot in the future. So thank you a lot!

As a last note, here some code that helped me highlight method foo in vim, if someone looking for this kind of problem finds this helpful:

~$ cat .vim/after/syntax/perl.vim 
" Support Syntax Highlight for 'method foo':
"
"   use Function::Parameters 'method'
"   method foo ($bar) { print $self->{bar} }
"
" 'method' as PerlMethod and the word after 'method' as PerlMethodname
syn keyword PerlMethod method nextgroup=PerlMethodname skipwhite
syn match PerlMethodname '\i\+' contained
" give some colors
hi link PerlMethodname perlFunctionName
hi link PerlMethod perlStatement

Will then look like this in standard Ubuntu 18.04 vim:

grafik

from perl-language-server.

FractalBoy avatar FractalBoy commented on July 22, 2024

The syntax for Perl in VSCode is here.

https://github.com/microsoft/vscode/blob/main/extensions/perl/syntaxes/perl.tmLanguage.json

I am closing this issue - if anyone wants to pick it up they are welcome to, but I will leave this closed in the meantime.

from perl-language-server.

raiph avatar raiph commented on July 22, 2024

@borisdaeppen

if you use any kind of "language extension", then the syntax highlighting is broken

Not Damian's. His approach to language extension, and integrating that into tooling, is not only viable but working, as demonstrated in the videos I linked.

It seems to me Damian is bent on porting the best of the language evolutions and extensions he spent 20 years designing, mostly as part of Raku, back to contemporary Perl, along with support for them in Perl editing environments.

And, appropriately for a master Perl hacker, he started by building tools that everyone can use for their evolutions and extensions.

The more folk adopt his approach, tweaking their own existing extensions if need be, the better the 2020s will be for Perl's language extensibility and editor handling of extensions.

So I reckon there's a good chance you will find his work is a great boon to you and your students. Plus I think he will be delighted to help you because those teaching Perl are surely ideal consumers of his tech, and natural partners in their polishing.

Good luck!

from perl-language-server.

raiph avatar raiph commented on July 22, 2024

PPI...

I suggest PPR instead as the first port of call for anyone dealing with Perl language extensions and/or editor features. See the two videos I linked in an earlier message and/or Comparison of PPR with PPI and, regardless, contact Damian Conway.

from perl-language-server.

FractalBoy avatar FractalBoy commented on July 22, 2024

PPR is good for certain things. PLS makes use of it. It cannot completely replace PPI in PLS as it does not provide things such as line numbers.

from perl-language-server.

FractalBoy avatar FractalBoy commented on July 22, 2024

I've locked this thread because this is not a place for random perl discussion.

from perl-language-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.