Disabling code completion menu based on some flag using Substitute menu and also retrieving default code-completion behavior

1. Consider I have a root concept ClassRoom whose contents are IClassContent[0...n] (an interface).
2. Two classes namely Student & Board implement IClassContent.
 Now in code completion if we press Ctrl+Space at content of classroom, we are getting two entries.(aliases of both Student & Board which are student & board respectively).

Now i want to show the code completion entry for Student, only when a flag is enabled. So i have created a default substitute menu for concept as shown.

But this doesn't show the entry when we press Ctrl+Space without typing anything. Earlier both entries(student and board) will be shown in the code-completion menu.  So i modified the return statement as 
return pattern.equals(conceptAlias) || pattern.isEmpty;

Now the entry is shown in code completion menu. But as soon as i type , the Student node is created. I found that second condition pattern.isEmpty is true now and hence the node is created.
But the expected behavior is the node should be created only when complete 'student' is typed(Need the default behavior exhibited before the introduction of substitute menu). How to achieve this?

Comment actions Permalink

You should leverage the "strictly" parameter and also handle the cases when the user has not typed in the whole "student" word yet:

if (strictly) { 
return "student".equals(pattern);
} else {
return "student".startsWith(pattern) || pattern.isEmpty;

MPS calls your "can substitute" function twice, once with "strictly" set to false and once with "strictly" set to true, to test, whether the match is partial or complete.

Comment actions Permalink

It works as expected :) . Thanks for the quick response @Vaclav

Comment actions Permalink

You can also put this action under the "group" part with the condition which checks the flag, so you won't need to override the "can substitute"


Please sign in to leave a comment.