vue-keyword.vim 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. function! s:GetIndent()
  2. let config = vue#GetConfig('config', {})
  3. let enable_initial_indent = 0
  4. for val in config.initial_indent
  5. if val =~ 'script'
  6. let enable_initial_indent = 1
  7. endif
  8. endfor
  9. let indent = &sw * (1 + enable_initial_indent)
  10. return indent
  11. endfunction
  12. function! s:GetMatchOption()
  13. " Currently support https://github.com/pangloss/vim-javascript
  14. let useJavaScriptPlugin = hlexists('jsAsyncKeyword')
  15. if useJavaScriptPlugin
  16. let containedin = 'jsObject,jsFuncBlock,@jsExpression'
  17. else
  18. " Just to avoid error from the containedin pattern
  19. syntax match javascriptScriptBlock /javascriptScriptBlock/
  20. let containedin = '.*ScriptBlock'
  21. endif
  22. let containedin .= ',typescriptIdentifierName'
  23. let contains = useJavaScriptPlugin
  24. \? 'jsAsyncKeyword'
  25. \: 'javaScriptReserved'
  26. let match_option =
  27. \' containedin='.containedin
  28. \.' contains='.contains
  29. \.' skipwhite skipempty'
  30. return match_option
  31. endfunction
  32. " Vue keywords as option key
  33. let s:vue_keywords = 'name parent functional delimiters comments components directives filters extends mixins inheritAttrs model props propsData data computed watch methods template render renderError inject provide beforeCreate created beforeMount mounted beforeUpdate updated activated deactivated beforeDestroy destroyed setup beforeUnmount unmounted errorCaptured renderTracked renderTriggered'
  34. let s:indent = s:GetIndent()
  35. let s:keywords_regexp = '\v^\s{'.s:indent.'}(async )?<('
  36. \.join(split(s:vue_keywords, ' '), '|')
  37. \.')\ze'
  38. let s:match_option = s:GetMatchOption()
  39. execute 'syntax match vueObjectKey display /'
  40. \.s:keywords_regexp
  41. \.'\s*:/'
  42. \.s:match_option
  43. \.' nextgroup=jsObjectValue'
  44. execute 'syntax match vueObjectFuncName display /'
  45. \.s:keywords_regexp
  46. \.'\_s*\(/'
  47. \.s:match_option
  48. \.' nextgroup=jsFuncArgs'
  49. execute 'syntax match vueObjectFuncKey display /'
  50. \.s:keywords_regexp
  51. \.'\s*:\s*function>/'
  52. \.s:match_option
  53. \.' nextgroup=jsFuncArgs'
  54. " Vue3 keywords as API, https://v3.vuejs.org/api/
  55. let s:basic_reactive = 'reactive readonly isProxy isReactive isReadonly toRaw markRaw shallowReactive shallowReadonly'
  56. let s:refs = 'ref unref toRef toRefs isRef customRef shallowRef triggerRef'
  57. let s:computed_and_watch = 'computed watchEffect watchPostEffect watchSyncEffect watch'
  58. let s:composition = 'setup onBeforeMount onMounted onBeforeUpdate onUpdated onBeforeUnmount onUnmounted onErrorCaptured onRenderTracked onRenderTriggered onActivated onDeactivated getCurrentInstance InjectionKey provide inject'
  59. let s:global = 'createApp h defineComponent defineAsyncComponent defineCustomElement resolveComponent resolveDynamicComponent resolveDirective withDirectives createRenderer nextTick mergeProps useCssModule'
  60. let s:vue3_keywords = join([s:basic_reactive, s:refs, s:computed_and_watch, s:composition, s:global], ' ')
  61. let s:vue3_keywords_regexp = '\v<('
  62. \.join(split(s:vue3_keywords, ' '), '|')
  63. \.')\ze'
  64. execute 'syntax match vue3Keyword display /'
  65. \.s:vue3_keywords_regexp
  66. \.'\_s*\(/'
  67. \.s:match_option
  68. highlight default link vueObjectKey vueObjectKeyword
  69. highlight default link vueObjectFuncName vueObjectKeyword
  70. highlight default link vue3Keyword vueObjectKeyword
  71. highlight default link vueObjectFuncKey vueObjectKeyword
  72. highlight default link vueObjectKeyword Type