Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Porting tern analysis of JS code to Node. #11948

Merged
merged 31 commits into from
Jul 13, 2017
Merged

Porting tern analysis of JS code to Node. #11948

merged 31 commits into from
Jul 13, 2017

Conversation

swmitra
Copy link
Collaborator

@swmitra swmitra commented Nov 23, 2015

This PR is created to port our js code analysis logic on node for better scalability . This will improve the overall performance and leverage addition of new features like -

  1. In place rename of variable with scoping [ Separate PR will enable this soon ]
  2. Find reference with scoping [ Separate PR will enable this soon ]
  3. Call Hierarchy [ Separate PR will enable this soon ]

and other related features.

TODO

  • Fetching of doc content from node domain instead of posting request back to main thread
  • Unit test update

@swmitra
Copy link
Collaborator Author

swmitra commented Nov 23, 2015

Tagging @nethip @abose @zaggino @ryanstewart @petetnt

@swmitra swmitra closed this Nov 23, 2015
@swmitra swmitra reopened this Nov 23, 2015
@swmitra swmitra added this to the Release 1.6 milestone Nov 23, 2015
@swmitra swmitra self-assigned this Nov 23, 2015
.gitmodules Outdated
@@ -10,6 +10,9 @@
[submodule "src/extensions/default/JavaScriptCodeHints/thirdparty/tern"]
path = src/extensions/default/JavaScriptCodeHints/thirdparty/tern
url = https://github.com/marijnh/tern.git
[submodule "src/extensions/default/JavaScriptCodeHints/node/node_modules/tern"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two tern submodules. Can this be unified?

@swmitra
Copy link
Collaborator Author

swmitra commented Nov 24, 2015

@abose WIP! Removed the old reference now.

@abose
Copy link
Contributor

abose commented Nov 24, 2015

Would the path change affect the extensions?

@petetnt
Copy link
Collaborator

petetnt commented Nov 30, 2015

@swmitra Have you done any initial performance benchmarks against the previous implementation yet 📊?

I can try and review this ASAP, been a bit busy as of late

.gitmodules Outdated
@@ -25,3 +22,9 @@
[submodule "src/extensions/default/JSLint/thirdparty/jslint"]
path = src/extensions/default/JSLint/thirdparty/jslint
url = https://github.com/peterflynn/JSLint.git
[submodule "src/extensions/default/JavaScriptCodeHints/node/node_modules/acorn"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooc, would not be better to create a package.json in src/extensions/default/JavaScriptCodeHints/node?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swmitra
we don't need submodules anymore, npm install will install dependencies defined in src/extensions/default/JavaScriptCodeHints/package.json, please remove

@ficristo
Copy link
Collaborator

@swmitra Do you think it would be possible / easier to add the reading of a .tern-config file (even in a future PR)?

@swmitra
Copy link
Collaborator Author

swmitra commented Dec 1, 2015

Sorry for late reply.

@petetnt Yes I tried to benchmark the performance to have the gain quantified (Will post a detailed result once the implementation is complete).
Any help on performance data with and without this PR is welcome!
For small and medium JS files , there is marginal gain which may not be even perceptible. The benefits of porting this analysis to tern node has 2 main agendas -

  • File content extraction can be done from node domain itself. I am currently working on this. This will allow us to perform the complete analysis and preparation for the analysis outside main thread as we don't have to post back messages to the main thread asking for file content.
  • We do have a bottleneck in terms of performance when we are asking for hints in htmlmixed content and the html file is large enough ( may be 10k+ lines of code ). The typing response gets severely affected as the main thread gets hogged to extract JS text from the html file. I am trying to use a CM runmode on node to offload this to node domain. This will improve the typing performance of the main editor significantly.

@ficristo Yes , it's a good idea to have a package.json and resolve the dependencies as node modules. Also we can introduce a tern config file. I will take both this activities outside this PR and do the changes under a separate PR soon after this.


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, node: true, regexp: true */

(function () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The methods in this function need JSDocs I think 📝

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petetnt Sorry for late reply. Was busy with some the type details stuff 😃 . I will add required JSDocs tonight.

Adding JSDoc in ExtractFileContent
# Conflicts:
#	.gitmodules
#	src/extensions/default/JavaScriptCodeHints/ScopeManager.js
Copy link
Collaborator

@petetnt petetnt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a notice

"name": "brackets-javascript-code-hints",
"dependencies": {
"acorn": "3.3.0",
"tern": "0.20.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest tern is now 0.21.0. If we can update to that, great. If it has breaking changes, lets keep this one and update later.

@ficristo ficristo dismissed their stale review June 7, 2017 13:17

No time for another review here.

@swmitra swmitra modified the milestones: Release 2.0, Release 1.10 Jun 19, 2017
@swmitra
Copy link
Collaborator Author

swmitra commented Jun 19, 2017

Pushing this to next release. We will merge this the moment we release 1.10 and do the first pre-release with this PR. It's breaking a few unit tests and have to resolve them before we merge.

@swmitra swmitra modified the milestones: Release 1.10, Release 2.0 Jun 19, 2017
@marcelgerber
Copy link
Contributor

@swmitra Based on your last comment, this is now ready to be merged.

@swmitra
Copy link
Collaborator Author

swmitra commented Jul 9, 2017

Yes @marcelgerber 😄 . If we need a build refresh for the reported dll issue, we would be in trouble in case this PR is merged. I would wait for a couple of days to discuss any possibility of build refresh and then merge this PR for the first pre release.

@swmitra
Copy link
Collaborator Author

swmitra commented Jul 12, 2017

@marcelgerber This PR can't be merged right now 😞. There are 2 major issues I found today while testing -

TOFIX

  • Require module hints have stopped working
  • If node restarts for any failure, re initialization of Tern should happen again

While I am working on these 2 issues, if you can spot any problem or a probable cause for this, please let me know. These should be fixed in a day or two.

* @param {Function} callback - callback handle to post the content back
*/
function _readFile(fileName, callback) {
fs.readFile(fileName, "utf8", function (err, data) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that Brackets handles arbitary encodings, should the encoding be passed to this function too?

Copy link
Collaborator Author

@swmitra swmitra Jul 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Precisely I am in a catch 22 situation 😢 . Encoding scheme is only available after detection at shell level, in order to use that, I have to read all the files by hopping on the Brackets main thread, which negates any gain in terms of performance compared to using nodes io. I was relying on Brackets only to fetch dirty files content, but If I start relying on Brackets we will end up with performance issues in case of flat project structure. Prime pump will clog the main thread which in turn will make the entire editor non responsive.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petetnt I have fixed most of the issues. Relying on Brackets main thread for content until we figure out a way to pass encoding info.

@swmitra
Copy link
Collaborator Author

swmitra commented Jul 12, 2017

Acorn and Tern have been upgraded to latest version 5.1.1 and 0.21.0 respectively. Haven't noticed any problem in real use or test suite except the ones mentioned before.

@swmitra
Copy link
Collaborator Author

swmitra commented Jul 13, 2017

@marcelgerber @petetnt Just the final bit remaining. Need to re-initialize Tern when node gets restarted after a crash. Can we merge this PR now? We can get some time for testing all the features then.

Copy link
Collaborator

@petetnt petetnt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more question


require("tern/plugin/requirejs");
require("tern/plugin/doc_comment");
require("tern/plugin/angular");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes Pete. Without these, commonjs dependency analysis and js doc parsing for parameter type inference doesn't work.

@petetnt petetnt merged commit 1edb0d6 into master Jul 13, 2017
@petetnt
Copy link
Collaborator

petetnt commented Jul 13, 2017

LGTM with a follow up PR on the restart-after-crash scenario

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants