coc-jsref
v1.1.15
Published
coc.nvim plugin for JavaScript refactoring
Downloads
5
Readme
jsref
JavaScript refactoring language server
An idea behind this project is to have desirable refactoring experience for JavaScript (JSX, TypeScript, Flowtype) without tying to any editor.
This tool implements language server protocol (LSP) to avoid any direct binding to code editors. This means any editor with LSP support can use it.
It uses babylon parser to parse and generate JavaScript.
Supported refactorings:
const A = () => { return r.div() }
const StyledDiv = styled("div", {});
const A = () => { return r(StyledDiv) }
return result;
Installation
Vim and Neovim (via coc.nvim)
- Install coc.nvim plugin
- Run
:CocInstall coc-jsref
- Configure hotkeys. For example to use
ga
:
nmap ga <Plug>(coc-codeaction-cursor)
xmap ga <Plug>(coc-codeaction-selected)
VSCode
VSCode extension contains server and you don't need to install global one with brew
.
Search in Extensions panel for jsref
or install via CLI
code --install-extension slonoed.jsref
Sublime Text 3
Install jsref language binary via brew
brew install slonoed/tap/jsref
or npm
npm i -g @slonoed/jsref
Install LSP package from Package Control.
Add new client to LSP via Preferences: LSP Setting
.
"jsref": {
"command": ["jsref", "--stdio"],
"scopes": ["source.js"],
"syntaxes": [
"Packages/babel-sublime/JavaScript (Babel).tmLanguage",
"Packages/Babel/JavaScript (Babel).sublime-syntax",
"Packages/JavaScript/JavaScript.sublime-syntax"
],
"languageId": "javascript",
},
Final config should look like this
{
"clients": {
"jsref": {
"command": ["jsref", "--stdio"],
"scopes": ["source.js"],
"syntaxes": [
"Packages/babel-sublime/JavaScript (Babel).tmLanguage",
"Packages/Babel/JavaScript (Babel).sublime-syntax",
"Packages/JavaScript/JavaScript.sublime-syntax"
],
"languageId": "javascript"
}
}
}
Other editors
All other editors are supported via standard plugins for language servers.
jsref language server can be installed via brew
brew install slonoed/tap/jsref
or npm
npm i -g @slonoed/jsref
Help needed to add instructions for other editors.
Plans
- Ability to create custom refactorings (per user and per workspace)
- More refactorings! If you need some specific, create an issue
Development
Install deps npm i
coc.nvim extension
Build package make coc-pack
Add set runtimepath^=~/THISREPO/build/coc/
to vimrc or run as command.
Debug VScode extension
Install LSP Inspector. Run debug version with extension
make run-vscode
Debug server
Run jsbin
with --lspi
flag and running inspector.
Deploy
Release npm package
make npm-publish
Release coc packaged
make coc-publish
Release brew tap (after npm release)
Install noob package
brew install zmwangx/npm-noob/noob
Publishing
make brew-publish
Release vscode extension
make vscode-publish
Contributing
You can easily contribute by creating new kinds of refactoring. A good example can be found here. To avoid duplication, create an issue first.