Setting optional parameter (Tag request)

SyntaxEditor for WPF Forum

Posted 14 years ago by Mick George - Senior Software Engineer, CNC Software, LLC
Version: 10.1.0523
Avatar
I have an adornment that works great, however, my question is, how do I assign a value to the object parameter in GetTags?

 public class SyncTag : ITag 
    {
    }

public class SyncTagger : TaggerBase<SyncTag>
    {
        public SyncTagger(ICodeDocument document) :
            base("SyncTagger", null, document, true)
        {
        }


public override IEnumerable<TagSnapshotRange<SyncTag>> GetTags(NormalizedTextSnapshotRangeCollection snapshotRanges, object parameter)
{
if (snapshotRanges != null)
            {
                // Loop through the snapshot ranges
                foreach (TextSnapshotRange snapshotRange in snapshotRanges)
                {
                    
                    // Get the text of the snapshot range
                    string text = snapshotRange.Text;

                    //TODO: use object parameter
                    if (text.StartsWith("P"))
                    {

                       // Create a tag
                        SyncTag tag = new SyncTag();

                        // Yield the tag
                        yield return new TagSnapshotRange<SyncTag>(
                            TextSnapshotRange.FromSpan(snapshotRange.Snapshot, snapshotRange.StartOffset, 250), tag);
                    }
                }
            }

}
[Modified at 09/16/2010 09:29 AM]

Comments (6)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Mick,

Taggers provide data back when requested. The requesters of this data are always tag aggregators. The ITagAggregator interface defines two overloads for its GetTags method. One of the overloads accepts an object parameter which in turn gets passed along to all the taggers that are examined.


Actipro Software Support

Posted 14 years ago by Mick George - Senior Software Engineer, CNC Software, LLC
Avatar
Hi,

Thanks for the quick response but I am still a little lost. How do I assign a value to the object parameter passed to GetTags? I have been looking through your help file and various examples for some insight but I am not seeing anything obvious.

If you look at your QuickStart AdornmentsHighlightWord WordHighlightTagger.cs example you can see that the object parameter is not null when called but I can not fathom how the parameter value was set? Do you have or can point me to an example that makes this a little clearer?

Thanks
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Mick,

I'm not sure if we have any samples on tag aggregators but the documentation topic "Tag Aggregators" talks about them. The taggers are generally called by our internal tag aggregators, therefore in most of the cases you wouldn't be able to specify a custom parameter to GetTags since its us calling it. If you are trying to do some custom lookup of tags from a tagger of your own creation, then you'd want to use a tag aggregator and could pass the parameter as needed.


Actipro Software Support

Posted 14 years ago by Mick George - Senior Software Engineer, CNC Software, LLC
Avatar
Thanks for the response.

I cannot assign a value to the object parameter passed to GetTags, I understand that now so how else can I get data into my SyncTagger class? I went so far as assigning values to document properties in hopes that I could then retrieve those values in my SyncTagger constructor via the ICodeDocument properties argument but they are always null.

What I am ultimately trying to accomplish is evaluate the text in the GetTags override with a string array I have that is created when a new document is created, I just need to get this array into GetTags.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

The optimal solution depends on where you are using these tags.

If you are consuming them yourself, you could create a tag aggregator to consume the tags, then use the aggregator overload that takes a parameter.

If it is our built in stuff that will be consuming the tags, you would need to acquire a reference to the tagger instance and set a property on it. When creating a new CodeDocumentTaggerProvider to register as a language service, there is a constructor overload that provides the option of specifying a singleton key which would be the type of tagger. If this value is specified, you could retrieve the tagger instance from document.Properties dictionary via the typeof(SyncTagger) key.

Please let us know if you have further questions.


Actipro Software Support

Posted 14 years ago by Mick George - Senior Software Engineer, CNC Software, LLC
Avatar
Everything is working fine now; I inadvertently set values to the documents properties dictionary after my synctagger constructor was called. Thanks again for your assistance, it certainly helped.
The latest build of this product (v24.1.3) was released 29 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.