1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-13 02:05:40 +08:00

Add more key bindings for tsx file (#4043)

This commit is contained in:
Wang Shidong 2021-02-10 10:23:38 +08:00 committed by GitHub
parent 5c74535428
commit 0b77e2279d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 24 deletions

View File

@ -44,12 +44,16 @@ function! SpaceVim#layers#lang#typescript#config() abort
augroup SpaceVim_lang_typescript augroup SpaceVim_lang_typescript
autocmd! autocmd!
autocmd FileType typescript setlocal omnifunc=tsuquyomi#complete autocmd FileType typescript setlocal omnifunc=tsuquyomi#complete
" Does tsuquyomi support tsx file?
autocmd FileType typescriptreact setlocal omnifunc=tsuquyomi#complete
augroup END augroup END
endif endif
call SpaceVim#mapping#gd#add('typescript', 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', 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#repl#reg('typescript', ['ts-node', '-i'])
call SpaceVim#plugins#runner#reg_runner('typescript', { call SpaceVim#plugins#runner#reg_runner('typescript', {
\ 'exe' : 'ts-node', \ 'exe' : 'ts-node',
@ -57,6 +61,13 @@ function! SpaceVim#layers#lang#typescript#config() abort
\ 'opt': [], \ 'opt': [],
\ }) \ })
let g:neomake_typescript_enabled_makers = ['eslint'] 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 endfunction
function! SpaceVim#layers#lang#typescript#set_variable(var) abort 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 let g:tsuquyomi_tsserver_path = tsserver_path
endif endif
endif endif
let g:jsdoc_lehre_path = get(a:var, 'lehre_path', 'lehre')
endfunction endfunction
function! s:on_ft() abort function! s:on_typescript_ft() abort
if SpaceVim#layers#lsp#check_filetype('typescript') if SpaceVim#layers#lsp#check_filetype('typescript')
nnoremap <silent><buffer> K :call SpaceVim#lsp#show_doc()<CR> nnoremap <silent><buffer> K :call SpaceVim#lsp#show_doc()<CR>
@ -136,7 +148,7 @@ function! s:on_ft() abort
endfunction endfunction
function! s:go_to_def() abort function! s:go_to_typescript_def() abort
if !SpaceVim#layers#lsp#check_filetype('typescript') if !SpaceVim#layers#lsp#check_filetype('typescript')
if has('nvim') if has('nvim')
TSDef TSDef
@ -147,3 +159,14 @@ function! s:go_to_def() abort
call SpaceVim#lsp#go_to_def() call SpaceVim#lsp#go_to_def()
endif endif
endfunction 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

View File

@ -8,9 +8,8 @@ description: "This layer is for TypeScript development, includding code completi
<!-- vim-markdown-toc GFM --> <!-- vim-markdown-toc GFM -->
- [Description](#description) - [Description](#description)
- [Install](#install) - [Installation](#installation)
- [Features](#features) - [Layer options](#layer-options)
- [Layer configuration](#layer-configuration)
- [Key bindings](#key-bindings) - [Key bindings](#key-bindings)
- [Code runner](#code-runner) - [Code runner](#code-runner)
- [Inferior REPL process](#inferior-repl-process) - [Inferior REPL process](#inferior-repl-process)
@ -19,9 +18,9 @@ description: "This layer is for TypeScript development, includding code completi
## Description ## 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: 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" 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 - `typescript_server_path`: set the path of the tsserver.
- syntax checking - `lehre_path`: set the path of lehre
- viewing documentation
- type-signature
- goto definition
- refernce finder
- lsp support
## Layer configuration
`typescript_server_path`: set the path of the tsserver.
## Key bindings ## Key bindings