sqlfluff / vscode-sqlfluff

An extension to use the sqlfluff linter in vscode.
https://marketplace.visualstudio.com/items?itemName=dorzey.vscode-sqlfluff
MIT License
156 stars 33 forks source link

Auto Detect SqlFlulf executable from Python Virtual Environment #146

Open aaronclong opened 4 months ago

aaronclong commented 4 months ago

Background


Hard coding executable paths into settings.json makes the config completely unportable. People will have different operating systems, and even different folder structures depending how things are installed.

Defining a path variable would also be cumbersome.

It should be noted that different repos might even use different versions, further complicating this practice.

This all came from Issue 133.

Suggestion


It would be nice if the config could specify a dependencyManager and directory. The extension could load this.

settings.json

"sqlfluff.dependencyManager": "poetry",
"sqlfluff.projectRoot": "${workspace}/path"

Then the linter provider could spawn a child process and get exec from there.

With poetry, you can dynamically fetch the path from this poetry run which sqlfluff.

image
const { exec } = require('child_process');
return new Promise((resolve, reject) => {
  exec('poetry run which sqlfluff', (error, stdout, stderr) => {
     if (error || stderr) {
        reject(error || stderr);
        return;
     }

    resolve(stdout)
  });
});

In addition, this extension could talk to the Microsoft Python extension and get the virtual environment.

It is defiantly more complex. However, it allows for easy changes to the environment.

https://github.com/microsoft/vscode-python/blob/main/src/client/api.ts#L150C9-L150C21 https://stackoverflow.com/questions/50058517/how-to-communicate-between-vscode-extensions/50068416#50068416

aaronclong commented 4 months ago

There doesn't seem to any appetite by the maintainers for addressing these issues (totally fair).

For people struggling with this, I've noticed some over lap with Issue #18.

Likewise, there seems to be an alternative extension, vscode-dbt-power-user, that might better resolve these issues for the time being. However, it doesn't seem to be a true linter

Here are some discussions I found around the issue here:

https://github.com/AltimateAI/vscode-dbt-power-user/issues/3#issuecomment-747652228

https://github.com/AltimateAI/vscode-dbt-power-user/issues/3#issuecomment-747671447

https://github.com/sqlfluff/vscode-sqlfluff/issues/18