goto-definition-plugin-for-react


Ⅰ. 插件描述

Goto definition pluigin for React JS written in Python

Ⅱ. 基本信息

创建日期:  2018-06-02
使用用户:  1
Github星:  14
插件作者:  Ivaylo Donchev

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'ivo-donchev/goto-definition-plugin-for-react'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'ivo-donchev/goto-definition-plugin-for-react'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'ivo-donchev/goto-definition-plugin-for-react'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/ivo-donchev/goto-definition-plugin-for-react

Ⅳ. 文档说明

# Goto definition plugin for React JS

Overview

A python powered vim plugin for goto defintion functionality for functions/components/constants... handling imports and exports for Javascript and especially React JS.
The implementation is entirely written in Python 3 using regular expressions.

Covered import types:

  • relative imports (import Something from '../components/Something') - will search for any of:

    • '../components/Something.jsx' or
    • '../components/Something.js' or
    • '../components/Something/index.js' or
    • '../components/Something/index.jsx'
  • absolute imports (import Page1 from 'pages/Page1') - will search into src/ folder for the import:

    • 'src/pages/Page1.jsx' or
    • 'src/pages/Page1.js' or
    • 'src/pages/Page1/index.js' or
    • 'src/pages/Page1/index.jsx'
  • default imports (import A from './A' or import {default as A} from './A') and non-default imports (import {a, b as c} from 'module'))

Covered definition types:

  • class <...>
  • function <...>
  • function* <...>
  • <...> = - for variables, constants and arrow functions

Searching algorythm works as follows:

  1. Soft scraping:

    • Search in current file
    • Search for import
    • Search for export from another file
  2. Hard scraping (if soft scraping fails :( ) - searches for wanted definition over the whole project

Installation

Vundle

Add the following line to your ~/.vimrc :

Plugin 'Ivo-Donchev/vim-react-goto-definition'

and run:

:PluginInstall

Usage

Set you cursor on the imported function/component and type:

:call ReactGotoDef()

You can also map this function call with:

" To map to <leader>D:
noremap <leader>D :call ReactGotoDef()<CR>

NOTE: Your vim needs to support python3+ scripting. You can check this with:

:python3 print('ReactJS')

添加新评论