Your browser does not support JavaScript!
Upvotes Anonymous 1 User 0

How to setup Spacemacs for JavaScript auto-complete and go-to-definition across files

This post assumes you have already done these steps.

To have intelligent JavaScript support across files in Spacemacs, we need to let Tern know which libraries and files we're using. 

Create a JSON file named .tern-project in your project's root directory: 
{
	"libs" : [
		"browser",
		"jquery"
	],
	"loadEagerly": [ "js/*.js", "*.js" ],
	"plugins" : {
		"commonjs" : {},
		"node" : {},
		"requirejs" : {},
		"node_resolve" : {}
	}
}
Above, we're telling Tern to:

1. Expect usages of JavaScript objects defined in web browsers, as well as the jQuery library.
2. Inspect .js files in the project's root directory and in the js/ directory.
3. Add plugins for NodeJS, etc.

Parts of the .tern-project file above are from this helpful post.

Edit your .spacemacs
If you're using NodeJS, you'll want to setup js2-mode so it knows what module means in your JavaScript. You might get similar errors if you're using other plugins and haven't set certain variables in your .spacemacs file. 
Where can I find more about configuring Tern?
What's the shortcut for go-to-definition?
SPACE m g g. See more shortcuts in the JavaScript layer documentation.
Was this helpful?

Tags

Comments

Leave a Comment

I agree to the Terms of Service
Design © 2015, Downranked, LLC.,
Original user code contributions under MIT License