Forum Visual Studio

Stuck trying to write an extension using ITextSearchService

arkonarkon AUMember ✭✭

Hi All, I need a Xamarin expert please. I'm writing an extension that needs to use the ITextSearchService but I can't for the life of me figure out how to import it. The VS not for mac version has a [Import] before it but that doesn't work on the mac version. Here is my code so far:-

using System;
using System.Collections.Generic;
using MonoDevelop.Components.Commands;
using MonoDevelop.Ide;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Text.Operations;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;

namespace QTools
{
class FixLineEndsHandler : CommandHandler
{
[Import] <----This doesn't work!!
internal ITextSearchService TextSearchService { get; set; }

    protected override void Run()
    {
        var textBuffer = IdeApp.Workbench.ActiveDocument.GetContent<ITextBuffer>();
        var textView = IdeApp.Workbench.ActiveDocument.GetContent<ITextView>();
        var caretPosition = textView.Caret.Position;
        var SnapShot = textBuffer.CurrentSnapshot;

        List<SnapshotSpan> wordSpans = new List<SnapshotSpan>();

        FindData findData = new FindData("using", SnapShot);
        findData.FindOptions = FindOptions.WholeWord | FindOptions.MatchCase;


        wordSpans.AddRange(TextSearchService.FindAll(findData));

        int length = wordSpans.Count;
        int xlength = wordSpans.Count;

        //textBuffer.Replace(new Span(0,100), "doodledoo");

        //textBuffer.Insert(caretPosition.BufferPosition.Position, "doodledoo");
    }

    protected override void Update(CommandInfo info)
    {
        var textBuffer = IdeApp.Workbench.ActiveDocument.GetContent<ITextBuffer>();
        if (textBuffer != null && textBuffer.AsTextContainer() is SourceTextContainer container)
        {
            var document = container.GetTextBuffer();
            if (document != null)
            {
                info.Enabled = true;
            }
        }
    }
}

}

Sign In or Register to comment.