Git Product home page Git Product logo

Comments (8)

PhilippSalvisberg avatar PhilippSalvisberg commented on July 23, 2024 1

If you do not want to have a line break before using you have to uncheck the option Line Breaks -> On ANSI joins as in the following screen shot:

image

To align the table aliases you have to check additionally the option Alignment -> Column and Table aliases as in the next screenshot:

image

There is no option to align the USING keywords when Line Breaks -> On ANSI joins is unchecked.

Please note that you need to terminate the SQL statements with ; if you want to format multiple statements.

from plsql-formatter-settings.

PhilippSalvisberg avatar PhilippSalvisberg commented on July 23, 2024 1

(...) Is there maybe a way to enable multi- to single-line formating?

Yes, of course. One option is to use the original formatter settings provided by the SQLDev team. Their settings configure a heavyweight formatter. This means the whitespace between tokens is not preserved (beside some exceptions) and therefore the formatter result will always look the same. If you are not happy with the formatter result you can contact the SQLDev team via the SQLDev forum or open a SR on MOS.

Another option is to amend the Arbori program provided in this repository. For that it's probably the easiest to fork this repository. A quick but incomplete hack would be to change the section I7 on line 890. Change wsBefore to " ". This will enforce a single space between all tokens. The problem is, that you do not really want that. You want to preserve some line breaks, e.g. those before the join keyword in your example. When the option Line Breaks On ANSI joins is unchecked there will be no line breaks before join nor using. Furthermore a lot of other statements will be badly formatted, e.g. create table statements. Basically every statement which the lightweight formatter keeps mostly "as is". So this change will completely break the lightweight formatter. But of course you can change the formatter settings further to exactly produce the result you want.

Yet another approach is to change the behavior of the option Line Breaks On ANSI joins. You find the relevant code by searching for breakAnsiiJoin which is a boolean variable representing the checkbox for this option. You might want to change the Arbori query o10_join_clause_keywords. Commenting out line 2397 might be a simple solution to avoid line breaks before the using keyword even when Line Breaks On ANSI joins is enabled.

In any case, we do not plan to make such changes in our formatter settings.

Is there a way to align all "using" after the aliases / table names?

Yes, of course. One option is to harmonize the length of the table aliases. In your example change advp to at and voilà the using keyword is automatically aligned.

Another option is to add a formatter section which explicitly aligns the using keyword. It will be similar to the code section O5: Alignment: Column and Table aliases. Options: true; false. (alignTabColAliases). You find the the nodes to be aligned with the following Arbori query:

using_nodes: 
     [scope) from_clause
   & [node) on_using_condition
   & scope < node
;

Similar as with column aliases and table aliases, you have to make sure that each using keyword is on a dedicated line, otherwise the alignment will produce a mess. The logic for that is also implemented in section O5. You have to copy and amend it accordingly.

In any case, we do not plan to make such changes in our formatter settings.

from plsql-formatter-settings.

PhilippSalvisberg avatar PhilippSalvisberg commented on July 23, 2024

closing due to inactivity.

from plsql-formatter-settings.

chatelao avatar chatelao commented on July 23, 2024

Thanks for the explanation. The "col/tab alias" part works great.

The "ANSI" Join part works not so well:

  • Converting short (single line) to long (multi lines) works.
  • Converting long (multi lines) to short (single line) doesn't works.

n.b.: My inactivity was due to the nice thing called holidays :-)

from plsql-formatter-settings.

PhilippSalvisberg avatar PhilippSalvisberg commented on July 23, 2024

Converting long (multi lines) to short (single line) doesn't works.

This is intended. See https://github.com/Trivadis/plsql-formatter-settings#nice-to-know .

from plsql-formatter-settings.

chatelao avatar chatelao commented on July 23, 2024

Okay - I didn't see it in the "nice tto know" - Is there maybe a way to enable multi- to single-line formating?

n.b.: Thanks again for the helpful hints, I think the alias-align will help me and the "using" stuff will be fine.

from plsql-formatter-settings.

chatelao avatar chatelao commented on July 23, 2024

Is there a way to align all "using" after the aliases / table names?

image

from plsql-formatter-settings.

chatelao avatar chatelao commented on July 23, 2024

Thank you for all the helpful hints to improve my workflow

from plsql-formatter-settings.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.