Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 488396 - [refs][search] After an all references rename the editor / tools seem to be in different states
Summary: [refs][search] After an all references rename the editor / tools seem to be i...
Status: RESOLVED FIXED
Alias: None
Product: Orion
Classification: ECD
Component: JS Tools (show other bugs)
Version: 11.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 12.0   Edit
Assignee: libing wang CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-24 12:36 EST by Michael Rennie CLA
Modified: 2016-02-29 15:32 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Rennie CLA 2016-02-24 12:36:17 EST
Its seems that after a rename of performed from the all references UI, the editor and tools are in different states.

heres some steps:

1. using the minesweeper-demo example find all refs to main in main.js
2. rename to main2
3. select main2 in the editor - occurrences only marks ‘main’ of main2
4. run find refs again on main2 - notice the search still says it looked for ‘main'
5. reload the page and everything works fine

I wonder if there is a problem with all of the *Changed events being sent out when the rename is performed. If this was a problem it would explain the tooling bad state, since the ASTManager uses those events to know when to flush a cached AST.
Comment 1 Michael Rennie CLA 2016-02-24 16:28:07 EST
I debugged this a bit and confirmed the AST manager is holding the old (pre-refactor) AST
Comment 2 Michael Rennie CLA 2016-02-24 16:47:52 EST
So the problem is no onModelChanged events being sent for files that are changed but are not the file your are currently working in.

Steps (using the minesweeper-demo project):
1. open index.html
2. open main.js
3. back in index.html, rename 'main' to 'main2', click in the editor to force it to update
4. at this point we get an onModelChanged for index.html (GOOD), but we do not get one for main.js (BAD) - so we don't know to flush the cache for its AST. Then when we navigate to main.js and try to use the tools, they are all working against the original main.js AST (with 'main' in it).
Comment 3 libing wang CLA 2016-02-25 08:41:55 EST
(In reply to Michael Rennie from comment #2)
> So the problem is no onModelChanged events being sent for files that are
> changed but are not the file your are currently working in.
> 
> Steps (using the minesweeper-demo project):
> 1. open index.html
> 2. open main.js
> 3. back in index.html, rename 'main' to 'main2', click in the editor to
> force it to update
> 4. at this point we get an onModelChanged for index.html (GOOD), but we do
> not get one for main.js (BAD) - so we don't know to flush the cache for its
> AST. Then when we navigate to main.js and try to use the tools, they are all
> working against the original main.js AST (with 'main' in it).

So in steps 3, I assume that you used "replace selected" feature in the search panel to rename. The "replace selected" feature is a silent "write" action against all the files related, where there is no editor context. I think the best way to notify the AST manager in this case is to send out an event with a list file URIs attached. The AST manager then needs to flush the cache on theses files, if any.
Comment 4 libing wang CLA 2016-02-25 15:20:18 EST
Talked to SSQ, ideally we should have sort of workspace resource eventing system so that any resource changes will be notified to client. But for the "replace selected" feature in the search, we do not need that heavy duty thing.
As we are using fileClient.write() to change all the file contents, we may end up dispatching a change event from fileClient. Because the javaScript plugin and orion client side share the same file client now(thanks SSQ's improvement), you can listen the change event on the plugin side to tell AST what to do.
Comment 5 Michael Rennie CLA 2016-02-25 15:53:58 EST
(In reply to libing wang from comment #4)
> Talked to SSQ, ideally we should have sort of workspace resource eventing
> system so that any resource changes will be notified to client. But for the
> "replace selected" feature in the search, we do not need that heavy duty
> thing.
> As we are using fileClient.write() to change all the file contents, we may
> end up dispatching a change event from fileClient. Because the javaScript
> plugin and orion client side share the same file client now(thanks SSQ's
> improvement), you can listen the change event on the plugin side to tell AST
> what to do.

Perfect, so I assume we will end up with something like:

addListener(id, callback)
removeListener(id)

in fileClient, and will get events like:

ADDED | file metadata
REMOVED | file metadata
CHANGED | file metadata
Comment 6 libing wang CLA 2016-02-26 11:56:08 EST
Pushed the dispatchEvent changes form the search pane and file client.
http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=4cd5f0760268e6ffe774eaa557e4367e3d89a304
Comment 7 libing wang CLA 2016-02-26 12:29:40 EST
Second commit to use Object.create(null) to create event.
http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=fc387e5eafbfa50d4c769b388dc2fe20754b4c9a
Comment 8 libing wang CLA 2016-02-26 12:32:20 EST
Opened bug 488582 for a generic solution.
Comment 9 libing wang CLA 2016-02-26 12:34:13 EST
Mike, my changes are in now. I put a piece of code(commented out) at the end of javascriptPlugin.js and verified the listener got the event. Please remove that code after you are done.
Comment 10 Michael Rennie CLA 2016-02-29 15:32:34 EST
I pushed all the glue on the plugin side:

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=d09ad4a73ad4c615cfa7d191dc8a8e3b6af1c6a2