styled-components / vim-styled-components

Vim bundle for http://styled-components.com based javascript files.
300 stars 24 forks source link

Typescript (.tsx/.ts) support #7

Closed victorandree closed 7 years ago

victorandree commented 7 years ago

Is it as simple as adding:

runtime! syntax/typescript.vim
runtime! syntax/tsx.vim

to relevant places, et cetera?

fleischie commented 7 years ago

Hi @victorandree is this a question? :smile:

I personally have no experiences with typescript, but am willing to help of course.

runtime! syntax/typescript.vim

will source all ex commands in the file provided. Thus if you have a syntax/typescript.vim file in your runtimepath it will be sourced. Missing files will be ignored, thus even if you have no such files, this command will not break anything. (You can set your runtimepath by using runtime! <runtimepath> syntax/typescript.vim if you wish to do so).

This was just a rather theoretical introduction on how the runtime command works and will certainly neither answer your question or solve your problem, I guess. So if you need more information or want to talk about it, I'm all ears. :smile:

victorandree commented 7 years ago

Sorry for being so short! Yes, it was a question :) I am wondering how easy it would be for this plugin to support TypeScript. I did a very quick and dirty patch according to the below. It seems to work but isn't exactly properly tested... Good enough for a pull request?

diff --git a/after/indent/styled-components.vim b/after/indent/styled-components.vim
index db2e028..c5aa231 100644
--- a/after/indent/styled-components.vim
+++ b/after/indent/styled-components.vim
@@ -6,6 +6,7 @@
 " extend javascript and jsx indentation (if available but should)
 runtime! indent/javascript.vim
 runtime! indent/jsx.vim
+runtime! indent/typescript.vim

 " store current indentexpr for later
 let b:js_jsx_indent=&indentexpr
diff --git a/after/syntax/styled-components.vim b/after/syntax/styled-components.vim
index 95b431b..1dc3b4f 100644
--- a/after/syntax/styled-components.vim
+++ b/after/syntax/styled-components.vim
@@ -17,6 +17,7 @@ endif
 " extend javascript syntax
 runtime! syntax/javascript.vim
 runtime! syntax/jsx.vim
+runtime! syntax/typescript.vim
 syntax include @CSS syntax/css.vim

diff --git a/ftdetect/javascript.vim b/ftdetect/javascript.vim
index 207556c..842325f 100644
--- a/ftdetect/javascript.vim
+++ b/ftdetect/javascript.vim
@@ -16,3 +16,5 @@ endfunction

 autocmd BufNewFile,BufRead *.js  call s:SelectStyledComponent()
 autocmd BufNewFile,BufRead *.jsx call s:SelectStyledComponent()
+autocmd BufNewFile,BufRead *.ts  call s:SelectStyledComponent()
+autocmd BufNewFile,BufRead *.tsx call s:SelectStyledComponent()
fleischie commented 7 years ago

Fundamentally the patch is ok.

The question is, whether typescript and javascript definitions (sourced via the runtime! commands) affect each other (regarding whether at all or in a specific order). I don't know typescript all too well, but will check their vim definitions out in the near future. If you like you can prepare a PR for now. :smile:

fleischie commented 7 years ago

Thanks for bringing this up. I merged your PR and will close this issue for now. I urge interested users to create a new issue, if there is something wrong with typescript-support.