Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when format document #296

Closed
ghost opened this issue Feb 13, 2017 · 7 comments · Fixed by #504
Closed

Error when format document #296

ghost opened this issue Feb 13, 2017 · 7 comments · Fixed by #504

Comments

@ghost
Copy link

ghost commented Feb 13, 2017

 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 
@felixfbecker
Copy link
Owner

Can you provide the file you tried to format?

@ghost
Copy link
Author

ghost commented Feb 13, 2017 via email

@thisboyiscrazy
Copy link

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();
    }
}

@wkiril
Copy link

wkiril commented Apr 5, 2017

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.

@kyle-mccarthy
Copy link

@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.

@yamenarahman
Copy link

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

@asolopovas
Copy link

Same thing over here.

felixfbecker added a commit that referenced this issue Oct 28, 2017
BREAKING CHANGE: removes formatting support

closes #501
closes #474
closes #473
closes #468
closes #450
closes #445
closes #443
closes #423
closes #343
closes #296
closes #293
felixfbecker added a commit that referenced this issue Oct 28, 2017
BREAKING CHANGE: removes formatting support

closes #501
closes #474
closes #473
closes #468
closes #450
closes #445
closes #443
closes #423
closes #343
closes #296
closes #293
closes #499
closes #471
felixfbecker added a commit that referenced this issue Oct 28, 2017
BREAKING CHANGE: removes formatting support

closes #501
closes #474
closes #473
closes #468
closes #450
closes #445
closes #443
closes #423
closes #343
closes #296
closes #293
closes #499
closes #471
felixfbecker added a commit that referenced this issue Oct 28, 2017
BREAKING CHANGE: removes formatting support

closes #501
closes #474
closes #473
closes #468
closes #450
closes #445
closes #443
closes #423
closes #343
closes #296
closes #293
closes #499
closes #471
felixfbecker added a commit that referenced this issue Oct 28, 2017
BREAKING CHANGE: removes formatting support

closes #501
closes #474
closes #473
closes #468
closes #450
closes #445
closes #443
closes #423
closes #343
closes #296
closes #293
closes #499
closes #471
felixfbecker added a commit that referenced this issue Nov 5, 2017
At this point there are countless issues about the formatting done by CodeSniffer. It plain out doesn't work in many cases, overrides format options that are contributed by other extensions in VS Code and does not reuse any of our AST parsing. For that reason, I am starting to think there is no reason to keep it in here until we have proper pretty-printing support from https://github.com/Microsoft/tolerant-php-parser that actually reuses our ASTs and can work while editing. For people who want to use CodeSniffer to format their code, there could be a standalone CodeSniffer language server (like there is a TSLint language server and ESLint language server). As said, we don't reuse our state anyway.

BREAKING CHANGE: removes formatting support

closes #501
closes #474
closes #473
closes #468
closes #450
closes #445
closes #443
closes #423
closes #343
closes #296
closes #293
closes #499
closes #471
@citosid citosid mentioned this issue Dec 18, 2019
cgxxv pushed a commit to cgxxv/php-language-server that referenced this issue Mar 25, 2022
At this point there are countless issues about the formatting done by CodeSniffer. It plain out doesn't work in many cases, overrides format options that are contributed by other extensions in VS Code and does not reuse any of our AST parsing. For that reason, I am starting to think there is no reason to keep it in here until we have proper pretty-printing support from https://github.com/Microsoft/tolerant-php-parser that actually reuses our ASTs and can work while editing. For people who want to use CodeSniffer to format their code, there could be a standalone CodeSniffer language server (like there is a TSLint language server and ESLint language server). As said, we don't reuse our state anyway.

BREAKING CHANGE: removes formatting support

closes felixfbecker#501
closes felixfbecker#474
closes felixfbecker#473
closes felixfbecker#468
closes felixfbecker#450
closes felixfbecker#445
closes felixfbecker#443
closes felixfbecker#423
closes felixfbecker#343
closes felixfbecker#296
closes felixfbecker#293
closes felixfbecker#499
closes felixfbecker#471
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants