Modify

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)

T13072_refactor_strategies.patch (21.4 KB) - added by Peter Suter 7 years ago.
T13072_strategy_extension_interface.patch (9.6 KB) - added by Peter Suter 7 years ago.
T13072_Use_IWikiSyntaxProvider.diff (6.6 KB) - added by Ryan J Ollos 7 years ago.
T13072_strategy_extension_interface.2.patch (9.6 KB) - added by Ryan J Ollos 7 years ago.
T13072_TagsPlugin_IWikiSyntaxProvider.diff (2.5 KB) - added by Ryan J Ollos 7 years ago.

Download all attachments as: .zip

Change History (25)

comment:1 Changed 8 years ago by Peter Suter

(Another fun example could be the WikiExtrasPlugin.)

comment:2 Changed 8 years ago by Peter Suter

(Also: @username mentions, see t:#11871)

comment:3 Changed 8 years ago by Ryan J Ollos

Another use-case is TagsPlugin auto-completing tag names for TracLinks ([tag:).

Last edited 8 years ago by Ryan J Ollos (previous) (diff)

Changed 7 years ago by Peter Suter

Changed 7 years ago by Peter Suter

comment:4 Changed 7 years ago by Peter Suter

  1. 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.
  2. Add extension point interface.

Maybe there's a simpler / better / nicer / more flexible / more performant approach?

comment:5 in reply to:  description Changed 7 years ago by Peter Suter

For example MailArchivePlugin should be able to provide completions for mailarchive: links.

See #13352

comment:6 Changed 7 years ago by Peter Suter

In 17030:

WikiAutoCompletePlugin: Move list of strategies to Python.
Prepare for extension point interface.
(see #13072)

comment:7 Changed 7 years ago by Ryan J Ollos

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:8 Changed 7 years ago by Ryan J Ollos

In 17059:

TracTags 0.10dev: Add support for WikiAutoCompletePlugin

Refs #13072.

comment:9 in reply to:  7 ; Changed 7 years ago by 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?

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, ...

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 in reply to:  9 Changed 7 years ago by Ryan J Ollos

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.

Last edited 7 years ago by Ryan J Ollos (previous) (diff)

comment:11 in reply to:  9 Changed 7 years ago by Ryan J Ollos

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!

Last edited 7 years ago by Ryan J Ollos (previous) (diff)

comment:12 Changed 7 years ago by Ryan J Ollos

In 17068:

TracTags 0.10dev: Suggest completions on OR queries

Patch by Pete Suter.

Refs #13072.

comment:13 Changed 7 years ago by Ryan J Ollos

In 17077:

TracTags 0.10dev: Change required WikiAutoCompletePlugin version

Refs #13072.

Changed 7 years ago by Ryan J Ollos

Changed 7 years ago by Ryan J Ollos

Changed 7 years ago by Ryan J Ollos

comment:14 Changed 7 years ago by Ryan J Ollos

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.

Last edited 7 years ago by Ryan J Ollos (previous) (diff)

comment:15 Changed 7 years ago by Peter Suter

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:

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:16 Changed 5 years ago by Ryan J Ollos

#13665 closed as a duplicate. Need to revisit this eventually.

comment:17 Changed 4 years ago by Jun Omae

Cc: Jun Omae added

comment:18 Changed 4 years ago by Jun Omae

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($) { 
    3535                };
    3636                $.getJSON(wikiautocomplete.url + '/' + strategy.name, data)
    3737                    .done(function(resp) {
    38                         cache[strategy] = resp;
     38                        cache[strategy.name] = resp;
    3939                        invoke_callback(resp);
    4040                    })
    4141                    .fail(function() { callback([]) });

comment:19 Changed 4 years ago by Jun Omae

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  
    303303    _extractSearchQuery: function (text) {
    304304      for (var i = 0; i < this.strategies.length; i++) {
    305305        var strategy = this.strategies[i];
    306306        var context = strategy.context(text);
    307307        if (context || context === '') {
    308308          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);
    311311          if (match) { return [strategy, match[strategy.index], match]; }
    312312        }
    313313      }
    314314      return []
    315315    },
    316316

However, jquery.textcomplete.js is no longer maintained. See https://github.com/yuku/textcomplete/blob/jquery-v1.8.5/README.md.

comment:20 Changed 4 years ago by Jun Omae

In 17990:

WikiAutoCompletePlugin: follow-up to r17030, fix cache option not working (refs #13072)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain Peter Suter.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.