Modify

Opened 17 months ago

Last modified 4 months 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: 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 months ago.
T13072_strategy_extension_interface.patch (9.6 KB) - added by Peter Suter 7 months ago.
T13072_Use_IWikiSyntaxProvider.diff (6.6 KB) - added by Ryan J Ollos 4 months ago.
T13072_strategy_extension_interface.2.patch (9.6 KB) - added by Ryan J Ollos 4 months ago.
T13072_TagsPlugin_IWikiSyntaxProvider.diff (2.5 KB) - added by Ryan J Ollos 4 months ago.

Download all attachments as: .zip

Change History (20)

comment:1 Changed 17 months ago by Peter Suter

(Another fun example could be the WikiExtrasPlugin.)

comment:2 Changed 17 months ago by Peter Suter

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

comment:3 Changed 17 months ago by Ryan J Ollos

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

Last edited 17 months ago by Ryan J Ollos (previous) (diff)

Changed 7 months ago by Peter Suter

Changed 7 months ago by Peter Suter

comment:4 Changed 7 months 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 months ago by Peter Suter

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

See #13352

comment:6 Changed 5 months ago by Peter Suter

In 17030:

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

comment:7 Changed 4 months 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 4 months ago by Ryan J Ollos

In 17059:

TracTags 0.10dev: Add support for WikiAutoCompletePlugin

Refs #13072.

comment:9 in reply to:  7 ; Changed 4 months 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 4 months 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 4 months ago by Ryan J Ollos (previous) (diff)

comment:11 in reply to:  9 Changed 4 months 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 4 months ago by Ryan J Ollos (previous) (diff)

comment:12 Changed 4 months ago by Ryan J Ollos

In 17068:

TracTags 0.10dev: Suggest completions on OR queries

Patch by Pete Suter.

Refs #13072.

comment:13 Changed 4 months ago by Ryan J Ollos

In 17077:

TracTags 0.10dev: Change required WikiAutoCompletePlugin version

Refs #13072.

Changed 4 months ago by Ryan J Ollos

Changed 4 months ago by Ryan J Ollos

Changed 4 months ago by Ryan J Ollos

comment:14 Changed 4 months 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 4 months ago by Ryan J Ollos (previous) (diff)

comment:15 Changed 4 months 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?)

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.