[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [Dltk-dev] Code completion fails to work with no prefix
|
That would make all calls to
createContext(ITextViewer viewer,
IRegion region)prefix dependent. Not sure that is a good
thing, and it would likely be an unexpected behavior.
This seems to work well:
protected
boolean
isValid(ITextViewer viewer,
Region region, String prefix) {
if
(prefix ==
null
)
return
false
;
if
(prefix.length() == 0) {
TemplateContextType contextType = getContextType(viewer, region);
String cId =
contextType.getId();
if
(MyTemplateContextType.
OPTIONS_CONTEXT_TYPE_ID
.equals(cId)) {
return
true
;
}
return
false
;
}
return
true
;
}
and changing
ScriptTemplateCompletionProcessor#computeCompletionProposals to:
...
String prefix =
extractPrefix(viewer, offset);
Region
region =
new
Region(offset - prefix.length(),
prefix.length());
if
(!isValid(viewer, region, prefix))
{
return
new
ICompletionProposal[0];
}
TemplateContext context = createContext(viewer, region);
if
(context ==
null
)
return
new
ICompletionProposal[0];
...
Don't think that it has a performance penalty.
Thanks,
Gerald
At 09:32 PM 8/26/2008, Alex Panchenko wrote:
createContext() could be costly
operation (if it performs source parsing), so separate prefix check
allows to avoid it.
If you want to check prefix based on the context you can acquire prefix
with the following code:
viewer.getDocument().get(region.getOffset(), region.getLength())
inside your implementation of the createContext() method
Regards,
Alex