Opened 8 years ago
Last modified 4 years ago
#13072 new enhancement
Extension point interface so other plugins can provide completions
Reported by: | Peter Suter | Owned by: | Peter Suter |
---|---|---|---|
Priority: | normal | Component: | WikiAutoCompletePlugin |
Severity: | normal | Keywords: | |
Cc: | Jun Omae | Trac Release: |
Description
I would like to allow other plugins to provide additional completions for their own realms, macros, etc.
For example MailArchivePlugin should be able to provide completions for mailarchive:
links.
Attachments (5)
Change History (25)
comment:1 Changed 8 years ago by
comment:3 Changed 8 years ago by
Another use-case is TagsPlugin auto-completing tag names for TracLinks ([tag:
).
Changed 7 years ago by
Attachment: | T13072_refactor_strategies.patch added |
---|
Changed 7 years ago by
Attachment: | T13072_strategy_extension_interface.patch added |
---|
comment:4 Changed 7 years ago by
- Refactor existing code. Move list of strategies from Javascript to Python. Try to make everything more uniform, so we can reuse the same Javascript for all strategies.
- Add extension point interface.
Maybe there's a simpler / better / nicer / more flexible / more performant approach?
comment:5 Changed 7 years ago by
For example MailArchivePlugin should be able to provide completions for
mailarchive:
links.
See #13352
comment:7 follow-up: 9 Changed 7 years ago by
Interface looks good. Maybe the interface name could be shortened to IWikiAutoCompleteProvider
.
I haven't tried, so maybe this doesn't make sense, but I wonder if it would be more flexible to have replace
and template
regexes rather than replace_prefix
, replace_suffix
, ...
For TagsPlugin, I looked at supporting the "or" queries, like tag:"plugin macro"
(TagsPlugin#tag:tagortagged:query). I'm not sure if that can or should be done.
comment:9 follow-ups: 10 11 Changed 7 years ago by
Interface looks good. Maybe the interface name could be shortened to
IWikiAutoCompleteProvider
.
Thanks for reviewing. Sounds reasonable. Would you also shorten get_wiki_auto_complete_strategies
, and to what?
I haven't tried, so maybe this doesn't make sense, but I wonder if it would be more flexible to have
replace
andtemplate
regexes rather thanreplace_prefix
,replace_suffix
, ...
Yes, I wondered exactly the same thing, but suspected it would get a bit confusing. If you can find a nice and clear way to do it, I'd be interested.
For TagsPlugin, I looked at supporting the "or" queries, like
tag:"plugin macro"
(TagsPlugin#tag:tagortagged:query). I'm not sure if that can or should be done.
Maybe something like this would work?
{ 'match': ( r'\b(tag:|tagged:)' # tag: or tagged: query r'("(?:\S* )*)?' # Optional: Quotes allow multiple OR-tags r'(\S*)$' # tag-prefix to complete ), 'index': 3, 'replace_prefix': '$1$2', # ... }
comment:10 Changed 7 years ago by
Replying to Peter Suter:
Interface looks good. Maybe the interface name could be shortened to
IWikiAutoCompleteProvider
.Thanks for reviewing. Sounds reasonable. Would you also shorten
get_wiki_auto_complete_strategies
, and to what?
That one seems okay to me. I would say to use get_strategies
, but it's not specific enough to ensure it wouldn't collide with some other interface implemented on the same Component.
comment:11 Changed 7 years ago by
Replying to Peter Suter:
Maybe something like this would work?
{ 'match': ( r'\b(tag:|tagged:)' # tag: or tagged: query r'("(?:\S* )*)?' # Optional: Quotes allow multiple OR-tags r'(\S*)$' # tag-prefix to complete ), 'index': 3, 'replace_prefix': '$1$2', # ... }
Works well. Thanks!
Changed 7 years ago by
Attachment: | T13072_Use_IWikiSyntaxProvider.diff added |
---|
Changed 7 years ago by
Attachment: | T13072_strategy_extension_interface.2.patch added |
---|
Changed 7 years ago by
Attachment: | T13072_TagsPlugin_IWikiSyntaxProvider.diff added |
---|
comment:14 Changed 7 years ago by
Considering comment:8:ticket:13071, I changed the implementation to use IWikiSyntaxProvider
. The changes assume the method get_wiki_auto_complete_strategies
, even though it's not defined on the IWikiSyntaxProvider
Interface
.
comment:15 Changed 7 years ago by
The patches look good to me. (Assuming the method will get added to the interface in an upcoming version of Trac.)
I guess we could just start with this. The proposed changes to the interface:
- The
replace
andtemplate
regexes idea from comment:7 - The
strategy, handler, priority
idea from comment:8:ticket:13071
They could probably be added later in a backward-compatible way. (But if you want to try implementing these soon, it might be better to not commit the patches yet, so we don't need any backward-compatibility considerations at all.)
(In comment:2:ticket:13071 I also mentioned IWikiMacroProvider
as a possible interface to extend for completions. This is also not urgent I think. The idea was to make macros more user-friendly. They could just provide a description more suited to this use-case, e.g. only listing parameters. Even better would be a context-sensitive per-macro-parameter help and suggestions for auto-completed parameter names and values. I'm not completely sure how to implement this though, and again I guess it can be done later in a backward compatible way. What do you think?)
comment:17 Changed 4 years ago by
Cc: | Jun Omae added |
---|
comment:18 Changed 4 years ago by
I noticed cache
option doesn't work while trying the patches in comment:14. It seems the issue is introduced in r17030.
-
wikiautocompleteplugin/wikiautocomplete/htdocs/js/wikiautocomplete.js
a b jQuery(document).ready(function($) { 35 35 }; 36 36 $.getJSON(wikiautocomplete.url + '/' + strategy.name, data) 37 37 .done(function(resp) { 38 cache[strategy ] = resp;38 cache[strategy.name] = resp; 39 39 invoke_callback(resp); 40 40 }) 41 41 .fail(function() { callback([]) });
comment:19 Changed 4 years ago by
I noticed jquery.textcomplete.js
has an issue in strategies loop while trying the patches in comment:14 with custom strategy from plugin.
Original text
is wrongly dropped if context
function returns normalized text. As the result, the completion for processor will no longer work because custom strategy is added as first entry to strategies.
-
jquery.textcomplete.js
old new 303 303 _extractSearchQuery: function (text) { 304 304 for (var i = 0; i < this.strategies.length; i++) { 305 305 var strategy = this.strategies[i]; 306 306 var context = strategy.context(text); 307 307 if (context || context === '') { 308 308 var matchRegexp = $.isFunction(strategy.match) ? strategy.match(text) : strategy.match; 309 if (isString(context)) { text = context; }310 var match = text.match(matchRegexp);309 var normText = isString(context) ? context : text; 310 var match = normText.match(matchRegexp); 311 311 if (match) { return [strategy, match[strategy.index], match]; } 312 312 } 313 313 } 314 314 return [] 315 315 }, 316 316
However, jquery.textcomplete.js
is no longer maintained. See https://github.com/yuku/textcomplete/blob/jquery-v1.8.5/README.md.
(Another fun example could be the WikiExtrasPlugin.)