amir9480 / vscode-laravel-extra-intellisense

This extension adds extra autocompletion for laravel projects to VSCode.
https://marketplace.visualstudio.com/items?itemName=amiralizadeh9480.laravel-extra-intellisense
MIT License
3.39k stars 54 forks source link

Triggers Constant Laravel Errors #9

Closed mikebronner closed 5 years ago

mikebronner commented 5 years ago

It looks like this extension is making constant requests to the app through PHP. This is triggering a constant deluge of application errors, as the extension is not tenant-aware, and does not execute its requests through the necessary Laravel middleware that determines the active tenant.

I would not expect VSCode plugins to make PHP requests to my application in order to understand them, but rather to run their own internal language server (if necessary), and parse the files in the directories as needed, to get more information.

As this stands now, I am unable to use this plugin because of this issue.

amir9480 commented 5 years ago

I get Laravel application information like all routes, views namespaces, translation namespaces, all configs using raw PHP codes. So if there is some easier and better way to do these, please let me know.

For example, I using this code to get Laravel routes.

define('LARAVEL_START', microtime(true));
require_once  __DIR__."/../vendor/autoload.php";
require_once __DIR__."/../bootstrap/app.php";
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle($request = Illuminate\Http\Request::capture());

echo json_encode(
    array_map(
        function ($route) {
            return [
                'method' => implode('|', array_filter($route->methods(), function ($method) {
                    return $method != 'HEAD';
                })),
                'uri' => $route->uri(),
                'name' => $route->getName(),
                'action' => str_replace('App\\Http\\Controllers\\', '', $route->getActionName()),
                'parameters' => $route->parameterNames()
            ];
        },
        app('router')->getRoutes()->getRoutes()
    )
);

Should I provide some option to load information manually using some status bar button instead of automatically load information on saving files? Something like this extension to load CSS classes. IntelliSense for CSS class names in HTML

mikebronner commented 5 years ago

Hi @amir9480, I think the core problem is that you are using the application itself to get the desired information. I understand that that approach provides an easy way to get the items from the CoI in Laravel, but that brings with it the problems that the middleware are not run.

Perhaps if you could run all middleware as well, it might not be an issue. Do you think that is doable?

In my specific instance, middleware sets up the database connection for my multi-tenant clients, and many other middleware provided by packages will also update the CoI and provide more accurate information for your plugin. Do you think that would be doable?

amir9480 commented 5 years ago

Hello. Thanks for helping me to fix this issue and sorry for my low English knowledge. I used Laravel's source to boot up Laravel and only removed this part of the code:

$response->send();
$kernel->terminate($request, $response);

To prevent website home output and instead, I used my own code to write the output. If you test that code I sent before, You can see all defined middlewares for the home route will run. Do you think if I use artisan code instead will fix this issue or not?

Do you think that would be doable?

If it's possible to write Single-File PHP code to do that and get desired information as JSON output, then I can use that code for the extension. I would appreciate if you help me to do this.

mikebronner commented 5 years ago

@amir9480 I'm not sure. I guess another problem with multi-tenancy projects is that they are URL-aware, and perhaps because no URL is defined, that's why the plugin is not working for me. What URL do you use to make the request in your plugin? Perhaps I can configure the URL you use in your plugin with my app.

amir9480 commented 5 years ago

@mikebronner I do not use any special URL because I use php -r 'code' command so Laravel will load home route (root route) (test.local/). I guess this happens because route / in your application throws an exception.

Please update to version 0.1.7 and if still, the problem exists let me know. If php artisan route:list works then I think this will also work. I tried boot Laravel CLI instead of Http to ignore any error in root route.

mikebronner commented 5 years ago

Sorry for taking so long to follow up. I'm not seeing any errors now. I will continue testing. :) Thanks!

jzpeepz commented 5 years ago

I am experiencing a similar scenario when using the extension. I get the following error:

Symfony\Component\Debug\Exception\FatalErrorException Uncaught Error: Call to undefined method Illuminate\Translation\FileLoader::namespaces() in Command line code:1 Stack trace:

0 {main}

thrown Command line code:1 Symfony\Component\Debug\Exception\FatalErrorException::__construct /Users/jonathan/Code/project/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:132 Illuminate\Foundation\Bootstrap\HandleExceptions::fatalExceptionFromError /Users/jonathan/Code/project/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:118 Illuminate\Foundation\Bootstrap\HandleExceptions::handleShutdown /Users/jonathan/Code/project/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php [main]

amir9480 commented 5 years ago

@jzpeepz Hello. Which Laravel version exactly you use? I using FileLoader::namespaces() to dectect translation namespaces for translation autocomplete.

jzpeepz commented 5 years ago

I have seen this happen in both Laravel 5.1 and 5.3 projects.

On Fri, Aug 30, 2019, 5:48 AM amir notifications@github.com wrote:

@jzpeepz https://github.com/jzpeepz Hello. Which Laravel version exactly you use? I using FileLoader::namespaces() to dectect translation namespaces for translation autocomplete.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/amir9480/vscode-laravel-extra-intellisense/issues/9?email_source=notifications&email_token=AAADRRVEERQR4UKELHPXZ6LQHD3HZA5CNFSM4HZMQA72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5RJ2HY#issuecomment-526556447, or mute the thread https://github.com/notifications/unsubscribe-auth/AAADRRQKPO5AYGW62MY2TTLQHD3HZANCNFSM4HZMQA7Q .

amir9480 commented 5 years ago

@jzpeepz Sorry. That's too old. But i gonna remove auto-retry after any error happens.

jzpeepz commented 5 years ago

@amir9480 That would be good enough. I don't really expect it to work in older projects, but it would be nice if it didn't fill up my logs with errors. :)

I appreciate how helpful and responsive you have been on this issue!

amir9480 commented 5 years ago

@jzpeepz It's a good idea to disable logging when running application from the extension. After some research around the web, I found a way to disable logger and hope it works in laravel 5.3.

class VscodeLaravelExtraIntellisenseProvider extends \Illuminate\Support\ServiceProvider
{
    public function boot()
    {
        $this->app['log']->setHandlers([new \Monolog\Handler\NullHandler()]);
    }
}

$app->register(new VscodeLaravelExtraIntellisenseProvider($app));

Please check out version 0.2.2. This code will not works if there are errors in service providers but errors in routes or somewhere else will be handled.