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

Bug 446319

Summary: Xtext-based editors should also work on files with non-matching file extension
Product: [Modeling] TMF Reporter: Moritz Eysholdt <moritz.eysholdt>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: anton, error-reports-inbox, ldubox-coding101, sebastian.zarnekow, sven.efftinge
Version: 2.8.0   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X   
Whiteboard: v2.7.3

Description Moritz Eysholdt CLA 2014-10-08 10:03:23 EDT
Steps to reproduce:

1. Create file "test.foo".
2. Open with "Xtext Editor" (yes, the grammar editor)
3. Type something.
4. get the exaction below. 

Expected behavior: 
No exceptions, maybe error annotations indicating "text.foo" isn't a syntactically valid Xtext grammar.

Proposed solution:
org.eclipse.xtext.ui.editor.DirtyStateEditorSupport.announceDirtyState(XtextResource) should get its ResourceServiceProvider from the XtextResource and *not* from the registry.


java.lang.NullPointerException
	at org.eclipse.xtext.ui.editor.DirtyStateEditorSupport.getResourceDescriptionManager(DirtyStateEditorSupport.java:496)
	at org.eclipse.xtext.ui.editor.DirtyStateEditorSupport.announceDirtyState(DirtyStateEditorSupport.java:466)
	at org.eclipse.xtext.ui.editor.reconciler.XtextDocumentReconcileStrategy.postParse(XtextDocumentReconcileStrategy.java:160)
	at org.eclipse.xtext.ui.editor.reconciler.XtextDocumentReconcileStrategy.doReconcile(XtextDocumentReconcileStrategy.java:146)
	at org.eclipse.xtext.ui.editor.reconciler.XtextDocumentReconcileStrategy.reconcile(XtextDocumentReconcileStrategy.java:65)
	at org.eclipse.xtext.ui.editor.reconciler.XtextReconciler.doRun(XtextReconciler.java:401)
	at org.eclipse.xtext.ui.editor.reconciler.XtextReconciler.access$3(XtextReconciler.java:386)
	at org.eclipse.xtext.ui.editor.reconciler.XtextReconciler$1.process(XtextReconciler.java:327)
	at org.eclipse.xtext.ui.editor.reconciler.XtextReconciler$1.process(XtextReconciler.java:1)
	at org.eclipse.xtext.util.concurrent.IUnitOfWork$Void.exec(IUnitOfWork.java:36)
	at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.modify(XtextDocument.java:418)
	at org.eclipse.xtext.ui.editor.model.XtextDocument.internalModify(XtextDocument.java:131)
	at org.eclipse.xtext.ui.editor.reconciler.XtextReconciler.run(XtextReconciler.java:324)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Comment 1 Sebastian Zarnekow CLA 2014-10-08 10:05:02 EDT
This is a regression. There was also some guy on the newsgroup who stumbled upon it.
Comment 2 Moritz Eysholdt CLA 2014-10-08 10:10:27 EDT
In my case it's a bug reported for Xpect:
https://github.com/meysholdt/Xpect/issues/153
Comment 3 Luke Usherwood CLA 2014-10-08 11:38:39 EDT
(Hi, I'm the Xpect ticket logger...)

Maybe this functionality targets some different use-cases to ours, but personally I'd rather the development environment did not activate XText-based editors for DSLs under development. (*.dmodel files.)  I would expect them to be enabled in the runtime-eclipse environment only.

Certainly in our current state of development (e.g. with complex, partially-implemented and bug-ridden Scope Providers) it sounds like a recipe for fragility.

(I'm also undecided whether I'd want DSL-editing functionality for *.dmodel.xt files in Xpect - I'm leaning towards no, but then again maybe it will prove useful later...)

Anyway, I guess the main topic here is the regression/crashes.
Comment 4 Sven Efftinge CLA 2014-10-09 02:15:17 EDT
(In reply to Luke Usherwood from comment #3)
> Maybe this functionality targets some different use-cases to ours, but
> personally I'd rather the development environment did not activate
> XText-based editors for DSLs under development. (*.dmodel files.)  I would
> expect them to be enabled in the runtime-eclipse environment only.

Not sure I understand, but of course DSLs under development, i.e. in the workspace are not being activated automagically. You need to install them or start a runtime-eclipse environment if you want to use that language tooling.
Comment 5 Moritz Eysholdt CLA 2014-10-09 03:33:03 EDT
(In reply to Luke Usherwood from comment #3)
> Maybe this functionality targets some different use-cases to ours, but
> personally I'd rather the development environment did not activate
> XText-based editors for DSLs under development. (*.dmodel files.)  I would
> expect them to be enabled in the runtime-eclipse environment only.

Your expectation holds true... Xtext only enables editors when the language has been installed into the running eclipse. And Xtext only enables editors for files with a file extension the language has been registered for. 

This bugzilla ticket complains that if you open an editor from an installed language via "Open With" -> "Other..." -> (pick editor from dialog) on a file with a non-matching file externs, the NPE is thrown.

> Certainly in our current state of development (e.g. with complex,
> partially-implemented and bug-ridden Scope Providers) it sounds like a
> recipe for fragility.

Luckily its not fragile because when your language isn't installed your code won't be executed. 

When Xpect offers an editor on your files (e.g. *.dmodel.xt), and the model language is not installed, then the Xpect editor will only support the XPECT-syntax. 

Xpect offers an editor on all text files that seem to contain XPECT-statements. 

> (I'm also undecided whether I'd want DSL-editing functionality for
> *.dmodel.xt files in Xpect - I'm leaning towards no, but then again maybe it
> will prove useful later...)

It's only the DSL-editing functionality for the Xpect-syntax. To get the editor that has DSL-editing functionality for XPECT-syntax and dmodel-syntax, the dmodel-language needs to be installed.
Comment 6 Luke Usherwood CLA 2014-10-09 04:59:48 EDT
Right, so the fact that I happened to trigger this on a file called "*.dmodel" was not relevant. Thanks for the clarifications.
Comment 7 Moritz Eysholdt CLA 2014-10-09 05:15:52 EDT
pushed fix to https://git.eclipse.org/r/#/c/34629/

we decided offline for a different solution strategy than initially proposed. From the commit message:
The DirtyStateEditorSupport should only announce resources as dirty state,
if the resource's language is the same as the lanugage registered for 
the resource's URI. 

E.g. If you open an "Arithmetics Editor" on "foo.xtext", the edtor sould
not contribute dirty state because its exportet IResourceDescription
can be significalty different (based on the arithmetics language) compared to
what clients expect (IResourceDescription based on the Xtext language).
Comment 8 Luke Usherwood CLA 2014-10-09 09:24:40 EDT
Great stuff, thanks for the quick fix!
Comment 9 Sebastian Zarnekow CLA 2014-11-05 08:20:26 EST
This is already fixed. Also available for 2.7.3.

Moritz, please reopen if there are any open ends.
Comment 10 Sven Efftinge CLA 2014-11-21 02:29:51 EST
*** Bug 446693 has been marked as a duplicate of this bug. ***