scottyb / ac-js2 Goto Github PK
View Code? Open in Web Editor NEWJavascript auto-completion in Emacs using Js2-mode's parser and Skewer-mode.
Javascript auto-completion in Emacs using Js2-mode's parser and Skewer-mode.
It would be good to support company mode as well as auto-complete. The best idea so far is to remove auto-complete as a dependency with options to add either auto-complete or company mode front ends. Need to investigate the format required for a company mode backend before refactoring.
I have no auto-completion with company. I write something like document.
and then I wait for suggestions but I get none.
I'm using company 20150301.1814 from MELPA and js2-mode 20150301.337 from MELPA. Running GNU Emacs 24.4.1 (i686-pc-linux-gnu, GTK+ Version 3.14.7) of 2015-01-17 on bisson
Following the instructions to install ac-j2, I am able to get a popup showing functions names (which match what I've typed), which is great. But I'm not able to get the completion popup to show the functions' parameters.
Is there something I can try to debug and see why this is not happening?
buildCandidates = function(obj, items) {
if (obj["__lookupGetter__"] && ((obj.__lookupGetter__(key) || obj.__lookupSetter__(key)))) {
var proto = obj.__lookupGetter__(key) || obj.__lookupSetter__(key); // test in moz 31.0
values[key] = proto.toString();
} else if (Object.prototype.toString.call(obj[key]) === "[object Function]") {
values[key] = obj[key].toString();
} else if (typeof obj[key] === "object"){
With the example code from the screenshot:
var moreMaths = {};
moreMaths.product = function(num1, num2) {
return num1 * num2;
};
moreMaths.divide = function(numerator, denominator) {
return numerator / denominator;
};
var someMath = math();
moreMaths.|
|
, press C-M-i
=> completion buffer pops up with expected contents, including product
and divide
.d
, press C-M-i
again => it completes to "document".backward-kill-word
, type d
again, press C-M-i
=> there's like 30% chance it will complete to divide
, otherwise it will be document
.modeMaths.di
, it will either say no match
, or complete to divide
, with the same buffer contents.completion-at-point
calls the completion function several times during one completion command, so maybe we're sometimes getting the response for the previous request, or something. EDIT: Nope, I can reproduce the same problem with calling (ac-js2-candidates)
directly, or with my company
back-end.
I tracked it down to ac-js2-get-object-properties
, and yes, it returns different completion lists for the same value of name
.
(defun ac-js2-find-property (list-names)
"Find the property definition that consists of LIST-NAMES.
Supports navigation to 'foo.bar = 3' and 'foo = {bar: 3}'."
(catch 'prop-found
(js2-visit-ast-root
js2-mode-ast
(lambda (node endp)
(let ((parent (js2-node-parent node)))
(unless endp
(if (or (and (js2-prop-get-node-p node)
(not (or (js2-elem-get-node-p parent) (js2-call-node-p parent)))
;;error: arrayp
;; (equal list-names (ac-js2-build-prop-name-list node))
t
)
(and (js2-name-node-p node)
(js2-object-prop-node-p parent)
(string= (js2-name-node-name node)
(first list-names))))
(throw 'prop-found node))
t))))))
js2 provides an idle timer option that makes possible a more terse linting:
But ac-js2 plays bad with it as it's continually forcing a new reparse. Please add an option to supress this behavior, I don't care the AST to be a bit outdated but I do care about the distracting spurious messages the reparsing is triggering.
ac-js2
thinks an underscore isn’t part of a variable name. Changing (bounds-of-thing-at-point 'word)
to (bounds-of-thing-at-point 'sexp)
in ac-js2-completion-function
fixes this, but I don’t know what potential other problems it might introduce.
I followed the instructions as specified on emacs 24.1.1 and got the error when package-installing skewer-mode: 'Package emacs 24.1 not available'. If I try to install ac-js without skewer-mode I get the same error. Any ideas?
Thanks...
Hello,
I've consider that ac-js2 only work with webkit browsers (i just tried latest version of Chromium on Linux), I tried it on Firefox with no success.
It's true or I'm doing something wrong? I've read skewer-addon.js and try to debug that, found that buildCandidates function won't return correct answer so result.value in Firefox return always null... different story in chromium which return result with correct value.
in the update of last versión of auto-complete-mode I get this error when I try to enable ac-js2
Debugger entered--Lisp error: (invalid-function ac-define-source)
ac-define-source("js2" ((candidates . ac-js2-ac-candidates) (document . ac-js2-ac-document) (prefix . ac-js2-ac-prefix) (requires . -1)))
ac-js2-setup-auto-complete-mode()
ac-js2-mode(toggle)
#<subr call-interactively>(ac-js2-mode record nil)
ad-Advice-call-interactively(#<subr call-interactively> ac-js2-mode record nil)
apply(ad-Advice-call-interactively #<subr call-interactively> (ac-js2-mode record nil))
call-interactively(ac-js2-mode record nil)
command-execute(ac-js2-mode record)
execute-extended-command(nil "ac-js2-mode")
#<subr call-interactively>(execute-extended-command nil nil)
ad-Advice-call-interactively(#<subr call-interactively> execute-extended-command nil nil)
apply(ad-Advice-call-interactively #<subr call-interactively> (execute-extended-command nil nil))
call-interactively(execute-extended-command nil nil)
command-execute(execute-extended-command)
I think that is solved with (eval '(ac-define-source "js2"
on line 285
When ac-source-js2 returns one or more matches to auto-complete, every other following source in ac-sources seems to be broken. That is, none of them will return any matches (although there are matches when I remove ac-source-js2).
Hi Guys!
I'm with some problem using ac-js2, while I'm coding js and I try to use auto complete the following error happens:
Ac-Js2 mode enabled in current buffer
Error running timer ‘ac-update-greedy’: (error "No JavaScript AST available") [2 times]
Error running timer ‘ac-show-menu’: (error "No JavaScript AST available")
Someone knows what can be?
My emacs version: GNU Emacs 25.1.1 (x86_64-apple-darwin15.0.0, NS appkit-1404.11 Version 10.11 (Build 15A284)) of 2016-10-03
When I try to load the ac-js2 mode I get an error:
require: Symbol's value as variable is void: cache-table-get
My Emacs version is:
GNU Emacs 24.2.1 (x86_64-pc-linux-gnu, GTK+ Version 3.6.4)
I made sure that I had the dependencies installed:
skewer-mode (MELPA)
js2-mode (ELPA)
(I installed ac-js2 using the package manager, but also tried to load the ac-js2.el file from the master branch with the same error as result).
Best Regards
Jeppe
Hi!
Could you please add release tag to this repo?
This will allow to download version 1.0 from https://github.com/ScottyB/ac-js2/releases URL.
Hi, I believe I have this installed just the readme says, but I am still not getting a drop down window when I type a previously-typed function: i.e.
I have in my .emacs:
(add-to-list 'auto-mode-alist (cons (rx ".js" eos) 'js2-mode))
(add-hook 'js-mode-hook 'ac-js2-mode)
So I do not know what is wrong. Any ideas?
First off, this is a nice piece of work - thanks for publishing.
Regarding M-.
, you can add backwards navigation and generally make this work more neatly by using ring-insert
and pop-tag-mark
-- take a look at https://github.com/purcell/elisp-slime-nav/blob/master/elisp-slime-nav.el#L93 for an example.
Secondly, I spotted a couple of typos in the code: search for "funtion" and "evalute".
Cheers!
-Steve
Experimental yansippet integration isn't supposed to be Yasnippet?
I was able to get Skrewer and HTTP server working but when I try to use ac-js2 together with company-mode and ask for next completion the Emacs freezes and I have to run keyboard-quit
.
My config below.
(eval-after-load 'ac-js2
'(progn
(setq ac-js2-evaluate-calls nil)
(add-to-list 'company-backends 'ac-js2-company)
(add-hook 'js2-mode-hook 'jarfar/js2-init t)
(add-hook 'js2-mode-hook 'skewer-mode t)
(add-hook 'js2-mode-hook 'ac-js2-mode t)
(defun jarfar/js2-init ()
(message "jarfar/js2-init run")
(setq-local browse-url-browser-function 'browse-url-chrome))
))
When I invoke run-skewer
together with ac-js2 I also get error 500 in browser.
I use macOS 10.15.7, Emacs 26.3.
That is the error I get when trying to use ac-js2 mode:
It shows no errors but as soon as I try to type something I get:
auto-complete error: (void-variable ac-source-js2)
Thank you for any help!
auto-complete
and company
are alternatives to each other, so it doesn't really make sense to support both in ac-js2
. For a start, the reference to company-*
symbols causes byte-compilation warnings on systems which don't have company
installed, which simply wouldn't be present if you could (require 'company)
. The naming is also confusing, because I doubt any company
users would expect an ac-*
package to be useful to them.
As a result, I'd strongly suggest splitting out a separate company-js2.el
in either the same repo or a fresh one, which would then form a separate easy-to-find and logically-named package in MELPA.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.