twigphp / Twig

Twig, the flexible, fast, and secure template language for PHP
https://twig.symfony.com/
BSD 3-Clause "New" or "Revised" License
8.18k stars 1.25k forks source link

Official Language Server #3650

Closed brooksvb closed 2 years ago

brooksvb commented 2 years ago

There is no language server that exists for Twig. Currently, it seems that if you want syntax highlighting and autocompletion support, your only choice is to use the proprietary Phpstorm IDE, or VS Code with a couple Twig extensions.

I no longer use Phpstorm because I can't have my development workflow heavily depend on proprietary software anymore, and VS Code is not ideal for me anymore. I have transitioned to using Neovim as my IDE, and in trying to configure it to support Twig, it is not supported well at all. Syntax highlighting does not work properly with some plugins, and without a language server, there will be no autocompletions.

Creating a Twig language server would allow the language support across all IDEs to be driven by the same engine, and allow any new IDEs to more easily support Twig.

I've never created a language server or syntax highlighting type of application. It seems that for whatever reason there is little interest to have Twig support in more editors. If no one else is willing to develop this, eventually I would probably try my hand at implementing one, but I figure there must be some other developers who are interested in improving the future of Twig's support in many development environments.

fabpot commented 2 years ago

Thank you for taking the time to create this issue. I think this is the first time someone asked for such a feature. Having a language server for Twig sounds like a great idea. I've never had a look at what it would involve, so I cannot say if that would take a lot of time. If you decide to start working on this, don't hesitate to share your experience with us.

brooksvb commented 2 years ago

I've asked around, and it seems the community of Neovim users also using Twig is not huge, but it exists. I also imagine there are probably many developers who try to use Neovim/Vim, find that it doesn't support Twig well, try a couple plugins which do a half-okay job, and either decide that it's the best they can do and deal with it, or give up on Vim and use a different editor.

Some links to discussion: https://www.reddit.com/r/neovim/comments/ny3gmp/comment/h1j0gef/?utm_source=share&utm_medium=web2x&context=3 https://www.reddit.com/r/neovim/comments/ny3gmp/comment/h1i3qrq/?utm_source=share&utm_medium=web2x&context=3 https://www.reddit.com/r/neovim/comments/sv8ff9/support_for_twig_templates/?utm_source=share&utm_medium=web2x&context=3

n3wborn commented 2 years ago

So true ! Having a language server for Twig would be awesome, this is something I'd really love to have 👍🏽

hansemschnokeloch commented 2 years ago

I too would love to have a language server for Twig :+1:

fabpot commented 2 years ago

Sure, I would love to, but I won't be able to do it myself, so it must come from the community.

kaermorchen commented 1 year ago

I have written Twig Language Server.

It supports:

fabpot commented 1 year ago

Thank you @kaermorchen Do you want to list it in the doc for more visibility? Maybe here: https://github.com/twigphp/Twig/blob/3.x/doc/templates.rst#ides-integration

kaermorchen commented 1 year ago

@fabpot I have added it in doc in #3868

lyrixx commented 1 year ago

Hello @kaermorchen. Thanks for this contribution! This is cool. I looked at your code, and I fail to see where you connect to a twig engine to get the list of filter, function, and so one.

It looks like the list is hardcoded in this file

So if I add a new function in my project, the LS will not know about it, and so I won't have autocompletion?

kaermorchen commented 1 year ago

Hello @lyrixx

It looks like the list is hardcoded in this file So if I add a new function in my project, the LS will not know about it, and so I won't have autocompletion?

Yes, you are right. I have already created the feature request about it #3866

moetelo commented 1 year ago

Here is Twiggy, a VS Code extension. This is a fork of Twig Language Server extended with many features.

The features include:

VS Code Marketplace: Twiggy

I am open to any kind of contribution to my project.


@lyrixx

fail to see where you connect to a twig engine to get the list of filter, function, and so on

You are welcome to look at the way I've implemented the connection to Symfony. Here I execute php bin/console debug:twig --format json to get all user-defined filters, functions and globals. Then I parse the stdout as JSON and use it to provide completion.

Although this would work for Symfony, this won't work for Twig-based CMS and other frameworks. So I'm open to suggestions on how to make this work for other Twig-based projects.

@fabpot

Is it okay if I submit a PR that lists Twiggy in the doc too?

fabpot commented 1 year ago

@moetelo Of course!

moetelo commented 1 year ago

@fabpot Here is the PR: https://github.com/twigphp/Twig/pull/3889