This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 249269 - Offer local node_modules in require() code completion
Summary: Offer local node_modules in require() code completion
Status: STARTED
Alias: None
Product: javascript
Classification: Unclassified
Component: Node.js (show other bugs)
Version: 8.1
Hardware: PC Linux
: P2 normal (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-10 16:55 UTC by Vladimir Riha
Modified: 2014-12-19 04:35 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Riha 2014-12-10 16:55:16 UTC
If I have NodeJS project, where Sources == project dir and there is a node_modules folder in sources, it would be handy to offer node modules from node_modules folder in 

var e = require("^");

it can be achieved now using relative file paths, but for locally installed modules, this is not necessary and probably also not common.

Example:

[project dir]
  -- node_modules
     -- body-parser
        -- test.js
        -- test2.js

in this case I have a body-parser module and it contains test.js and test2.js. The code completion would offer

#1 
var e = require("^"); => NodeJS core modules, file paths (as it does now) and also body-parser, once I select body-parser, it would be completed w/o "/"

var e = require("body-parser");


#2
var e = require("body-parser/^");

=> cc would offer test.js, test2.js


There can be node_modules folders inside of some other module folder, but only the single top level node_modules in project/sources dir (I guess package.json will be in most cases in the same folder as node_modules) would be used for #1. The #2 is "just about mapping" resolved path to file paths.

I have no idea of any performance implications, but at least #1 would be imho very nice :)


Thanks
Comment 1 Petr Pisl 2014-12-11 17:23:36 UTC
Regarding the performance, it can be "cached" in the index in the worse case. But it should be tested.  

If I summarize is. If there is a node_modules folder in the project, offer the names of the child folders in the code completion, in the empty string in require or define method. Is it right?
Comment 2 Vladimir Riha 2014-12-11 17:30:47 UTC
(In reply to Petr Pisl from comment #1)
> Regarding the performance, it can be "cached" in the index in the worse
> case. But it should be tested.  

Probably, it won't change that often but in case it does, would be nice to somehow force refresh :) 

> If I summarize is. If there is a node_modules folder in the project, offer
> the names of the child folders in the code completion, in the empty string
> in require or define method. Is it right?

Yes, but probably makes sense to use just the one main node_modules in project/sources dir (not "nested" node_modules in individual module's folders). I guess only exports method makes sense, not define


Thank you
Comment 3 Petr Pisl 2014-12-18 16:13:29 UTC
The first part is in the web-main now. 

The implementation now looks for the first node_modules folder that is up to the edited file. If such folder is found, then all children folders of node_modules (containing package.json file) are offered in the code completion. From the package.json file is constructed the documentation. Now includes the module name, version and description. It can be included more if you want. 

Also Go To Declaration works(CTRL+click). In such case the editor opens the file, which is defined in the package.json as main file. 

Vlado, this is already second Christmas present for you :).
Comment 4 Vladimir Riha 2014-12-18 18:50:40 UTC
Thank you, I guess I've been good this year :) It works great
Comment 5 Quality Engineering 2014-12-19 04:35:56 UTC
Integrated into 'main-silver', will be available in build *201412190001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/af9ee840f5d0
User: Petr Pisl <ppisl@netbeans.org>
Log: #249269 - Offer local node_modules in require() code completion
First part implemented