tinkerwellapp / drivers

All available Tinkerwell drivers
https://tinkerwell.app
MIT License
83 stars 34 forks source link

`contextMenu()` is ignored in custom driver #6

Open maks-rafalko opened 4 years ago

maks-rafalko commented 4 years ago

With the following code:

final class InfectionTinkerwellDriver extends TinkerwellDriver
{
    public function canBootstrap($projectPath)
    {
        var_dump('canBootstrap');

        return file_exists($projectPath . '/bin/infection');
    }

    public function bootstrap($projectPath)
    {
        var_dump('bootstrap');
        require_once $projectPath . '/vendor/autoload.php';
    }

    public function getAvailableVariables()
    {
        var_dump('getAvailableVariables');
        return [
            'container' => Container::create(),
        ];
    }

    public function contextMenu()
    {
        var_dump('Detected Infection');
        return [
            Label::create('Detected Infection'),
        ];
    }
}

when I run the empty script on Tinkerwell, it get:

Tinkerwell - infection 2020-01-26 02-00-27

So you can see that contextMenu is ignored and I don't see any new context menu items in the app.

mpociot commented 4 years ago

The context menu method is not being used in the execution of your script, but it only gets called once when you open your project folder. So you can not see any output there. Also make sure not to dump anything in the context menu method as its execution needs to return valid json.

Did you import the label class use statement?

maks-rafalko commented 4 years ago

Yes I did, see the full code here https://github.com/tinkerwellapp/drivers/pull/7/files

I tried restart the app, reopen the folder but nothing helps, unfortunately. Is there any way to debug it?

nikolov-tmw commented 4 years ago

I can confirm the same thing happening for me too. I logged to a file to make sure that contextMenu gets called and below is a var_export of what I'm returning from the method:

array (
  0 => 
  Tinkerwell\ContextMenu\Label::__set_state(array(
     'label' => 'Detected Wordpress v',
  )),
  1 => 
  Tinkerwell\ContextMenu\SetCode::__set_state(array(
     'label' => 'Test',
     'code' => 'Company::find( 302 )',
  )),
)

Seems good to me, yet I get nothing in the context menu:

Screenshot from 2020-01-30 19-02-00

However, loading the default Laravel app, the context menu is populated correctly. So it has to be a problem in the project I'm working on perhaps. Any ideas as to what might be happening?

mpociot commented 4 years ago

I think this was an issue with an older version of Tinkerwell. I can not reproduce the error - could you please verify that it still exists with the latest (2.1.1) version?

nikolov-tmw commented 4 years ago

Installed 2.1.1 and same thing is still happening.

Are there any command line options I can pass to the binary to see some debugging information? Right now if I run tinkerwell from a terminal, I see a couple of lines of debug information(checking for updates and such), but nothing when I select a project directory or run commands.

tjespers commented 4 years ago

@mpociot I can verify that i'm still having this issue in 2.2.0 as well

leek commented 4 years ago

Still seeing this issue with 2.2.1.

nikolov-tmw commented 4 years ago

Following up on this with one additional detail(aside from still having the same issue in 2.4.0) - some helper functions like dd are undefined in my tinkerwell session for some reason(while they are available in general and in regular tinker). Not sure if that's helpful in any way or not.

trizz commented 4 years ago

In 2.7.0 (with a remote connection, if that makes any difference) I also do not see the context menu. My code in bootstrap is executed, so it is using my custom driver.

Juje commented 3 years ago

I'm not sure if it helps for replication @mpociot but the contextMenu seems only to get called every once in a while but if you have multiple tabs open then it will hold the result of one of the tabs you had opened up when it gathered new data.

In other words I have 2 tabs 1 is a Laravel install and the other is a WordPress install. On boot my Laravel install was opened and I see the Laravel details but when I go to the WordPress install I still see the Laravel info.

FluffyMatt commented 3 years ago

I have this issue also on version 2.15.0 using a custom driver for Laravel.

I'm able to run Artisan commands but the context menu looks like the below Screenshot 2021-09-10 at 11 38 37

The contextMenu method is as follows

public function contextMenu()
    {
        return [
            Label::create('Detected Laravel v' . app()->version()),

            Submenu::create('Artisan', collect(Artisan::all())->map(function ($command, $key) {
                return SetCode::create($key, "Artisan::call('" . $key . "', []);\nArtisan::output();");
            })->values()->toArray()),

            OpenURL::create('Documentation', 'https://tinkerwell.app'),
        ];
    }
danielsetreus commented 2 years ago

Can confirm that this "bug" exists in version 2.18.1, extending LaravelTinkerwellDriver:

<?php

use Tinkerwell\ContextMenu\SetCode;
use Tinkerwell\ContextMenu\Label;
use Tinkerwell\ContextMenu\OpenURL;
use Tinkerwell\ContextMenu\Submenu;

class CompanyTinkerwellDriver extends LaravelTinkerwellDriver
{

    public function canBootstrap($projectPath)
    {
        ...
    }

    public function bootstrap($projectPath)
    {
        ...
    }

    public function contextMenu(): array
    {
        return array_merge(parent::contextMenu(), [
            Label::create('Detected Laravel v' . app()->version()),

            Submenu::create('Snippets', [
                SetCode::create('Perform Query', '\DB::table("example")->get();'),
            ]),

            OpenURL::create('Documentation', 'https://tinkerwell.app'),
        ]);
    }
}

The app bootstraps fine but the context menu remains unchanged.

Hope this can get fixed, or better documented since it would be a super useful feature for our team.

danielsetreus commented 1 year ago

Not to bump issues without reason, but I've not tested it again in verion 3.10.0 - and still can't get custom context menus to work. Would be nice to know if there is a way to debug this - or if we are doing something wrong. I think getting this to function could really make the app twice as powerful.