PageRenderTime 18ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/IronPython_Main/Tools/IronStudio/IronStudioCore/IronStudioCore/SnapshotMultipleSpanTextContentProvider.cs

#
C# | 60 lines | 36 code | 11 blank | 13 comment | 1 complexity | c5c08dc22ba261929b3e186f8f94589c MD5 | raw file
 1/* ****************************************************************************
 2 *
 3 * Copyright (c) Microsoft Corporation. 
 4 *
 5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
 6 * copy of the license can be found in the License.html file at the root of this distribution. If 
 7 * you cannot locate the Apache License, Version 2.0, please send an email to 
 8 * ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 9 * by the terms of the Apache License, Version 2.0.
10 *
11 * You must not remove this notice, or any other, from this software.
12 *
13 * ***************************************************************************/
14
15using System.Text;
16using Microsoft.Scripting;
17using Microsoft.Scripting.Hosting;
18using Microsoft.Scripting.Hosting.Providers;
19using Microsoft.VisualStudio.Text;
20
21namespace Microsoft.IronStudio.Core {
22    internal class SnapshotMultipleSpanTextContentProvider : TextContentProvider, ISnapshotTextContentProvider {
23        private readonly NormalizedSnapshotSpanCollection _spans;
24
25        internal SnapshotMultipleSpanTextContentProvider(NormalizedSnapshotSpanCollection spans) {
26            _spans = spans;
27        }
28
29        internal static SourceUnit Make(ScriptEngine engine, NormalizedSnapshotSpanCollection spans) {
30            return Make(engine, spans, "None");
31        }
32
33        internal static SourceUnit Make(ScriptEngine engine, NormalizedSnapshotSpanCollection spans, string path) {
34            var textContent = new SnapshotMultipleSpanTextContentProvider(spans);
35            var languageContext = HostingHelpers.GetLanguageContext(engine);
36            return new SourceUnit(languageContext, textContent, path, SourceCodeKind.File);
37        }
38
39        #region TextContentProvider
40
41        public override SourceCodeReader GetReader() {
42            return new SourceCodeReader(new SnapshotMultipleSpanSourceCodeReader(_spans), Encoding.Default);
43        }
44
45        #endregion
46
47        #region ISnapshotTextContentProvider
48
49        public ITextSnapshot Snapshot {
50            get {
51                if (_spans.Count > 0) {
52                    return _spans[0].Snapshot;
53                }
54                return null;
55            }
56        }
57
58        #endregion
59    }
60}