Bug 40793 - Primary working copies: Type search does not find type in modified CU
Summary: Primary working copies: Type search does not find type in modified CU
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M4   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-07-25 13:20 EDT by Martin Aeschlimann CLA
Modified: 2003-10-14 11:31 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2003-07-25 13:20:02 EDT
M2

See test cases AllTypesCacheTest.testWorkingCopies() & testWorkingCopies2():

Editor is opened and the type name of the opened type is modfied.

testWorkingCopies():
editor is saved: new type is found in index but also old type is still found

testWorkingCopies2():
editor is not saved: new type is not found in index
Comment 1 Jerome Lanneluc CLA 2003-09-01 09:17:25 EDT
Fixed SearchEngine.searchAllTypeNames(...) to filter out results from indexes 
that have a corresponding working copy, and add the types of the working copies 
at the end.

Added regression test WorkingCopySearchTests.testAllTypeNames()

Also note that the tests in AllTypesCacheTest need to be changed to 
reset 'res1' before doing the second query.
Comment 2 Martin Aeschlimann CLA 2003-09-16 10:54:50 EDT
20030916 (jdt.core v_370)

The test 'testWorkingCopies2' still fails: The new type 'A' is not found.
(fixed the missing 'res1.clear))
Comment 3 Jerome Lanneluc CLA 2003-09-23 09:22:14 EDT
Just ran 'testWorkingCopies2' from org.eclipse.jdt.ui.tests v20030916 and it 
passed. Do you have more details on how to make it fail?
Comment 4 Martin Aeschlimann CLA 2003-09-23 09:40:00 EDT
Did you set JavaPlugin.USE_WORKING_COPY_OWNERS to true?
Comment 5 Jerome Lanneluc CLA 2003-09-23 09:46:15 EDT
No, it wasn't in the instructions :-)
Comment 6 Jerome Lanneluc CLA 2003-09-23 09:59:37 EDT
AllTypesCacheTest.testWorkingCopies() & testWorkingCopies2() from v20030916 
still don't clear 'res1'
Comment 7 Jerome Lanneluc CLA 2003-09-23 10:20:04 EDT
After fixing the tests, they pass under the debugger, but testWorkingCopies2() 
fails when run full speed. Sounds like a timing issue.

Martin are you sure that the working copy has been reconciled when asking for 
all types?
Comment 8 Martin Aeschlimann CLA 2003-09-23 10:55:32 EDT
'res1.clear()' is in v20030923 or HEAD!
Comment 9 Jerome Lanneluc CLA 2003-09-23 10:59:18 EDT
Comment #2 said 20030916 !!! And you didn't answer my last question.
Comment 10 Martin Aeschlimann CLA 2003-09-23 11:03:27 EDT
Didn't know that I have to reconcile before searching.
What's the rule here?
Before every search all CU that are in working copy mode have to be reconciled?

Couldn't search do that if it really needs that?
Comment 11 Jerome Lanneluc CLA 2003-09-23 11:09:42 EDT
This is the same rule as for the Outline: it shows new types only after a 
reconcile. It is not the job of the SearchEngine to do so.
Comment 12 Jerome Lanneluc CLA 2003-09-23 11:12:26 EDT
Note that the reconcile is usually done automatically by the Outline view. You 
need to force the reconcile only in the tests.
Comment 13 Martin Aeschlimann CLA 2003-09-23 11:20:10 EDT
Sorry for the confusion about versions. It was supposed to describe what 
jdt.core I was using. Always take HEAD of the tests and our code. 

About the reconcile: If you want me to do this; is there method that returns 
all CU currently in working copy mode so I can make sure that each is 
reconciled?
I really think search should do that when called. Why would I want to search on 
on an outdated structure?
The outliner of course reconciles every 300 ms, but in the event of a search I 
want the most current state, not even the one 100ms before!
Comment 14 Jerome Lanneluc CLA 2003-09-23 11:30:01 EDT
If we took HEAD for your tests, we would have to take HEAD for jdt.ui, and HEAD 
for platform.ui, etc... We have to concentrate on jdt.core. Moreover we run the 
jdt.ui tests from last integration build to make sure that we don't break you, 
but these should not be seen as test cases. A good test case from the jdt.core 
point of view is a test case that uses jdt.core API only. Otherwise we have to 
spend time understanding your code. We have enough on our plate with jdt.core 
already.
Comment 15 Jerome Lanneluc CLA 2003-09-23 11:33:20 EDT
As for reconciling working copies, we would have to do it for each operation 
(e.g. ICompilationUnit.getAllTypes()), which would be expensive especially in 
the case of no changes to the underlying document. I expect that jdt.ui and/or 
jdt.text know when a change to the underlying document has occured, so when it 
is a good time to reconcile. That's actually the whole purpose of the reconcile 
operation.
Comment 16 Martin Aeschlimann CLA 2003-09-23 11:57:38 EDT
I see the problems with having everything in HEAD. I agree that's a pain. It 
seems to work fine with Olivier. I send him test case like that all the time. 

So in today's integration build you have all the tests as I mentioned them in 
the bug reports. I though it's clear that when I mention a version number this 
would be one of the past.
I guess if you don't like HEAD, you have to wait for the next integration 
build. Or maybe use the nightly build?

As for reconciling working copies: There are usually many editors open, all of 
them in working copy mode, potentially unsaved. So if you don't want to force 
them to be reconciled: We would have to do exacltly the same. So performance- 
wise this comes to the same.
We don't know either if a CU has been reconciled after the latest change.
To avoid unnecessary reconciles on unmodified document you probably need a 
dirty bit for that. I don't think we should have such a dirty bit.

In my opinuon it is a implementation detail that type search uses the Java 
Model elements. It could also use the AST and in that case a reconcile wouldn't 
be necessary. And if a reconcile is required, you have to document it.

Comment 17 Jerome Lanneluc CLA 2003-09-23 13:24:56 EDT
Will use the working copy if it is consistent with its buffer, otherwise will 
do the search by reparsing the buffer's source, without reconciling the working 
copy. This should make everyone happy.
Comment 18 Jerome Lanneluc CLA 2003-09-23 13:26:19 EDT
I don't think Olivier would agree that working with HEAD from another plugin is 
confortable :-)
Comment 19 Philipe Mulet CLA 2003-09-24 03:51:13 EDT
Ok, we will ensure search find matches in non-reconciled working copies. 
Ideally, we want to avoid forcing a reconciliation action since it will notify 
clients in an unexpected way.

