Minor, but highly annoying, issue with MySQL code identation

Hi all,

So, I'm having this indentation issue when editing MySQL code: any new line subsequent field in the select clause is being indented with 7 chars instead of 4. That 7 would be the size of the "select " text. Same behavior for "where ", "group by ", "order by " etc., that is, for everything that's lengthier than the indent size, 4 in my case.

I need the indent to stick to 4 no matter what. Any idea how can I do that?

Thank you,

Katy

18 comments
Comment actions Permalink

Hi. Is it in a .sql file or SQL injection in some other language?

0
Comment actions Permalink

In a .sql file.

0
Comment actions Permalink

Do you have this option enabled by any chance?

If not - then please attach a screenshot that would show how the code looks at your end.

 

0
Comment actions Permalink

That option is not active, I figured it might be involved before posting here. Bellow is the screenshot:

0
Comment actions Permalink

Could you please export your code style scheme as XML (you can do that in the gear icon menu) and share it using the following service? https://uploads.services.jetbrains.com/

0
Comment actions Permalink

Here is the upload ID: 2022_01_14_Rds19NYdscXH8r2w (file: mysql_code_style.xml).

0
Comment actions Permalink

Thank you! Strangely enough, with your code style scheme, I don't get the behavior you describe. After I

  • Disable EditorConfig at Settings | Editor | Code Style and
  • Set Settings | Editor | Code Style | SQL | MySQL, MariaDB | Queries | Common | Place clause elements on to New line

The code get formatted exactly as you want it. Please check if these changes help, and if they don't, please double-check that you have the MySQL/MariaDB dialect chosen for the file at Settings | Languages & Frameworks | SQL Dialects.

0
Comment actions Permalink

Well, with you suggestions the select clause works as I want it, but that's the only one working like that. The from, where, order by, group by now they all start from the beginning of the line instead of being indented. Now there is no automatic indentation at all. Don't know which one is worse.

0
Comment actions Permalink

Could you please clarify, what exactly starts from the beginning of the line, the clauses themselves or their elements?
On your screenshot, clauses start from the beginning of the line, I assumed that this was the desired behavior. Do you want them to be indented?

0
Comment actions Permalink

Their elements. I type where, hit ENTER, no indent on the next line. Then I hit TAB, write my first condition, hit ENTER again, I'm at the beginning of the line, again no indent. And this behavior is the same for all other clauses.

0
Comment actions Permalink

I wonder why the behavior I get is so different from yours. For me, with your code style scheme, there is indentation on Enter.

Please try the following:

  1. Close the project.
  2. Remove the .idea/codeStyles folder.
  3. Open the project and apply those changes again.

Is it any better?

0
Comment actions Permalink

Renamed the codeStyles folder and then started up PhpStorm. No difference at all, still no indenting when ENTER-ing to new line. The thing is that those settings you mentioned early did not change, they are in the same state as before renaming the folder, that is: EditorConfig unchecked and Place clause elements on = New line.

On the other hand, looking at the name of the latter setting, doesn't seem to have anything to do the elements of the clauses but with the clauses themselves, which is not my issue. My issue is the elements not being indented when hitting ENTER for a new line.

0
Comment actions Permalink

Please try settings like this:

Indent with WHERE clause will work if you write like:

where

   id = 1 and

   --here will be indent after AND (OR) on previous line.

0
Comment actions Permalink

No, it's not working, when I hit ENTER after where, there is no indentation, the cursor is at the very beginning of the line. Here are my settings:

 

Are you on Windows or Linux, btw? I am on Windows. Could that be an issue? I know PhpStorm is written mainly in Java, but I also know that many parts of it are native.

0
Comment actions Permalink

This bug is fixed in next release, please wait for the update. Until that please use 'Reformat code' action, this will align elements as expected.

0
Comment actions Permalink

That sounds good :)  Any idea of a release date for the next update? Not asking for an exact date, just a rough estimate.

Thank you.

0
Comment actions Permalink

It's about mid-end of March.

0

Please sign in to leave a comment.