Git Product home page Git Product logo

Comments (14)

mniewrzal avatar mniewrzal commented on August 15, 2024 2

I abandon my previous PR for CS-Fixer. I created PR #35 with PHPCBF integration. PHPCBF formatting looks slightly better and performance is good even with XDebug enabled. Like CS-Fixer it has some gaps to fill (e.g. whitespaces in namespace declaration) but I think it will be easier to add missing rules than writing formatter from scratch (e.g. based on PrettyPrinter).

from php-language-server.

mniewrzal avatar mniewrzal commented on August 15, 2024 1

Range formatting is probably less problematic than lack of configuration. PrettyPrinter should be able to format just selected range if user will select complete AST node. To make it configurable we need to extend it and add own logic.

I will take a look at CS Fixer and PHPCBF.

from php-language-server.

mniewrzal avatar mniewrzal commented on August 15, 2024 1

Yes, I understand. I just wanted to say that without hope for better performance I didn't see a chance for using cs-fixer with language server. Actual implementation is too messy to make PR from it ;)

from php-language-server.

felixfbecker avatar felixfbecker commented on August 15, 2024

This early implementation of the formatting feature is using he standard PrettyPrinter of PHPParser: https://github.com/nikic/PHP-Parser/blob/master/lib/PhpParser/PrettyPrinter/Standard.php.

I am also not satisfied with the output, for example how it handles use and declare statements and the empty lines. I'm sure the class can be customized more. We could

  • do a PR to PHPParser to allow customizing of the PrettyPrinter
  • subclass it to customize it

contributions welcome!

from php-language-server.

kaloyan-raev avatar kaloyan-raev commented on August 15, 2024

I heard from @mniewrzal that the PrettyPrinter can't be used for range formatting, but only for formatting the whole document.

I wonder if we can use either the CS Fixer or PHPCBF. AFAIK they already support a variety of coding standards.

I am not sure if they are better for range formatting, but perhaps it's worth taking a look.

from php-language-server.

mniewrzal avatar mniewrzal commented on August 15, 2024

I played with CS Fixer today and I was able to use it with language server. If someone want to take a look here is branch with changes. Its just a fast hack ;-)

Pros:

  • configurable
  • workspace can contain configuration file .php_cs, no need for additional configuration through language server protocol
  • quite easy to integrate

Cons:

  • can be very slow, with enabled xdebug formatting 1600 LOC can take more than 10s, The same operation without xdebug takes under 1s.

from php-language-server.

felixfbecker avatar felixfbecker commented on August 15, 2024

@mniewrzal always feel free to open a PR, it is a nice way to start a discussion :)

can be very slow, with enabled xdebug formatting 1600 LOC can take more than 10s, The same operation without xdebug takes under 1s.

I would like to implement some solution in the client that spawns the language server without XDebug, XDebug is performance killer. Some ideas here: http://stackoverflow.com/questions/38506140/how-to-run-composer-without-xdebug-when-installed-with-homebrew
On startup, read the php.ini, remove lines containing "xdebug", write to temp folder, start php with the ini file.

from php-language-server.

mniewrzal avatar mniewrzal commented on August 15, 2024

@mniewrzal always feel free to open a PR, it is a nice way to start a discussion :)

If there is an option to overcome xdebug performance issue making such PR make sense :) I will prepare something soon.

from php-language-server.

felixfbecker avatar felixfbecker commented on August 15, 2024

I meant that I prefer to discuss changes on an open PR that is not yet finished, because you can better comment on the changes, even when it won't get merged in the current state of the branch :)

from php-language-server.

kaloyan-raev avatar kaloyan-raev commented on August 15, 2024

@mniewrzal can you check what is the performance impact if having Zend Debugger instead of Xdebug?

from php-language-server.

mniewrzal avatar mniewrzal commented on August 15, 2024

PHP CS Fixer times for https://github.com/composer/composer/blob/master/src/Composer/Installer.php:

  • no debugger: ~0.9s
  • zenddebugger: ~1.3s
  • xdebug: ~4.4s

from php-language-server.

felixfbecker avatar felixfbecker commented on August 15, 2024

Solved with PHP_CodeSniffer

from php-language-server.

myMartek avatar myMartek commented on August 15, 2024

And how to configure the formatting now?

Can you give an example?

from php-language-server.

felixfbecker avatar felixfbecker commented on August 15, 2024

Please refer to the PHP CodeSniffer documentation on how to configure it with an XML file - you can also find one in this repository

from php-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.