Skip to main content



      Home
Home » Modeling » TMF (Xtext) » How to create complete code suggestions in Xtext Eclipse Plugin?(How to create complete syntax suggestions in Xtext Eclipse Plugin instead of having suggestions for keyword by keyword?)
How to create complete code suggestions in Xtext Eclipse Plugin? [message #1799648] Tue, 11 December 2018 22:26 Go to next message
Eclipse UserFriend
Hi,
I'm creating an Eclipse language plugin using Xtext. As of now, when I run the plugin, I get keyword suggestions when I press Ctrl+space. However, the keywords are suggestion one-by-one. i.e, I need to press Ctrl+space four times if the syntax has four keywords.
Quote:

eg: - if the complete syntax is 'entityset <entityname> for <entityunit>' then, when I pressed Ctrl+space once, it will suggest 'entity', then, again when I entered Ctrl+space it will suggest '<entityname> and so on. Instead I want it to suggest the complete syntax by just one Ctrl+space.

My question is, how do I make it in a way, that when I press Ctrl+space, the entire syntax will be suggested?
Below is my code: -
Domainmodel:
	(elements+=MainElement)*
;

MainElement:
	FileName | Type 
;

Type:
	Component | Layer | Description | Category | Entity | Comment
;

FileName:
	'projection' name=ID ';'
;

Component:
	'component' name=ID ';'
;

Layer:
	'layer' name=ID ';'
;

Description:
	'description' string=STRING ';'
;

Entity:
	'entityset' name=ID 'for' name2=ID ';'
;

Comment:
	'----------' comment=ID '----------'
;

[Updated on: Tue, 11 December 2018 22:27] by Moderator

Re: How to create complete code suggestions in Xtext Eclipse Plugin? [message #1799656 is a reply to message #1799648] Wed, 12 December 2018 00:42 Go to previous messageGo to next message
Eclipse UserFriend
The thing you are looking for in called template proposals (see docs)
Re: How to create complete code suggestions in Xtext Eclipse Plugin? [message #1800033 is a reply to message #1799656] Wed, 19 December 2018 04:06 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
I looked for examples on template proposals, but I couldn't quite find a simple example. I found this posthttps://kthoms.wordpress.com/2012/05/22/xtext-content-assist-filtering-keyword-proposals/ from which I copied the first given code sample and my MyDslProposalProvider.xtend file looks like below: -

/*
 * generated by Xtext 2.15.0
 */
package org.xtext.example.mydsl.ui.contentassist

import org.eclipse.xtext.Keyword

/**
 * See https://www.eclipse.org/Xtext/documentation/304_ide_concepts.html#content-assist
 * on how to customize the content assistant.
 */
class MyDslProposalProvider extends AbstractMyDslProposalProvider {
	private static final Set&lt;String&gt;      FILTERED_KEYWORDS = Sets.newHashSet("text", "line", "class", "behavior", "style", "custom");
    @Override
    public void completeKeyword(Keyword keyword, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) {
        if (FILTERED_KEYWORDS.contains(keyword.getValue())) {
            // don't propose keyword
            return;
        }
        super.completeKeyword(keyword, contentAssistContext, acceptor);
    }
}


However this does not appear to be correct. get errors for the below listed keywords (keyword: "error") : -


Set&lt;     : "no viable alternative at input '&'", "lt cannot be resolved to a type.", "no viable alternative at input ';'"
String&gt     : "no viable alternative at input '&'", "gt cannot be resolved to a type.", "no viable alternative at input ';'"
FILTERED_KEYWORDS =      :    "FILTERED_KEYWORDS cannot be resolved to a type.", "no viable alternative at input '='"
@Override      :      "The annotation @Override is disallowed for this location."
void     :      "Primitive void cannot be a dependency."
Keyword keyword       :      "mismatched input 'keyword' expecting ')'"


Could you please let me know whether this is the correct approach and why these errors occur? I'll explain my question again.
Instead of code suggestions appearing for each keypress of Ctrl+space, I need the complete code to be suggested.
Eg:- If the full expression is : Hello from Xext !
I want the whole sentence to be suggested instead of having Ctrl+space= Hello, Ctrl+space= from, Ctrl+space= Xtext, Ctrl+space= !

Regards!

[Updated on: Wed, 19 December 2018 04:07] by Moderator

Re: How to create complete code suggestions in Xtext Eclipse Plugin? [message #1800035 is a reply to message #1800033] Wed, 19 December 2018 04:11 Go to previous messageGo to next message
Eclipse UserFriend
java is not xtend.
you can convert java code to xtend code by rightklick paste java code
Re: How to create complete code suggestions in Xtext Eclipse Plugin? [message #1800036 is a reply to message #1800035] Wed, 19 December 2018 04:29 Go to previous messageGo to next message
Eclipse UserFriend
It is working. But now when I go to the runtime and press Ctrl+space, nothing happens. However, after I manually typed the first keyword 'Hello', keywords are suggested by each press of Ctrl+space. It is the same as before. The only thing that has happened is 'Hello' keyword not being suggested at all.
Below is my ProposalProvider file: -

package org.xtext.example.mydsl.ui.contentassist

import org.eclipse.xtext.Keyword
import com.google.inject.Inject
import org.xtext.example.mydsl.services.MyDslGrammarAccess
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor

class MyDslProposalProvider extends AbstractMyDslProposalProvider {
	@Inject package MyDslGrammarAccess grammarAccess
	override void completeKeyword(Keyword keyword, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) {
		if (!grammarAccess.getGreetingAccess().getHelloKeyword_0().equals(keyword)) {
			super.completeKeyword(keyword, contentAssistContext, acceptor) 
		}
	}
}


I read the explanation in the Doc, but I don't exactly understand the procedure that I should follow or where to actually start. Is it required to write a .xml file configuring the proposal templates that I need to implement, or can I directly do it using the ProposalProvider file? Could you kindly explain?
Re: How to create complete code suggestions in Xtext Eclipse Plugin? [message #1800047 is a reply to message #1800036] Wed, 19 December 2018 05:34 Go to previous messageGo to next message
Eclipse UserFriend
is the method called or not? what is your goal. what the grammar you use?
Re: How to create complete code suggestions in Xtext Eclipse Plugin? [message #1800050 is a reply to message #1800047] Wed, 19 December 2018 05:59 Go to previous messageGo to next message
Eclipse UserFriend
I'm sorry, I used the below basic grammar for this ProposalProvider implementation: -

grammar org.xtext.example.mydsl.MyDsl with org.xtext.example.mydsl.MyDsl2

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"


Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID '!';


I need the complete Greeting rule to be proposed by one Ctrl+space press.
Re: How to create complete code suggestions in Xtext Eclipse Plugin? [message #1800051 is a reply to message #1800050] Wed, 19 December 2018 06:07 Go to previous messageGo to next message
Eclipse UserFriend
I still cannot follow you
What is the behavior without customization
What is the expected behavior
What is the actual behavior with customization
Re: How to create complete code suggestions in Xtext Eclipse Plugin? [message #1800054 is a reply to message #1800051] Wed, 19 December 2018 06:14 Go to previous messageGo to next message
Eclipse UserFriend
Behaviour without customization: In runtime, when I press Ctrl+space in a blank .dsl file, I first get 'Hello' keyword suggested. After Hello keyword, when I again press Ctrl+space, I get 'name-ID' suggested. Finally, when I again press Ctrl+space after 'name-ID', eclipse suggests '!'

Expected Behaviour: I need the complete code (Hello name !) to appear by just pressing Ctrl+space only one time. That is, I want the complete expression's template to appear in my file when I select the suggestion so that I will only need to change the variables. In my expected behavior, I do not have to press Ctrl+space 3 times to get the whole expression, but only once.

Actual Behaviour with customization: When I press Ctrl+space once in the blank .dsl file, nothing happens. If I manually typed 'Hello' and then pressed Ctrl+space, Eclipse suggests 'name-ID'. Then again when I press Ctrl+space, it suggests '!'

[Updated on: Wed, 19 December 2018 06:15] by Moderator

Re: How to create complete code suggestions in Xtext Eclipse Plugin? [message #1800061 is a reply to message #1800054] Wed, 19 December 2018 07:08 Go to previous message
Eclipse UserFriend
this is what template proposals are for. (didnt we had this before)
Previous Topic:Differences in auto-suggest in Xtext Eclipse DSL plugins
Next Topic:Disable DocumentSymbolService for Binary Files
Goto Forum:
  


Current Time: Mon Jun 16 06:56:31 EDT 2025

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

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

Back to the top