Skip to content
JavaScript refactoring language server
TypeScript Makefile Other
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
dev
scripts
src
vscode-extension
.gitignore
.prettierrc
Makefile
README.md
jest.config.js
package-lock.json
package.json
tsconfig.json
tslint.json

README.md

jsref

JavaScript refactoring language server

Demo Animation

An idea behind this project is to have desirable refactoring experience for JavaScript 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:

  • Convert explicit return to implicit
  • Flip if-else
  • Flip ternary expression
  • Convert regular function to arrow function
  • Convert implicit return to explicit
  • Expand empty JSX tag
  • Replace string literal with concatenation of strings
  • Convert require to import

Experimental refactorings (can be removed in future):

  • Disable Jest test (add '.skip')
  • Enable Jest test (remove '.skip')
  • Add '.only' to Jest test
  • Remove '.only' from Jest test
  • Use styled component form "styletron-react"

Installation

Install globally via brew

brew install slonoed/tap/jsref

Vim

Install vim-lsc plugin and setup

Plug 'natebosch/vim-lsc'
let g:lsc_server_commands = {
\'javascript': 'jsref --stdio',
\'javascript.jsx': 'jsref --stdio',
\}

By default vim-lsc adds ga shortcut for requesting code actions.

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-insiders --install-extension slonoed.jsref

Atom

TBD

help needed

Sublime Text 3

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": {
    "jref": {
      "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"
    }
  }
}

Enable language server via LSP: Enable Language Server Globally or LSP: Enable Language Server in Project

Emacs

TBD

help needed

Plans

  • More refactorings! If you need some specific, create an issue

Development

Install deps npm i

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-pack
make npm-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.

You can’t perform that action at this time.