Php-language-server: Error when format document

Created on 13 Feb 2017  Â·  7Comments  Â·  Source: felixfbecker/php-language-server

 Message: Exception: Unable to format file in /home/huzhifeng/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/felixfbecker/language-server/src/Formatter.php:52
Stack trace:
#0 /home/huzhifeng/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/felixfbecker/language-server/src/PhpDocument.php(244): LanguageServer\Formatter::format('<?php\n/**\n * \xE6\x95...', 'file:///home/hu...')
#1 /home/huzhifeng/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/felixfbecker/language-server/src/Server/TextDocument.php(179): LanguageServer\PhpDocument->getFormattedText()
#2 /home/huzhifeng/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/sabre/event/lib/Promise.php(242): LanguageServer\Server\TextDocument->LanguageServer\Server\{closure}(Object(LanguageServer\PhpDocument))
#3 /home/huzhifeng/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/sabre/event/lib/Loop/Loop.php(261): Sabre\Event\Promise->Sabre\Event\{closure}()
#4 /home/huzhifeng/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/sabre/event/lib/Loop/Loop.php(215): Sabre\Event\Loop\Loop->runNextTicks()
#5 /home/huzhifeng/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/sabre/event/lib/Loop/Loop.php(194): Sabre\Event\Loop\Loop->tick(true)
#6 /home/huzhifeng/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/sabre/event/lib/Loop/functions.php(122): Sabre\Event\Loop\Loop->run()
#7 /home/huzhifeng/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/felixfbecker/language-server/bin/php-language-server.php(102): Sabre\Event\Loop\run()
#8 {main}
  Code: -32603 
bug formatting

Most helpful comment

@felixfbecker I have noticed that this happens whenever there is a phpcs error. For example, the following code causes the -32603 error.

<?php namespace app\test;

class test
{
    public $test1;
}

And phpcs will have the following error

file: 'xxx/app/models/test.php'
severity: 'Error'
message: 'Class name "test" is not in camel caps format'
at: '3,1'
source: 'phpcs'

But if I fix the error and change it to the following

<?php namespace app\test;

class Test
{
    public $test1;
}

I am then able to save the file and the formatting/validation is run correctly.

All 7 comments

Can you provide the file you tried to format?

sure. but it not opensource code. you can write mail to my mail.
[email protected]
and i will mail one to you . and you need keep it in secret. or should
delete it after use

Appreciate your time.

Netroby

2017-02-13 16:46 GMT+08:00 Felix Becker notifications@github.com:

Can you provide the file you tried to format?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/felixfbecker/php-language-server/issues/296#issuecomment-279325897,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAQ-iSRpVohbuEqZS8Ewg05SPSBGy4hpks5rcBh1gaJpZM4L-4Pz
.

I am having the same problem here is the code in the file:
```

if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}

require_once('modules/Campaigns/Campaign.php');

class CampaignIDFix
{

function after_save($bean, $event, $arguments)
{

    global $db;

    if (! $bean->campaign_id) {
        return ;
    };

    $campaign = new Campaign();
    $campaign->retrieve($bean->campaign_id);

    if (! $campaign->id) {
        return;
    };

    $pq = $db->prepareQuery("SELECT *DELETE FROM campaign_log WHERE target_id = '?'");
    $tresult = $db->executePreparedQuery($pq, array($bean->id));

    $campaign_log = new CampaignLog();
    $campaign_log->retrieve_by_string_fields(array(
    "target_type"=>$bean->module_name,
    "target_id"=>$bean->id,
    "related_type"=>$bean->module_name,
    "related_id"=>$bean->id,
    "campaign_id"=>$campaign->id
    ));

    if ($campaign_log->id) {
        return;
    };

    $pq = $db->prepareQuery("DELETE FROM campaign_log WHERE (target_type = 'Contacts' target_id = '?'");
    $tresult = $db->executePreparedQuery($pq, array(
        $bean->module_name,
        $bean->id,
        $bean->module_name,
        $bean->id
    ));
    $camplog = new CampaignLog();
    $camplog->campaign_id  = $bean->campaign_id;
    $camplog->related_id   = $bean->id;
    $camplog->related_type = $bean->module_name;
    $camplog->activity_type = "contact";
    $camplog->target_id = $bean->id;
    $camplog->target_type = $bean->module_name;
    $camplog->activity_date = $bean->date_entered;
    $camplog->save();
}

}
```

I use vscode on windows and have installed PHP IntelliSense v1.1.4 and the PHP Formatter v0.2.4 extension which uses php-cs-fixer for formatting the code. I've configured it to run on save and this error shows every time I save the file and there is nothing to fix by the formatter. If I have incorrect formatting the formatter fixes it and the error doesn't show up.

@felixfbecker I have noticed that this happens whenever there is a phpcs error. For example, the following code causes the -32603 error.

<?php namespace app\test;

class test
{
    public $test1;
}

And phpcs will have the following error

file: 'xxx/app/models/test.php'
severity: 'Error'
message: 'Class name "test" is not in camel caps format'
at: '3,1'
source: 'phpcs'

But if I fix the error and change it to the following

<?php namespace app\test;

class Test
{
    public $test1;
}

I am then able to save the file and the formatting/validation is run correctly.

@kyle-mccarthy Yes! that's happening because of phpcs, is there anyway to ignore it ?

Same thing over here.

Was this page helpful?
0 / 5 - 0 ratings