Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross-referencing challenges
Cross-referencing challenges [message #1831165] Wed, 12 August 2020 18:52 Go to next message
Waqas Ilyas is currently offline Waqas IlyasFriend
Messages: 80
Registered: July 2009
Member
Hi,

I worked on a DSL (devicetree) some while ago and I am returning back to it after quite some time to add new capabilities. Below are some of the challenges I am facing, and hoping to validate my findings. I have quite a few questions, so I will start with one first, and rest in later posts.

Example tree:
/{
  aa: x {
    p = "1";
    y {
    };
  };
};
&{/x/y} {
  p2 = "2";
};
&aa {
  p3 = "3";
}


Problem 1:
This language allows referencing other nodes via a node path (as &{/x/y} above) and "label" (as aa: above). How can I define the grammar for these paths like behavior with references. The label thing is easy but can this work with paths as a cross-reference? Does below grammar make sense?
Label:
	name=ID ':'
;
Node:
	(lb=Label)? name=ID
	'{'
		//....
	'}' ';'
;
Reference:
	'&' ( label=[Label|REFERENCE_ID] | path=[Node|REFERENCE_PATH ])
;
ExtensionNode:
	reference=Reference
	'{'
		//....
	'}' ';'
;


A few challenges here, that I am using JFlex so I am not fully flexible on terminal tokens above. So I need to ensure that whenever "path" is being matched with anything I strip the "&{ }" ... Is the value converter the proper way to do this?

Also I need to ensure that qualified names are calculated using "/", for matching with references, so I think I need a custom IQualifiedNameConverter through bindIQualifiedNameProvider in my module. Correct? Because it seems like the existing scoping logic depends on qualified names to find references.

More questions later....
Re: Cross-referencing challenges [message #1831166 is a reply to message #1831165] Wed, 12 August 2020 19:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes you can use the QualifiedNameConverter. you could also use the IValueConverter.
see org.eclipse.xtext.linking.impl.LinkingHelper.getCrossRefNodeAsString(INode, boolean)
and org.eclipse.xtext.linking.impl.DefaultLinkingService.getLinkedObjects(EObject, EReference, INode)

for binding: IQualifiedNameConverter != IQualifiedNameProvider
you add a bindIQualifiedNameConverter if you need.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross-referencing challenges [message #1831168 is a reply to message #1831166] Wed, 12 August 2020 21:20 Go to previous messageGo to next message
Waqas Ilyas is currently offline Waqas IlyasFriend
Messages: 80
Registered: July 2009
Member
Thanks a lot! using a qualified converter, I was able to achieve some success. I will also try value converters soon.

Another problem is, that each element can be identified in two ways. It can have a "label" and a "name". The reference that someone specifies can use a label "&some_label" or a path "&{/a/b/c}". How can I add the same node more than once to a scope? Once for label, and once for name.

Or perhaps override the point where the match happens to detect whether to match labels or qualified names?

Or perhaps create my own scope by adding each such node twice in my IScopeProvider? if existing built in functionality can't support my case. Also note that a label on a node is saved in "lb" and not "name" property obviously .
Re: Cross-referencing challenges [message #1831177 is a reply to message #1831168] Thu, 13 August 2020 05:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you can either do the scope manually or index the element twice (customize org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy.createEObjectDescriptions(EObject, IAcceptor<IEObjectDescription>) and/or org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.internalGetAllDescriptions(Resource)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross-referencing challenges [message #1831179 is a reply to message #1831177] Thu, 13 August 2020 06:13 Go to previous messageGo to next message
Waqas Ilyas is currently offline Waqas IlyasFriend
Messages: 80
Registered: July 2009
Member
Thanks again, while waiting for our reply I did try to create a scope manually which worked, with certain limitations. What I have realized is that I don't need to index elements twice because the Label is a type so does appear as a child and included in the scope. But it is scoped based on its occurrence in node hierarchy and expected to be reached using qualified name (if i understood correctly). I want all Labels to be in top level scope, so that they don't need any qualified access to resolve reference (as in example tree above). So I guess, my choice is to build a scope myself, or perhaps override the global scope provider, what's better? Or maybe just override behavior of qualified name calculation?

Another thing. I don't want all nodes from all files in the project to be in global scope. I need to limit that based on "include" directives in this devicetree file. I imagine this is a common usage in many languages, but I am not sure where to begin with this? Do i need to build a scope myself by inspecting "includes" and reading other resources. Or can I leverage something built-in?

Does this ImportedNamespaceAwareLocalScopeProvider of help here? How are "imports" or "includes" declared or described in grammar? I was looking at the domainmodel example and perhaps "importedNamespace" is a special attribute?
Re: Cross-referencing challenges [message #1831197 is a reply to message #1831179] Thu, 13 August 2020 12:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you can filter delegateGetScope(ctx, ref) in your scope provider for aliasedeobjectdescriptions (imported onces) andor once from local resource

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross-referencing challenges [message #1831198 is a reply to message #1831197] Thu, 13 August 2020 12:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you might also try out old ImportUriGlobalScopeProvider

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross-referencing challenges [message #1831216 is a reply to message #1831198] Fri, 14 August 2020 01:11 Go to previous messageGo to next message
Waqas Ilyas is currently offline Waqas IlyasFriend
Messages: 80
Registered: July 2009
Member
Some updates... So i added a IQualifiedNameProvider in addition to qualified name converter, so that when we calculate qualified name for a Label, we strip the leading qualifiers added because of its parents. This gives it that "global" matching ability. With this I don't need to create my scope from scratch.

The next thing is to limit the scope of other resources in project based on "inclusion". I will look at the options you mentioned. Thank you for that.

[Updated on: Fri, 14 August 2020 04:55]

Report message to a moderator

Re: Cross-referencing challenges [message #1831248 is a reply to message #1831216] Sat, 15 August 2020 07:05 Go to previous messageGo to next message
Waqas Ilyas is currently offline Waqas IlyasFriend
Messages: 80
Registered: July 2009
Member
The ImportUriGlobalScopeProvider worked well. However, it doesn't recursively find imported resources chain. I think I will need to add that myself.

Also a few more cross-referencing question... I am trying to add some helping tooltip. And I tried adding my own binding for IEObjectDocumentationProvider to show customized tooltip. However, I only get an EObject to inspect, and I can't tell if that EObject's occurrence is where it is defined, or where it is being referenced. I would like to show different tooltips in each case. Any solution to that?

Another thing; to keep my builder lenient until I have confidence in my grammar (or rich enough feature-set in editor to enforce strict checks), I would like the builder to avoid any "error" markers on the resources in IDE. I am ok for the editor to show error markers in editor but would like to avoid markers on workspace. How can I achieve that?
Re: Cross-referencing challenges [message #1831258 is a reply to message #1831248] Sat, 15 August 2020 16:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
You would need custom code and maybe also customize indexing to do recursive imports

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross-referencing challenges [message #1831295 is a reply to message #1831258] Mon, 17 August 2020 00:19 Go to previous messageGo to next message
Waqas Ilyas is currently offline Waqas IlyasFriend
Messages: 80
Registered: July 2009
Member
ok, but what about the tooltip question? Any way to have tooltips different for reference location, and actual definition of "referenced" eobject?
Re: Cross-referencing challenges [message #1831302 is a reply to message #1831295] Mon, 17 August 2020 06:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
thsi would work with real references or heavy customization
you could index the model roots under their file name and have references
or you need to customize hover


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross-referencing challenges [message #1831340 is a reply to message #1831302] Mon, 17 August 2020 18:01 Go to previous messageGo to next message
Waqas Ilyas is currently offline Waqas IlyasFriend
Messages: 80
Registered: July 2009
Member
I am sorry, but I did not fully understand. My problem is that I want different tooltips, when the mouse hovers over the actual node, and a different one when the mouse hovers over a reference to that particular node. In the tree example above, basically I need show a tooltip like "Ctrl+Click to open definition" (and other details) on text "&aa {", but I don't want the same tooltip to appear when the mouse hovers over "aa: x {" text.

In IEObjectDocumentationProvider you only get an EObject, how do differentiate the two cases?
Re: Cross-referencing challenges [message #1831348 is a reply to message #1831340] Mon, 17 August 2020 19:58 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Xtext provides fgood functionality for straightforward cases. If you want something more specialized you need to code the specialization. For OCL I make a similar hover distinction. Debug the production of the hover message and choose somewhere on the call tree to override that is convenient and has the context you need.

If you need some examples ...

	// contributed by org.eclipse.ocl.examples.build.fragments.MarkupHoverFragment
	public Class<? extends org.eclipse.xtext.ui.editor.hover.IEObjectHover> bindIEObjectHover() {
		return org.eclipse.ocl.xtext.markup.ui.hover.MarkupHover.class;
	}

	// contributed by org.eclipse.ocl.examples.build.fragments.MarkupHoverFragment
	public Class<? extends org.eclipse.xtext.ui.editor.hover.IEObjectHoverProvider> bindIEObjectHoverProvider() {
		return org.eclipse.ocl.xtext.markup.ui.hover.MarkupHoverProvider.class;
	}

	// contributed by org.eclipse.ocl.examples.build.fragments.MarkupHoverFragment
	public Class<? extends org.eclipse.xtext.documentation.IEObjectDocumentationProvider> bindIEObjectDocumentationProvider() {
		return org.eclipse.ocl.xtext.base.ui.model.BaseDocumentationProvider.class;
	}

	// contributed by org.eclipse.ocl.examples.build.fragments.MarkupHoverFragment
	public Class<? extends org.eclipse.jface.text.ITextHover> bindITextHover() {
		return org.eclipse.ocl.xtext.markup.ui.hover.MarkupCompositeHover.class;
	}


Regards

Ed Willink
Re: Cross-referencing challenges [message #1831355 is a reply to message #1831348] Tue, 18 August 2020 01:56 Go to previous message
Waqas Ilyas is currently offline Waqas IlyasFriend
Messages: 80
Registered: July 2009
Member
Thanks for the suggestion Ed. I wanted to make sure that I am not missing some obvious way of doing things before trying to a lot of customizations myself. Thanks for the confirmation.

And Thanks a lot Christian Dietrich for all the help. As always your quick and helpful answers have guided me to the objectives I needed to meet.

By the way, for reference, I bound my own IResourceUIValidatorExtension in the UI module to avoid creating markers on the eclipse workspace resources.
Previous Topic:Terminal Rule vs. Keyword Prioritization
Next Topic:Bundle activator on xtext
Goto Forum:
  


Current Time: Thu Apr 25 07:43:34 GMT 2024

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

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

Back to the top