Skip to content

[SQL] Add default SQL syntax selector command #4279

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

deathaxe
Copy link
Collaborator

@deathaxe deathaxe commented May 30, 2025

This PR adds a naive command for users to choose default SQL dialect to be assigned to source.sql.

grafik

The sql_set_default_syntax basically works for any syntax, but is prefixed sql_ as it is located in and dedicated to SQL syntax package.

Alternatively a general purpose set_default_syntax could be implemented by ST core or Default package.

Ideally, dialect syntaxes could be identified by attributes in Syntax() class, but until this becomes true, rely on a static list of files specified via dialect_file argument to choose from.

FWIW, Right now SQL seems to be the only use case for what is called a "dialect".

This commit adds a naive command for users to choose default SQL dialect
to be assigned to `source.sql`.

The `sql_set_default_syntax` basically works for any syntax, but is prefixed
`sql_` as it is located in and dedicated to SQL syntax package.

Alternatively a general purpose `set_default_syntax` could be implemented
by ST core or Default package.

Ideally, dialect syntaxes could be identified by attributes in `Syntax()` class,
but until this becomes true, rely on a static list of files specified via
`dialect_file` argument to choose from.
@deathaxe deathaxe force-pushed the pr/sql/add-dialect-chooser branch from 2f27ffd to 01634dd Compare May 30, 2025 15:45
@predragnikolic
Copy link

If I have a *.sql file open,
and I would like to specify a dialect for that file,
intuitively I would look in the command palette to see if it offers Set Syntax: SQL (MySQL) or Set Syntax: SQL (PostgreSQL).

@deathaxe
Copy link
Collaborator Author

deathaxe commented Jun 13, 2025

You can do so and even assign *.sql extension to any of MySQL, PostgreSQL or T-SQL.

Syntax names like <Name> (<Base>) denote extended syntaxes based on another. That's not really the case here, because SQL is by default just an alias for MySQL, which can be changed to anything. All dialects are based on SQL (basic) (yes it violates given scheme above).

The point of this PR and provided command is to be able to specify the SQL syntax/dialect to use in syntax highlighted strings of Python, PHP, ... as those don't provide any other way to do so - and just embed source.sql.

That being said, we could hide "SQL" syntax and just assign *.sql extension to MySQL by default - somewhat following the scheme of ShellScript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants