GithubHelp home page GithubHelp logo

Indent parsed incorrectly about sqldelight HOT 6 CLOSED

cashapp avatar cashapp commented on August 21, 2024
Indent parsed incorrectly

from sqldelight.

Comments (6)

JakeWharton avatar JakeWharton commented on August 21, 2024

interesting cases:

foo:
  SELECT *
    FROM foo
foo:
   SELECT *
     FROM foo
LEFT JOIN bar
foo:
SELECT *
FROM foo

from sqldelight.

JakeWharton avatar JakeWharton commented on August 21, 2024

I think the only reasonable policy here is to discourage indentation on lines following a name and preserve it on every line of the query.

So the above examples change to:

foo:
SELECT *
  FROM foo
foo:
   SELECT *
     FROM foo
LEFT JOIN bar
foo:
SELECT *
FROM foo

from sqldelight.

JakeWharton avatar JakeWharton commented on August 21, 2024

and we can use syntax highlighting to visually distinguish label names from query syntax

from sqldelight.

AlecKazakova avatar AlecKazakova commented on August 21, 2024

actually preserving the spaces in front of the first SELECT is tricky. Both the gradle plugin and intellij just copy the text from start index to stop index. Ideally theres a way to grab text via line numbers. I'll see how far I can get with that. It's actually all the lines EXCEPT the first are indented properly.

Pretty related to what you've been mentioning is #1 . Once we decide on how to format the queries, how does the formatter come into play? More specifically, what happens if I have SELECT * and then hit enter. Does the cursor go right below the T, or does it go to the beginning of the new line?

I agree with the formatting you're suggesting though, where the longest keyword is fully left aligned and then everything else is right aligned with the longest keyword. As for the formatter easiest and most user friendly is probably just to do nothing while they're typing and then align things when they actually run the formatter.

Also, wouldn't the last case format to the same as the first case?

from sqldelight.

JakeWharton avatar JakeWharton commented on August 21, 2024

If you applied formatting on the whole file then yes they should end up the same. For this issue I was only thinking about how the indentation was copied to the source's string literal in those two cases.

from sqldelight.

JakeWharton avatar JakeWharton commented on August 21, 2024

Recommendation is: left-align your things in some way.

SELECT *
FROM table
WHERE things

or when it gets big:

SELECT
  column,
  another,
  more
FROM
  table,
  chair,
  desk
WHERE
  things AND
  more things AND
  all the things
GROUP BY
  everything

from sqldelight.

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.