Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BaseIntellisenseSession.cs « Intellisense « Impl « Language « VSEditor « MonoDevelop.SourceEditor2 « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5b30575658424094f2b8c931e267ae1d5c7869ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Utilities;
using Microsoft.VisualStudio.Utilities;

namespace Microsoft.VisualStudio.Language.Intellisense.Implementation
{
    internal abstract class BaseIntellisenseSession : IIntellisenseSession
    {
        private PropertyCollection properties = new PropertyCollection();
        protected readonly ITextView textView;
        protected IIntellisensePresenter presenter;

        protected BaseIntellisenseSession(ITextView textView)
        {
            if (textView == null)
            {
                throw new ArgumentNullException("textView");
            }

            this.textView = textView;
        }

        public event EventHandler PresenterChanged;
        public event EventHandler Recalculated;
        public event EventHandler Dismissed;

        public ITextView TextView
        {
            get { return this.textView; }
        }

        public PropertyCollection Properties
        {
            get { return this.properties; }
        }

        public IIntellisensePresenter Presenter
        {
            get { return this.presenter; }
        }

        public virtual void Dismiss()
        {
            this.properties = null;
            this.presenter = null;
        }

        public abstract void Start();
        public abstract void Recalculate();
        public abstract bool Match();
        public abstract void Collapse();
        public abstract bool IsDismissed { get; }
        public abstract ITrackingPoint TriggerPoint { get; }

        public virtual ITrackingPoint GetTriggerPoint(ITextBuffer textBuffer)
        {
            var mappedTriggerPoint = GetTriggerPoint(textBuffer.CurrentSnapshot);

            if (!mappedTriggerPoint.HasValue)
            {
                return null;
            }

            return mappedTriggerPoint.Value.Snapshot.CreateTrackingPoint(mappedTriggerPoint.Value, PointTrackingMode.Negative);
        }

        public SnapshotPoint? GetTriggerPoint(ITextSnapshot textSnapshot)
        {
            var triggerSnapshotPoint = this.TriggerPoint.GetPoint(this.textView.TextSnapshot);
            var triggerSpan = new SnapshotSpan(triggerSnapshotPoint, 0);

            var mappedSpans = new FrugalList<SnapshotSpan>();
            MappingHelper.MapDownToBufferNoTrack(triggerSpan, textSnapshot.TextBuffer, mappedSpans);

            if (mappedSpans.Count == 0)
            {
                return null;
            }
            else
            {
                return mappedSpans[0].Start;
            }
        }

        protected IIntellisensePresenter FindPresenter
                                        (IIntellisenseSession session,
                                         IList<Lazy<IIntellisensePresenterProvider, IOrderableContentTypeMetadata>> orderedPresenterProviders,
                                         IGuardedOperations guardedOperations)
        {
            var buffers = Helpers.GetBuffersForTriggerPoint(session);

            foreach (var presenterProviderExport in orderedPresenterProviders)
            {
                foreach (var buffer in buffers)
                {
                    foreach (var contentType in presenterProviderExport.Metadata.ContentTypes)
                    {
                        if (buffer.ContentType.IsOfType(contentType))
                        {
                            IIntellisensePresenter presenter = guardedOperations.InstantiateExtension(
                                session, presenterProviderExport,
                                factory => factory.TryCreateIntellisensePresenter(session));
                            if (presenter != null)
                            {
                                return presenter;
                            }
                        }
                    }
                }
            }

            return null;
        }



        protected void RaisePresenterChanged()
        {
            EventHandler tempHandler = this.PresenterChanged;
            if (tempHandler != null)
            {
                tempHandler(this, EventArgs.Empty);
            }
        }

        protected void RaiseRecalculated()
        {
            EventHandler tempHandler = this.Recalculated;
            if (tempHandler != null)
            {
                tempHandler(this, EventArgs.Empty);
            }
        }

        protected void RaiseDismissed()
        {
            EventHandler tempHandler = this.Dismissed;
            if (tempHandler != null)
            {
                tempHandler(this, EventArgs.Empty);
            }
        }
    }
}