Closed jparise closed 3 years ago
@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.
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!
@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 28869c2c334ffea1576366234abaf50246125185 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.
thanks - will do!
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