jparise / vim-graphql

A Vim plugin that provides GraphQL file detection, syntax highlighting, and indentation.
MIT License
487 stars 25 forks source link

Queries in template literals have leading spaces stripped away on indent #54

Closed rsslldnphy closed 3 years ago

rsslldnphy commented 4 years ago

Hi, I'm not sure if this is meant to happen but I'm finding that graphql in template literals is having any leading spaces stripped away on indent. I usually indent my graphql template literals by 2 spaces, but with this text:

import gql from 'graphql-tag';

export default gql`
  query OrganisationContext {
    organisation: currentOrganisation {
      id
      name
      slug
    }
  }
`;

the command gg=G results in this:

import gql from 'graphql-tag';

export default gql`
query OrganisationContext {
  organisation: currentOrganisation {
    id
    name
    slug
  }
}
`;

the query has now been shifted to the left so it's flush with the start of the line.

i've removed everything from my ~/.config/nvim/init.vim apart from:

set nocompatible
filetype plugin indent on
syntax on

call plug#begin('~/.config/nvim/vim-plug')
Plug 'jparise/vim-graphql'` 
call plug#end()

set shiftwidth=2
set tabstop=2

is this expected behaviour? examples i've seen in the docs show template literals indented by two spaces - is there a config option i'm missing? thanks!

Vim Version

NVIM v0.4.3
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/tmp/neovim-20191107-85913-1wbgqz6/neovim-0.4.3/build/config -I/tmp/neovim-20191107-85913-1wbgqz6/neovim-0.4.3/src -I/usr/local/include -I/tmp/neovim-20191107-85913-1wbgqz6/neovim-0.4.3/deps-build/include -I/usr/local/opt/gettext/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include -I/tmp/neovim-20191107-85913-1wbgqz6/neovim-0.4.3/build/src/nvim/auto -I/tmp/neovim-20191107-85913-1wbgqz6/neovim-0.4.3/build/include
Compiled by brew@Catalina.local

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.4.3/share/nvim"
jparise commented 4 years ago

@rsslldnphy it sounds like you're running into the same problem that's described in #24?

rsslldnphy commented 4 years ago

hm running into the specific behaviour mentioned in #24 but yes definitely the same in that i'm having indentation issues within template literals. hopefully a fix for one will be a fix for both!

jparise commented 4 years ago

Fixed by #58

rsslldnphy commented 4 years ago

🎉 thanks @jparise !

rsslldnphy commented 4 years ago

actually this is still happening for me in typescript files :-(

looking at the updated tests in the PR, it looks like the javascript test asserts on the indentation behaviour i would expect:

https://github.com/jparise/vim-graphql/blob/e64fba4ee17fa8dd391405982500c72d68fc50b9/test/javascript/default.vader#L35-L43

but the typescript test asserts on different behaviour (i.e. the leading spaces being stripped away):

https://github.com/jparise/vim-graphql/blob/e64fba4ee17fa8dd391405982500c72d68fc50b9/test/typescript/default.vader#L38-L46

i am not super hot on vimscript but the ts/js after/indent files look almost identical to me so not sure what might be causing it!

jparise commented 4 years ago

@rsslldnphy I don't write much TypeScript. Could you provide an example of how you think the formatting should look?

rsslldnphy commented 4 years ago

Hi @jparise , yes no problem - in this case I think it should look exactly identical to the javascript version:

Expect (propertly indented): 
   const query = gql` 
     { 
       user(id: ${uid}) { 
         firstName 
         lastName 
       } 
     } 
   `; 
jparise commented 4 years ago

Reopening this issue until we can sort out the remaining indentation problems with GraphQL syntax embedded within templates.