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 formatting files without namespace #293

Closed
felixfbecker opened this issue Feb 9, 2017 · 3 comments · Fixed by #504
Closed

Error when formatting files without namespace #293

felixfbecker opened this issue Feb 9, 2017 · 3 comments · Fixed by #504

Comments

@felixfbecker
Copy link
Owner

From @andreshg112 on February 9, 2017 22:42

I'm getting this error in class files where there's no a defined namespace:

[Error - 17:38:31] Request textDocument/formatting failed.
  Message: Exception: Unable to format file in /home/andreshg112/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/felixfbecker/language-server/src/Formatter.php:52
Stack trace:
#0 /home/andreshg112/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/felixfbecker/language-server/src/PhpDocument.php(244): LanguageServer\Formatter::format('<?php\n\nuse Illu...', 'file:///opt/lam...')
#1 /home/andreshg112/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/felixfbecker/language-server/src/Server/TextDocument.php(179): LanguageServer\PhpDocument->getFormattedText()
#2 /home/andreshg112/.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/andreshg112/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/sabre/event/lib/Loop/Loop.php(261): Sabre\Event\Promise->Sabre\Event\{closure}()
#4 /home/andreshg112/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/sabre/event/lib/Loop/Loop.php(215): Sabre\Event\Loop\Loop->runNextTicks()
#5 /home/andreshg112/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/sabre/event/lib/Loop/Loop.php(194): Sabre\Event\Loop\Loop->tick(true)
#6 /home/andreshg112/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/sabre/event/lib/Loop/functions.php(122): Sabre\Event\Loop\Loop->run()
#7 /home/andreshg112/.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 
[Error - 17:39:50] Request textDocument/formatting failed.
  Message: Exception: Unable to format file in /home/andreshg112/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/felixfbecker/language-server/src/Formatter.php:52
Stack trace:
#0 /home/andreshg112/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/felixfbecker/language-server/src/PhpDocument.php(244): LanguageServer\Formatter::format('<?php\n\nuse Illu...', 'file:///opt/lam...')
#1 /home/andreshg112/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/felixfbecker/language-server/src/Server/TextDocument.php(179): LanguageServer\PhpDocument->getFormattedText()
#2 /home/andreshg112/.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/andreshg112/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/sabre/event/lib/Loop/Loop.php(261): Sabre\Event\Promise->Sabre\Event\{closure}()
#4 /home/andreshg112/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/sabre/event/lib/Loop/Loop.php(215): Sabre\Event\Loop\Loop->runNextTicks()
#5 /home/andreshg112/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/sabre/event/lib/Loop/Loop.php(194): Sabre\Event\Loop\Loop->tick(true)
#6 /home/andreshg112/.vscode/extensions/felixfbecker.php-intellisense-1.1.1/vendor/sabre/event/lib/Loop/functions.php(122): Sabre\Event\Loop\Loop->run()
#7 /home/andreshg112/.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 

Copied from original issue: felixfbecker/vscode-php-intellisense#72

@felixfbecker felixfbecker changed the title Error on files without namespace Error when formatting files without namespace Feb 9, 2017
@felixfbecker
Copy link
Owner Author

Can you post the file please?

@andreshg112
Copy link

andreshg112 commented Feb 9, 2017

The name of the file is: 2017_02_09_173745_add_registra_iva_to_establecimientos.php

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddRegistraIvaToEstablecimientos extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('establecimientos', function (Blueprint $table) {
            $table->boolean('registra_iva')->default(1)->after('tiene_pedido_mesa');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('establecimientos', function (Blueprint $table) {
            $table->dropColumn('registra_iva');
        });
    }
}

@MartinP7r
Copy link

MartinP7r commented Oct 16, 2017

I got this error today when trying to format a php file containing only:

<?php
class SomeClass
{
}
[Error - 13:05:37] Request textDocument/formatting failed.
  Message: Exception: Unable to format file in /Users/abc/.vscode/extensions/felixfbecker.php-intellisense-1.5.1/vendor/felixfbecker/language-server/src/Formatter.php:52
Stack trace:
#0 /Users/abc/.vscode/extensions/felixfbecker.php-intellisense-1.5.1/vendor/felixfbecker/language-server/src/PhpDocument.php(179): LanguageServer\Formatter::format('<?php\n\n\nclass M...', 'file:///Volumes...')
#1 /Users/abc/.vscode/extensions/felixfbecker.php-intellisense-1.5.1/vendor/felixfbecker/language-server/src/Server/TextDocument.php(172): LanguageServer\PhpDocument->getFormattedText()
#2 /Users/abc/.vscode/extensions/felixfbecker.php-intellisense-1.5.1/vendor/sabre/event/lib/Promise.php(242): LanguageServer\Server\TextDocument->LanguageServer\Server\{closure}(Object(LanguageServer\PhpDocument))
#3 /Users/abc/.vscode/extensions/felixfbecker.php-intellisense-1.5.1/vendor/sabre/event/lib/Loop/Loop.php(261): Sabre\Event\Promise->Sabre\Event\{closure}()
#4 /Users/abc/.vscode/extensions/felixfbecker.php-intellisense-1.5.1/vendor/sabre/event/lib/Loop/Loop.php(215): Sabre\Event\Loop\Loop->runNextTicks()
#5 /Users/abc/.vscode/extensions/felixfbecker.php-intellisense-1.5.1/vendor/sabre/event/lib/Loop/Loop.php(194): Sabre\Event\Loop\Loop->tick(true)
#6 /Users/abc/.vscode/extensions/felixfbecker.php-intellisense-1.5.1/vendor/sabre/event/lib/Loop/functions.php(122): Sabre\Event\Loop\Loop->run()
#7 /Users/abc/.vscode/extensions/felixfbecker.php-intellisense-1.5.1/vendor/felixfbecker/language-server/bin/php-language-server.php(102): Sabre\Event\Loop\run()
#8 {main}
  Code: -32603

edit:
if you put a ?> at the end of the file, formatting the file doesn't throw an error, removes the ?> and throws an error the next time you hit format. Not sure if that informations helps, though

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.

3 participants