Community
Participate
Working Groups
Consider this scenario: void foo { "string"; } The definition of foo has the context type of "functionDef". Inside foo, we have context type of "block". The string "string" is a "localLiteral" I have defined a code template for the context type "functionDef" The code template shows up as expected when I am at the context of "functionDef". However, when I place the cursor inside the double quotes, my template also shows up in content assist unexpectedly. I have seen similar problem in the XText editor. I created a template at the "Action" scope, then inside a keyword, invoke content assist. My template for the "Action" scope will show up. RuleName: 'myKeyword' ...; I tried to debug the problem. I found that when I am inside the double quotes, XText creates extra contexts and would ask me for template proposals for all the elements that are parent to the current local literals. In these contexts, the prefix is missing, and the template proposal provider has no choice but to provide template based on the context type given. When the cursor is outside of the ", there is only one context, and that context does reflect the current location, with prefix information. I traced it to ParserBasedContentAssistContextFactory. It seems to me that the extra contexts are created by the "4th context". But I do not understand why these contexts are causing problems, and how we can get around this problem.
Hello, Is there anyway to help me get around this problem? Thanks! Samantha
Hi Samantha, you could try to override org.eclipse.xtext.ui.editor.templates.AbstractTemplateProposalProvider.validate(Template, ContentAssistContext) and use the information from the content assist context (offset and last complete node) to identify invalid templates. Regards, Sebastian
Could you please provide a reproducable example? Thanks.
Created attachment 188100 [details] template proposals inside strings I'm also seeing this after adding template proposals via templates.xml, see attached screenshot. Unfortunately, I cannot reproduce it using a simple DSL. You can reproduce it following these steps though: - git clone git://github.com/ralfebert/applitude.git - git checkout 0998b121903c07cbe7c2f413e914af274cbc3dee - Import tooling/* plug-ins - Run and import examples/demo/ - Open examples/demo/demo.applitude - Press Ctrl+Space on line 55 right after the opening brace -> Template proposals for surrounding elements are offered inside STRING
Pushed to master.
Closing all bugs that were set to RESOLVED before Neon.0