Community
Participate
Working Groups
Build ID: M20060921-0945 Steps To Reproduce: 1. Create a std make project such that the root of the project does not contain all sources. 2. Add some error in one of these external sources. 3. Build the project. 4. From the error in the problems view, right click and select "Open external file". 5. The file is opened but is not a C/C++ source file - note the editor icon and no content in the outline view. More information: CModelManager#createTranslationUnitFrom only works for external header files, not source files. The steps to reproduce is how I first saw the problem, but if you search for refererences on createTranslationUnitFrom you'll see that many places will have the same problem. I understand that the typical case is that all sources are under the project root and are hence IFile's, but that's not always the case. Originally I had that of changing the code in EditorUtility#getEditorInputForLocation like this: if (cproject != null) { ITranslationUnit unit = CoreModel.getDefault().createTranslationUnitFrom(cproject, location); if (unit == null) { String id = CoreModel.getRegistedContentTypeId(cproject.getProject(), location.lastSegment()); if (id != null) { unit = new ExternalTranslationUnit(cproject, location, id); } } if (unit != null) { return new ExternalEditorInput(unit, new FileStorage(location)); } But that would miss the other places that try to get a translation unit with a valid external path and project reference. So it seems the logical place to add this check is in CModelManager#createTranslationUnitFrom. Something like the attached patch. I'm not sure though if this is the best place for the change, or if it would have any bad side effects or not. Or if external source files were intentionally left out. But I can't think of a reason why they would be right now.
Created attachment 61383 [details] patch file
I am basically OK with the patch and don't see a problem, but it should be implemented as a fallback to the current behaviour of searching the include path first instead of overriding it. Otherwise, translation units for referenced header files might get different ICElement parents depending on how they are created.
(In reply to comment #2) > I am basically OK with the patch and don't see a problem, but it should be > implemented as a fallback to the current behaviour of searching the include > path first instead of overriding it. Otherwise, translation units for > referenced header files might get different ICElement parents depending on how > they are created. So just move the if (path.toFile().exists()) block I added below the first try/catch block. Sounds good to me.
I'll commit post M6.
Created attachment 62214 [details] Updated patch I changed the patch as indicated and made sure the content type id is computed only once (potentially expensive).
Applied patch to HEAD.