Home > Xtext > Xtext Content Assist Auto Activation

Xtext Content Assist Auto Activation

Xtext offers nice Content Assist facilities. JDT offers a nice additional feature: Content assist is autoactivated if a certain character (.) is typed. To activate this feature in Xtext simply customize your UiModule

	
public class MyDslUiModule extends org.xtext.example.mydsl.ui.AbstractMyDslUiModule {
public MyDslUiModule(AbstractUIPlugin plugin) {
		super(plugin);
	}
	
	@Override
	public void configure(Binder binder) {
		super.configure(binder);
	binder.bind(String.class)
.annotatedWith(com.google.inject.name.Names.named(
(XtextContentAssistProcessor.COMPLETION_AUTO_ACTIVATION_CHARS)))
.toInstance(".,:");
	}
}

In this case content assist is autoactivated on . , and :

Advertisements
  1. September 20, 2011 at 08:47

    Very nice!

  2. Axel Terfloth
    September 22, 2011 at 21:27

    good to know…

  3. November 23, 2011 at 20:58

    Is it also possible to use NEWLINE or TAB for auto activation? Or is another approach required?

    • November 23, 2011 at 21:26

      binder.bind(String.class)
      .annotatedWith(com.google.inject.name.Names.named(
      (XtextContentAssistProcessor.COMPLETION_AUTO_ACTIVATION_CHARS)))
      .toInstance(” \t”);

      works for me

  4. December 12, 2011 at 20:36

    Thank you! The tab auto activation works indeed, a newline with \n did not work on windows. The solution was \r\n like:

    String eol = System.getProperty(“line.separator”);
    binder.bind(String.class).annotatedWith(com.google.inject.name.Names.named((XtextContentAssistProcessor.COMPLETION_AUTO_ACTIVATION_CHARS)))
    .toInstance(” \t” + eol);

    • Michal
      April 25, 2012 at 08:12

      Thank you for this nice how-to… Made usage nicer!
      I am getting only little imperfection, if I use previous example with “eol”: It provides content assist in the end of line and also on the beginning of new line :(. I would need assist only on newline. Any suggestion to this?

      • April 25, 2012 at 08:19

        no i do not know the backend of the code in that detail. Guess you have to debug yourself

  5. Brad
    May 10, 2012 at 21:48

    Is it possible to activate the content assist mechanism after entering certain grammar keywords too?

  6. Hans Peterson
    May 27, 2012 at 17:03

    I hava a basici question to this Xtext Content Assist Auto Activation:

    Do I need to create this class MyDslUiModule under the src or src-gen folder?

    • May 27, 2012 at 20:27

      Hi,

      not create! edit – it is already there. btw it is never a good idea to create any custom class or to edit any class in the src-gen folder since it will be erased when you run the workflow

  7. Latha
    July 12, 2012 at 04:57

    Could we customize this auto activation to work only in selected scenarios? For example, I do not want the auto content assist in case of comments. Is there a way to achieve this?

    • July 18, 2012 at 06:22

      Sorry I don’t know that. Guess you have to look at the code yourself

  8. Ed Willink
    August 3, 2013 at 10:46

    It might be worth adding the Fragment configuration as well

    bindFactory.addConfiguredBinding(String.class.getName(), “binder.bind(String.class).annotatedWith(com.google.inject.name.Names.named((org.eclipse.xtext.ui.editor.contentassist.XtextContentAssistProcessor.COMPLETION_AUTO_ACTIVATION_CHARS))).toInstance(\”.,:\”);”);

  9. Puneet Patwari
    November 21, 2014 at 13:03

    Hi

    I tried the above approach but it is not working at all. I have to still press ctrl+space. đŸ˜¦
    Please help.

    • November 24, 2014 at 11:17

      can you give more details on what you are exactly? the best place to do so would be in the tmf xtext part of eclipse forum or at Stackoverflow

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: