mtxr / SublimeText-SQLTools

SQLTools for Sublime Text 3
https://code.mteixeira.dev/SublimeText-SQLTools/
GNU General Public License v3.0
177 stars 40 forks source link

[DUDE] Code completation in *.php #199

Closed marcoas closed 5 years ago

marcoas commented 6 years ago

Hi

In the documentation is this example configuration ...

{
  "auto_complete_triggers": [
    {"selector": "text.html", "characters": "<" },
    {"selector": "source.sql", "characters": "."}
  ]
}

But can I configure it to work in any project file (*.*) Or in the project's php files (*.php)?

tkopets commented 6 years ago

Autocompletion is shown only within certain code blocks configured by setting selectors in SQLTools settings (ST: Settings). You can add additional selectors there as shown below (note the last two items in the list below):

// .......
"selectors": [
        "source.sql",
        "source.pgsql",
        "source.plpgsql.postgres",
        "source.plsql.oracle",
        "source.tsql",
        "source.php",
        "embedding.php",
    ],
// .......

However, please note that completions are not shown inside the strings (this is hardcoded and not configurable) - that was made to aviod showing completion when those are not needed, but in case of PHP this is almost always the case that you have your SQL inside a string. I will try to fix this in next SQLTools release.

tkopets commented 6 years ago

Actually, you don't need to alter your selectors, only wait for a fix in the next release. If would be of great help if you can provide a code snippet where you would expect the completion to work, but it doesn't work right now.

marcoas commented 6 years ago

In my case, I would need it to work within this code, in every PHP file type

<?php
  ...
$sqlDatos = "SELECT dps_rg1creqleg.*,
                    dps_ma1creqleg.d_req_leg,
                    dps_ma1caplica.d_aplicacion AS d_aplicacion,
                    dps_ma1creqleg.dias_validez,
                    dps_ma1cplantas.d_planta

               FROM dps_rg1creqleg JOIN dps_ma1creqleg USING( c_req_leg )
                                   JOIN dps_ma1caplica USING( c_aplicacion )
                                   JOIN dps_ma1cplantas USING( c_planta )

              WHERE dps_rg1creqleg.fecha_prox_alerta = CURDATE()  ";
 ... 
tkopets commented 6 years ago

Thanks for this code snippet, I will make the appropriate adjustments and try to make it work with your sample.

marcoas commented 6 years ago

Could it also be possible to ask for the value of the variables included in the string?

In the following example, it would be that you ask for the value of $date

<?php
  ...
$sqlDatos = "SELECT  dps_ma1creqleg.d_req_leg,
                    dps_ma1caplica.d_aplicacion AS d_aplicacion

               FROM dps_rg1creqleg 

              WHERE dps_rg1creqleg.fecha_prox_alerta = '$date'";
 ... 
marcoas commented 5 years ago

Thank You ! When will the update be available from SublimeText?