Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 367757

Summary: Editor caches external file changes
Product: [Technology] DLTK Reporter: Wojciech Galanciak <wojciech.galanciak>
Component: CommonAssignee: dltk.common-inbox <dltk.common-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: alex.panchenko, ganoro
Version: 4.0   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
patch
none
patch2 none

Description Wojciech Galanciak CLA 2012-01-03 08:00:49 EST
Problem can be reproduce in PHP editor from pdt.

Here are steps to reproduce:
1. Open external php file using Eclipse.
2. Make some changes.
3. Close editor, do not save changes.
4. Open the same file again in the same Eclipse instance.

Result:
All changes from point 2 are visible and file is dirty.
Comment 1 Wojciech Galanciak CLA 2012-01-03 08:05:10 EST
Created attachment 208933 [details]
patch

The problem is located in org.eclipse.dltk.internal.ui.editor.SourceModuleDocumentProvider. It is possible that when SourceModuleDocumentProvider.connect(Object) is called a new file info is added with a fake source module (line 1281 in SourceModuleDocumentProvider.createFileInfo(Object)) but it is not added to fFakeCUMapForMissingInfo map. During fake source module creation new buffer is created for it (org.eclipse.dltk.internal.ui.editor.DocumentAdapter). During its initialization (DocumentAdapter.initialize()) fFile is null so fileStore is stored in TextFileBufferManager (IFileBufferManager.connectFileStore(IFileStore, IProgressMonitor)).

When file is closed fake copy is disconnected but only if file info is stored in fFakeCUMapForMissingInfo (in our case it does not). The second problem is in DocumentAdapter.close() method. It only disconnect buffer but does not disconnect fileStore (in our case only file store was connected).

The result is that fileStore is not fully disconnected and when the file is opened again then modification are restored from it.
Comment 2 Alex Panchenko CLA 2012-01-03 09:35:36 EST
I was able to reproduce the bug.
Checking the patch.
Comment 3 Alex Panchenko CLA 2012-01-04 02:27:33 EST
Created attachment 208985 [details]
patch2

The fixes continue the changes started by bugĀ 267008 "No validation for opened external files in PDT" (btw, how to check if it works?)

There were 2 calls to create working copy, so now you need 2 calls to discard it.
It doesn't feel correct, let's try if it can work with only 1 call. Please try how it works with my patch. Editor content is not cached, but I have no idea how to check the behavior of the mentioned bug 267008, even with PDT sources.
Comment 4 Wojciech Galanciak CLA 2012-01-04 08:31:07 EST
Your fix breaks bug 267008. To check it you need to break a code (e.g. line "echo 'hello world';" change to "echoo 'hello world';").
Comment 5 Wojciech Galanciak CLA 2012-01-06 07:15:02 EST
Finally, it looks like your patch does not affect on bug 267008 so it can be committed.
Comment 6 Alex Panchenko CLA 2012-01-09 04:36:10 EST
Patch2 committed.