In a project with client side javascript and Node.js javascript, how can I configure WebStorm to only recognize global variables within their own scope?

I have a (MEAN) WebStorm project with a directory structure like this:

Project
->client
--->js
----->client-app.js
----->controllers
-------->client-meetups-controller.js
--->views
----->singlepageapp.html (or index.html)

->server
--->server.js
--->controllers
------>server-meetups-controller.js
--->models
------>server-meetup-model.js


I have created two Scopes in Settings>Scopes, one for the Server Scope and one for the Client Scope. I went to Settings>File Colors and colored the scopes to verify I had the files correctly scoped and seperated into Server and Client (every js file in the "server" directory in one scope, every js file in the "client" directory in another scope).

However, in client-meetups-controller.js I have a line:

app.controller('meetupsController', ['$scope', '$resource', function ($scope, $resource) {

"app" isn't defined anywhere in my client side scope (yet), so I should see an error underline from WebStorm. Instead it is bolded and purple, indicating it is defined. Additionally, when I right-click on "app" and do "Go to>Declaration" it takes me to server.js which is in my Server Scope and not in my Client Scope (which client-meetups-controller.js is in). How do I get WebStorm to respect my scopes?

- Austin

1 comment
Comment actions Permalink

Scopes-based completion/types resolving is only available for javascript libraries - you can assign scopes to each of them to get library functions only available in specified scope. For other files WebStorm uses a global scope for resolving dependencies. It means that all .js files (external dependencies/your own files) located in the project root will be used in one single global resolve scope
You can create a library using "Settings | JavaScript | Libraries" and associate it with a custom scope. That allows to exclude the created library from global scope. But note that library filesd are3 read-only in WebStorm, so you won't be able to edit them after adding them to javascript libraries
So, I suppose, the only solution here is to have 2 separate projects - one for server and another - for client side

See also http://youtrack.jetbrains.com/issue/WEB-1061

0

Please sign in to leave a comment.