;;; xref-js2.el --- Jump to references/definitions using ag & js2-mode's AST -*- lexical-binding: t; -*- ;; Copyright (C) 2016 Nicolas Petton ;; Author: Nicolas Petton ;; URL: https://github.com/NicolasPetton/xref-js2 ;; Package-Version: 20170530.126 ;; Keywords: javascript, convenience, tools ;; Version: 1.0 ;; Package: xref-js2 ;; Package-Requires: ((emacs "25") (js2-mode "20150909")) ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; ;; xref-js2 adds an xref backend for JavaScript files. ;; ;; Instead of using a tag system, it relies on `ag' to query the codebase of a ;; project. This might sound crazy at first, but it turns out that `ag' is so ;; fast that jumping using xref-js2 is most of the time instantaneous, even on ;; fairly large JavaScript codebase (it successfully works with 50k lines of JS ;; code). ;; ;; Because line by line regexp search has its downside, xref-js2 does a second ;; pass on result candidates and eliminates possible false positives using ;; `js2-mode''s AST, thus giving very accurate results. ;;; Code: (require 'subr-x) (require 'xref) (require 'seq) (require 'map) (require 'js2-mode) (require 'vc) (defcustom xref-js2-ag-arguments '("--js" "--noheading" "--nocolor") "Default arguments passed to ag." :type 'list :group 'xref-js2) (defcustom xref-js2-ignored-dirs '("bower_components" "node_modules" "build" "lib") "List of directories to be ignored when performing a search." :type 'list :group 'xref-js2) (defcustom xref-js2-ignored-files '("*.min.js") "List of files to be ignored when performing a search." :type 'list :group 'xref-js2) (defcustom xref-js2-definitions-regexps '("\\b%s\\b[\\s]*[:=][^=]" "function[\\s]+\\b%s\\b" "class[\\s]+\\b%s\\b" "(? (seq-length match) 100) (setq match (concat (seq-take match 100) "..."))) (list (cons 'file (expand-file-name (car attrs) (xref-js2--root-dir))) (cons 'line (string-to-number (cadr attrs))) (cons 'symbol symbol) (cons 'match match)))) (provide 'xref-js2) ;;; xref-js2.el ends here