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:
Refactoring | Code before | Code after |
---|---|---|
const arrow to function declaration |
|
|
experimental jest only test |
|
|
experimental jest revert only |
|
|
experimental jest revert skip test |
|
|
experimental jest skip test |
|
|
experimental use styled component |
|
|
explicit return to implicit |
|
|
extract return |
|
|
flip if else |
|
|
flip ternary |
|
|
function to arrow |
|
|
implicit return to explicit |
|
|
jsx expand empty tag |
|
|
replace with concatenation |
|
|
require to import |
|
|
- 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 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
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"
}
}
}
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.
- Ability to create custom refactorings (per user and per workspace)
- More refactorings! If you need some specific, create an issue
Install deps npm i
Build package make coc-pack
Add set runtimepath^=~/THISREPO/build/coc/
to vimrc or run as command.
Install LSP Inspector. Run debug version with extension
make run-vscode
Run jsbin
with --lspi
flag and running inspector.
make npm-publish
make coc-publish
Install noob package
brew install zmwangx/npm-noob/noob
Publishing
make brew-publish
make vscode-publish
You can easily contribute by creating new kinds of refactoring. A good example can be found here. To avoid duplication, create an issue first.