Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Linking in external file(How to enable link in external file)
Linking in external file [message #1784344] Tue, 27 March 2018 07:09 Go to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 142
Registered: June 2014
Senior Member
Hello,

I am trying to open a model file using File->Open file from menu.
File is in C:\Temp\test.MyDsl
File opened in editor.
But linking is not working.
If I click on reference, its not going to definition.

Sample grammar.
Clicking on Test under group is not going to its definition.
virag 1
Test 2

Group{
	Test
} 



Kindly help me with this.
I am expecting these cross reference should work.
Thanks in advance.

Best regards,
Virag Purnam
Re: Linking in external file [message #1784345 is a reply to message #1784344] Tue, 27 March 2018 07:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
this is not intended to work. opening files from outside eclipse is view only => you need projects

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Linking in external file [message #1784347 is a reply to message #1784345] Tue, 27 March 2018 07:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
see https://bugs.eclipse.org/bugs/show_bug.cgi?id=407831 too

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Linking in external file [message #1784353 is a reply to message #1784347] Tue, 27 March 2018 08:05 Go to previous messageGo to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 142
Registered: June 2014
Senior Member
Thanks for the reply.
I checked the same behaviour with external java file and tried opening with eclipse.
It opens and local references works fine in .java file.
Can we achieve same with model file? (Only local references)

[Updated on: Tue, 27 March 2018 08:11]

Report message to a moderator

Re: Linking in external file [message #1784363 is a reply to message #1784353] Tue, 27 March 2018 09:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes you need to customize the opener

import org.apache.log4j.Logger;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.ide.IDE;
import org.eclipse.xtext.ui.editor.LanguageSpecificURIEditorOpener;
import org.eclipse.xtext.ui.editor.utils.EditorUtils;

import com.google.inject.Inject;

public class MyDslLanguageSpecificURIEditorOpener extends LanguageSpecificURIEditorOpener {
	
	private static final Logger logger = Logger.getLogger(MyDslLanguageSpecificURIEditorOpener.class);
	
	@Inject(optional = true)
	private IWorkbench workbench;
	
	@Override
	public IEditorPart open(URI uri, EReference crossReference, int indexInList, boolean select) {
		IEditorPart result = super.open(uri, crossReference, indexInList, select);
		if (result == null && uri.isFile()) {
			try {
				IFileStore fileStore =  EFS.getLocalFileSystem().getStore(new Path(uri.toFileString()));
				FileStoreEditorInput editorInput = new FileStoreEditorInput(fileStore);
				IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
				final IEditorPart editor = IDE.openEditor(activePage, editorInput, getEditorId());
				selectAndReveal(editor, uri, crossReference, indexInList, select);
				return EditorUtils.getXtextEditor(editor);
			} catch (WrappedException e) {
				logger.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause());
			} catch (PartInitException partInitException) {
				logger.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException);
			}
		}
		return result;
	}

}
class MyDslUiModule extends AbstractMyDslUiModule {

	override void configureLanguageSpecificURIEditorOpener(com.google.inject.Binder binder) {
		if(PlatformUI.isWorkbenchRunning()) binder.bind(IURIEditorOpener).annotatedWith(LanguageSpecific).to(
			MyDslLanguageSpecificURIEditorOpener)
	}
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Linking in external file [message #1784533 is a reply to message #1784363] Thu, 29 March 2018 07:01 Go to previous messageGo to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 142
Registered: June 2014
Senior Member
Hi Mr, Christian Dietrich,

Binding is done.
But still local references are not working.
I mean on click it is not going to definition.

what can be the mistake on my code ?

Thanks and regards,
Virag Purnam
Re: Linking in external file [message #1784536 is a reply to message #1784533] Thu, 29 March 2018 07:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
please share a complete example

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Linking in external file [message #1784554 is a reply to message #1784536] Thu, 29 March 2018 10:00 Go to previous messageGo to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 142
Registered: June 2014
Senior Member
Here i have attached a sample project and sample file.
Please keep the file some where in system. e.g c:\temp\test.MyDsl

Open file using File->Open file and provide the path. e.g c:\temp\test.MyDsl
Expectation is that, local reference linking should work.

Thanks and regards,
Virag Purnam
  • Attachment: Example.zip
    (Size: 1.65MB, Downloaded 346 times)
  • Attachment: test.MyDsl
    (Size: 0.04KB, Downloaded 79 times)
Re: Linking in external file [message #1784558 is a reply to message #1784554] Thu, 29 March 2018 10:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
mydsl and MyDsl as file extension are not the same.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Linking in external file [message #1784561 is a reply to message #1784558] Thu, 29 March 2018 11:15 Go to previous messageGo to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 142
Registered: June 2014
Senior Member
Thanks.
It works.
Sorry for the silly mistake. Overlooked this extension part. (With Xtext project, both extensions are supported).
Thanks again.
Re: Linking in external file [message #1784569 is a reply to message #1784561] Thu, 29 March 2018 11:59 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
no they are not. it only parially works for partial usecases.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Load external metamodel for LSP using gradle
Next Topic:Regarding Compiler integration with Xtext
Goto Forum:
  


Current Time: Tue Apr 16 20:28:10 GMT 2024

Powered by FUDForum. Page generated in 0.63994 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top