diff --git a/autoload/SpaceVim/layers/lang/typescript.vim b/autoload/SpaceVim/layers/lang/typescript.vim index 964024726..a3462d9ac 100644 --- a/autoload/SpaceVim/layers/lang/typescript.vim +++ b/autoload/SpaceVim/layers/lang/typescript.vim @@ -44,12 +44,16 @@ function! SpaceVim#layers#lang#typescript#config() abort augroup SpaceVim_lang_typescript autocmd! autocmd FileType typescript setlocal omnifunc=tsuquyomi#complete + " Does tsuquyomi support tsx file? + autocmd FileType typescriptreact setlocal omnifunc=tsuquyomi#complete augroup END endif call SpaceVim#mapping#gd#add('typescript', - \ function('s:go_to_def')) + \ function('s:go_to_typescript_def')) + call SpaceVim#mapping#gd#add('typescriptreact', + \ function('s:go_to_typescriptreact_def')) call SpaceVim#mapping#space#regesit_lang_mappings('typescript', - \ function('s:on_ft')) + \ function('s:on_typescript_ft')) call SpaceVim#plugins#repl#reg('typescript', ['ts-node', '-i']) call SpaceVim#plugins#runner#reg_runner('typescript', { \ 'exe' : 'ts-node', @@ -57,6 +61,13 @@ function! SpaceVim#layers#lang#typescript#config() abort \ 'opt': [], \ }) let g:neomake_typescript_enabled_makers = ['eslint'] + " does eslint support tsx? + let g:neoformat_typescriptreact_prettier = { + \ 'exe': 'prettier', + \ 'args': ['--stdin', '--stdin-filepath', '"%:p"', '--parser', 'typescript'], + \ 'stdin': 1 + \ } + let g:neoformat_enabled_typescriptreact = ['prettier'] endfunction function! SpaceVim#layers#lang#typescript#set_variable(var) abort @@ -71,9 +82,10 @@ function! SpaceVim#layers#lang#typescript#set_variable(var) abort let g:tsuquyomi_tsserver_path = tsserver_path endif endif + let g:jsdoc_lehre_path = get(a:var, 'lehre_path', 'lehre') endfunction -function! s:on_ft() abort +function! s:on_typescript_ft() abort if SpaceVim#layers#lsp#check_filetype('typescript') nnoremap K :call SpaceVim#lsp#show_doc() @@ -136,7 +148,7 @@ function! s:on_ft() abort endfunction -function! s:go_to_def() abort +function! s:go_to_typescript_def() abort if !SpaceVim#layers#lsp#check_filetype('typescript') if has('nvim') TSDef @@ -147,3 +159,14 @@ function! s:go_to_def() abort call SpaceVim#lsp#go_to_def() endif endfunction +function! s:go_to_typescriptreact_def() abort + if !SpaceVim#layers#lsp#check_filetype('typescriptreact') + if has('nvim') + TSDef + else + call SpaceVim#lsp#go_to_def() + endif + else + call SpaceVim#lsp#go_to_def() + endif +endfunction diff --git a/docs/layers/lang/typescript.md b/docs/layers/lang/typescript.md index ec01b3b6e..f1f5c4665 100644 --- a/docs/layers/lang/typescript.md +++ b/docs/layers/lang/typescript.md @@ -8,9 +8,8 @@ description: "This layer is for TypeScript development, includding code completi - [Description](#description) -- [Install](#install) -- [Features](#features) -- [Layer configuration](#layer-configuration) +- [Installation](#installation) +- [Layer options](#layer-options) - [Key bindings](#key-bindings) - [Code runner](#code-runner) - [Inferior REPL process](#inferior-repl-process) @@ -19,9 +18,9 @@ description: "This layer is for TypeScript development, includding code completi ## Description -This layer is for TypeScript development, includding code completion, Syntax lint and doc generation. +This layer is for TypeScript development, includding code completion, syntax lint and doc generation. -## Install +## Installation To use this configuration layer, update custom configuration file with: @@ -30,25 +29,16 @@ To use this configuration layer, update custom configuration file with: name = "lang#typescript" ``` -BTW, you need to install TypeScript via: +To generate doc of typescript file, you need to install [lehre](https://www.npmjs.com/package/lehre) -```sh -npm install -g typescript +``` +yarn add -D lehre ``` -## Features +## Layer options -- auto-completion -- syntax checking -- viewing documentation -- type-signature -- goto definition -- refernce finder -- lsp support - -## Layer configuration - -`typescript_server_path`: set the path of the tsserver. +- `typescript_server_path`: set the path of the tsserver. +- `lehre_path`: set the path of lehre ## Key bindings