Skip to content

Conversation

@jparise
Copy link
Owner

@jparise jparise commented Oct 4, 2020

When we're within a template string, it's common for the author to
indent the GraphQL syntax some level beyond the outer scope.

Attempt to honor that initial indentation by looking for the first line
of GraphQL syntax and telling vim to leave its indentation untouched
(-1). The following lines will be indentation relative to this initial
line.

Fixes #54

When we're within a template string, it's common for the author to
indent the GraphQL syntax some level beyond the outer scope.

Attempt to honor that initial indentation by looking for the first line
of GraphQL syntax and telling vim to leave its indentation untouched
(-1). The following lines will be indentation relative to this initial
line.
@jparise
Copy link
Owner Author

jparise commented Oct 4, 2020

@rsslldnphy this should hopefully address the issue you reported. It's not the most elegant solution, but I couldn't come up with another way to honor the initial "user-defined" indentation within a template string.

@jparise jparise merged commit 5f5bf0f into master Oct 4, 2020
@jparise jparise deleted the indent-previous branch October 4, 2020 17:09
@rsslldnphy
Copy link

Thanks for this @jparise! I can confirm it works 🎉 . one thing i've spotted, and i'm not sure whether this is vim-graphql or a clash with something else in my setup, but the extra indendation seems to be being applied to the closing ` as well as the lines below it. so when i indent the whole of this (already correctly indented) file:

import gql from 'graphql-tag';

export default gql`
  fragment Foo on Bar {
    id
    baz
  }
`;

export const unrelated = 3;

what i end up with is this:

import gql from 'graphql-tag';

export default gql`
  fragment Foo on Bar {
    id
    baz
  }
  `;

  export const unrelated = 3;

As I say it could be something in my vim setup, I've removed most plugins from it and just left vim-graphl, but there could still be something going on there. I'll see if I can figure it out - if it works for you then I'm sure it must be something I've done!

@jparise
Copy link
Owner Author

jparise commented Oct 4, 2020

@rsslldnphy yes, I've noticed that, too. It appears to be something specific to the TypeScript syntax and not something I'm doing (or not doing). This is further confirmed by 28869c2 and the fact that the JavaScript syntax works fine in this regard.

I noticed the TypeScript syntax (shipped with vim) sets different indent flags from the JavaScript syntax. For example, JavaScript sets autoindent while TypeScript doesn't but provides its own formatexpr.

If you discover anything that might inform what I could be doing in this GraphQL plugin, please let me know.

@rsslldnphy
Copy link

thanks - will do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Queries in template literals have leading spaces stripped away on indent

3 participants