We should only use the model if consistent, if not then we should consider the 
buffer contents (and parse it) directly. This would be consistent with various 
resolve actions (which directly look at the buffer). 
Comment 20 Jerome Lanneluc CLA 2003-09-24 06:27:30 EDT
Even after changing the SearchEngine to take the buffer's content instead of 
the working copy, the test still fails. Problem is that the AllTypeCache relies 
on Java delta to mark itself as needing refreh. This can happen only if the 
working copy has been reconciled. IBuffer.setContent(...) doesn't force a 
reconcile.

So even if we forced a reconcile in the SearchEngine, AllTypeCache would not 
call the SearchEngine since it considers it is up-to-date.
Comment 21 Martin Aeschlimann CLA 2003-09-24 08:08:50 EDT
Have to think about that.

I think this means that the AllTypeCache should force a reconcile to be sure it 
got all the deltas. I'll look at that.
Thanks for the fix for search. Please release it still, I think it is the 
correct thing to do. 
Comment 22 Jerome Lanneluc CLA 2003-09-24 08:40:50 EDT
Released the fix in SearchEngine. Will not be in I20030924, but in next 
integration build.
Comment 23 Jerome Lanneluc CLA 2003-09-25 07:14:07 EDT
JDT/Core side of the problem is fixed. A new bug is being opened against JDT/UI 
for the AllTypeCache needing to reconcile its working copies.
Comment 24 Jerome Lanneluc CLA 2003-09-25 07:16:10 EDT
New bug in JDT/UI is bug 43641.
Comment 25 David Audel CLA 2003-10-14 11:31:04 EDT
Verified.