Skip to main content



      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 03:09 Go to next message
Eclipse UserFriend
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 03:10 Go to previous messageGo to next message
Eclipse UserFriend
this is not intended to work. opening files from outside eclipse is view only => you need projects
Re: Linking in external file [message #1784347 is a reply to message #1784345] Tue, 27 March 2018 03:16 Go to previous messageGo to next message
Eclipse UserFriend
see https://bugs.eclipse.org/bugs/show_bug.cgi?id=407831 too
Re: Linking in external file [message #1784353 is a reply to message #1784347] Tue, 27 March 2018 04:05 Go to previous messageGo to next message
Eclipse UserFriend
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 04:11] by Moderator

Re: Linking in external file [message #1784363 is a reply to message #1784353] Tue, 27 March 2018 05:14 Go to previous messageGo to next message
Eclipse UserFriend
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)
	}
}
Re: Linking in external file [message #1784533 is a reply to message #1784363] Thu, 29 March 2018 03:01 Go to previous messageGo to next message
Eclipse UserFriend
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 03:28 Go to previous messageGo to next message
Eclipse UserFriend
please share a complete example
Re: Linking in external file [message #1784554 is a reply to message #1784536] Thu, 29 March 2018 06:00 Go to previous messageGo to next message
Eclipse UserFriend
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 378 times)
  • Attachment: test.MyDsl
    (Size: 0.04KB, Downloaded 101 times)
Re: Linking in external file [message #1784558 is a reply to message #1784554] Thu, 29 March 2018 06:25 Go to previous messageGo to next message
Eclipse UserFriend
mydsl and MyDsl as file extension are not the same.
Re: Linking in external file [message #1784561 is a reply to message #1784558] Thu, 29 March 2018 07:15 Go to previous messageGo to next message
Eclipse UserFriend
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 07:59 Go to previous message
Eclipse UserFriend
no they are not. it only parially works for partial usecases.
Previous Topic:Load external metamodel for LSP using gradle
Next Topic:Regarding Compiler integration with Xtext
Goto Forum:
  


Current Time: Fri Jun 20 19:37:01 EDT 2025

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

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

Back to the top