I work for Adobe Systems and I have been part of ColdFusion Engineering Team for almost 5 years now. Off late I have been involved in delevlopment of ColdFusion Builder, and I also had my share of work on the ColdFusion Server. sandeep is a DZone MVB and is not an employee of DZone and has posted 4 posts at DZone. View Full User Profile

How to contribute to code assist from Extensions

05.07.2011
| 4957 views |
  • submit to reddit

One of new feature in ColdFusion Builder 2 is the ability to contribute to code assist using extensions. This means that code assist proposals can be contributed using CFML. This allows users to create extensions which provide editor support for given framework or for any other code assist usage.

What contributing to code assist means?

It allows ColdFusion Builder extensions to add their own proposals in code assist popup dialog. Contributed proposals are shown in code assist dialog after regular proposals available through ColdFusion Builder.

How Do I add code assist contribution?

Extensions can specify that they want to contribute to Code assist by specifying this in ide_config.xml inside”<codeassistcontribution>”tag.

eg.


<codeassistcontribution>

<functions>

<!— contributions for functions—>

<functions>

<variables>

<!— contributions for variables—>

<variables>

</codeasistcontribution>

 

What use-cases are supported for code assist contribution?

a. Contribute code assist proposals for a given function parameters. So suppose if there is a function named “foo” which can take three arguments, I can add code asssit proposals for function foo()’s argument 1 or argument 2 or argument 3 or for all of them.

This means if user invokes content assist for code shown below at given cursor position he will see code assist contributions for arguments 1 ,2 and 3 coming from extension

<cfset foo(|) > , <cfset foo(“arg1”, |)>, <cfset foo(“arg1”, “arg2”, |)>
Code Assist Contribution for Function Arguments

Code Assist Contribution for Function Arguments

Sample code for ide_config.xml:

<codeassistcontribution>

<functions>

<function name=”foo“ handlerId=”">

<parameter index=”1“ />

<parameter index=”2“ />

<parameter index=”3“ />

</function>

</functions>

</codeassistcontribution>

b. Contribute code assist proposals for a given function invoked on a specific variable. This is similar to previous one with one basic difference. Let’s assume if there is a variable say ”event” available through some framework. And one can invoke function foo() on it. You can now contribute to code assist proposals for this function foo()’s arguments only when it is invoked on “event” variable. So contributed code assist proposals will only be shown for following cases-

<cfset event.foo(|) >, <cfset event.foo(“arg1”, |)>, <cfset event.foo(“arg1”, “arg2”, |)>

Sample code for ide_config.xml:

<codeassistcontribution>

<functions>

<function name=”foo” variablename=”event” handlerId=”">

<parameter index=”1“ />

<parameter index=”2“ />

<parameter index=”3“ />

</function>

</functions>

</codeassistcontribution>

c. Contribute code assist proposals for a specific variable. It can be used to add code assist support for scoped framework variables. This allows to display functions and member variables available on a given variable. So again taking back example of “event” variable, let’s assume that functions foo1(), foo2() and variables “var1” and “var2” are available on it. So now extensions can show these available options on this variable by contributing to code assist. These will be displayed when users presses “.” on event variable on invokes content assist in following case

<cfset event.| >

Code Assist Contribution for Variable

Sample code for ide_config.xml:

<codeassistcontribution>

<variables>

<variable variablename=”event” handlerId=”">

</variable>

</variables>

</codeassistcontribution>

 


How it works

Once content assist is invoked on specified function arguments or variable, handler identified with handlerid is called with details about code assist invocation.

These details include

· Function or variable name on which code assist was invoked.

· Index of argument in case of function

· CFC path in case code assist is invoked on variable which is a CFC instance.


Demo Extension

You can download sample demo extension form here to see code assist contribution working.

Just install the given extension, and then you should see code assist contributions from extension in following cases if you invoke code assist at position marked by ’|’  -

 

<cfset foo1(|)> <!— code assist for function foo1() –>
<cfset event.foo2(|1,|)> <!— code assist for function foo2() on variable event –>
<cfset event.|> <!— code assist for event variable member functions, scope variables etc. –>
References
Published at DZone with permission of sandeep , author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)