Phpstorm For Javascript



PhpStorm IDE provides code refactoring, auto-completion, on-the-fly error prevention, zero-configuration debugging, and an extended HTML, CSS, and JavaScript editor. PhpStorm provides tools and code assistance features for working with databases and SQL in your projects. Setup the Default Settings for PHPbstorm, so that all projects start with them by default. Go to Default Settings Languages & Frameworks JavaScript and choose JavaScript language version to ECMAScript 6 Select Prefer Strict mode (SEE THE PICTURE BELLOW!) You may need to repeat this process for the current Settings as well. Just put the tags into your customjs file and put your code inside. PhpStorm will highlight everything correctly then.

Features

Those of us who work a lot with JavaScript often face a small issue with Autocompletion which turns to be not a small issue but a big mess.
By default, completion works for all JavaScript files located under your project root. This may lead to a long and almost unusable completion list. Even if you use just a few JavaScript libraries in your project like jQuery, Ext JS and MooFX, you can get up to 4,000 autocompletion hints for Document object coming from all those libraries! And even when you type e.g. “set”, you’ll still end up with about 200 functions starting with “set” . Not a lot of help, is it? 😉

Starting from WebStorm/PhpStorm 2.0 we include a new feature that deals with this very issue. Now, in Settings | Project settings you can specify the JavaScript Libraries that should be used for each file/folder or for the whole project — in other words, their Usage Scope. In the example below we have two libraries defined for our project.

Let’s say we have jCrop and jQuery in our project.

example1.js uses only jCrop because we specifed at project-level that we use this library for the whole project (and thus we may need autocompletion for jCrop in any file).
example2.html will use jQuery and jCrop so autocompletion will be available for both libraries.

These settings will be stored in the project file, so you can share it via your VCS to other members of your project, so that they will be ready-to-go just by checking out project files.

How to set up JavaScript library in WebStorm/PhpStorm

Phpstorm

Phpstorm Javascript Unresolved Variable

Open IDE Settings | Project Settings. Select JavaScript | Libraries | Add… and add the files or folders you need.

There is an additional benefit — you will be able to create global JavaScript libraries shared between different projects.

“Download Library” Intention

There is an even easier way to create a library containing just one .js file, if this file is located on the Internet and can be accessed over HTTP. For example, if a JavaScript library is available online. Here is a small example of an HTML file containing a link to jQuery on jquery.com:

Phpstorm Javascript Type Hinting


Assuming that jQuery library hasn’t been defined yet, you can move the caret to “http://code.jquery.com/…” string, press Alt+Enter/Option+Enter and choose “Download Library” from the list of available intention actions:

It may take a while before the library is downloaded but eventually you will see the message “Successfully downloaded http://code.jquery.com/jquery-1.4.3.js”. The downloaded file will be stored in your local file system for code completion and navigation to work.

Download the latest WebStorm/PhpStorm EAP and try this.

Debugging JavaScript in PhpStorm is supported through the JavaScript Debugger plugin. The JavaScript Debugger plugin is bundled with PhpStorm and activated by default. If the plugin is disabled, enable it on the Settings/Preferences | Plugins page as described in Managing plugins.

Debugging of JavaScript code is supported in Google Chrome and other browsers of the Chrome family.

Phpstorm Javascript Debug

To ensure successful debugging, it is enough to specify the built-in web server port and accept the default settings that PhpStorm suggests for other debugger options.

Before you start

  • Make sure the JavaScript Debugger bundled plugin is enabled on the Settings/Preferences | Plugins page, see Managing plugins for details.

For

Set the built-in web server port

  1. In the Settings/Preferences dialog Ctrl+Alt+S, go to Build, Execution, Deployment | Debugger.

  2. In the Built-in server area, specify the port where the built-in web server runs. By default this port is set to the default PhpStorm port 63342 through which PhpStorm accepts connections from services. You can set the port number to any other value starting with 1024 and later.

Optionally

  • Suppress calls to the files on the built-in server from other computers or from outside PhpStorm by clearing the Can accept external connections or Allow unsigned requests checkbox respectively.

  • Choose the way to remove breakpoints, the default setting is Click.

  • On the Debugger. Data Views page under the Debugger node, configure advanced debugger options: enable or disable Inline Debugging, specify when you want to see tooltips with object values and expressions evaluation results, and so on.

  • On the Debugger. Stepping page, specify the scripts to be skipped by the debugger.
    By default, the debugger does not step only into library scripts. To expand the suppression list, select Do not step into scripts checkbox and add the URL addresses to skip using and .

Starting a debugging session with your default Chrome user data

You may notice that your debugging session starts in a new window with a custom Chrome user data instead of your default one. As a result, the window looks unusual, for example, your bookmarks, the browser history, and the extensions are missing, which altogether breaks your development experience. That happens because PhpStorm uses Chrome Debugging Protocol and runs Chrome with the --remote-debugging-port option. However, if Chrome is already started, a debugging port can't be opened for any new or existing Chrome instance that has the same user data. Therefore, when Chrome Debugging Protocol is used, PhpStorm always starts a debugging session with in a new window with a custom user data.

To open a new Chrome instance with your familiar look-and-feel, configure Chrome in PhpStorm to start with your user data. In this case, before starting a debugging session, always make sure that Chrome is not already running with your user data. Otherwise PhpStorm still launches another instance of Chrome with your user data but is unable to open a debugging port for it. As a result, PhpStorm debugger fails to connect to the application in the new Chrome instance and the debugging session does not start.

Configure Chrome in PhpStorm to start with your Chrome user data

  1. Save your Chrome user data anywhere on your machine.

  2. In the Settings/Preferences dialog Ctrl+Alt+S, click Web Browsers under Tools. The Web Browsers page opens.

  3. To create a new Chrome configuration, click . A new item appears in the list. In the Path field, specify the path to the Chrome installation folder.

  4. Select the new configuration and click . The Chrome Settings dialog opens.

  5. Select the Use custom user data directory checkbox and specify the path to your user data directory in the PhpStorm settings.

  6. Mark your Chrome browser configuration default as described in Choosing the default PhpStorm browser, and don't forget to choose Default from the Browser list when creating a run/debug configuration.

    Alternatively, always choose this Chrome browser configuration from the Browser list.





Comments are closed.