/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. using System.Text;
  15. using Microsoft.Scripting;
  16. using Microsoft.Scripting.Hosting;
  17. using Microsoft.Scripting.Hosting.Providers;
  18. using Microsoft.VisualStudio.Text;
  19. namespace Microsoft.IronStudio.Core {
  20. internal class SnapshotMultipleSpanTextContentProvider : TextContentProvider, ISnapshotTextContentProvider {
  21. private readonly NormalizedSnapshotSpanCollection _spans;
  22. internal SnapshotMultipleSpanTextContentProvider(NormalizedSnapshotSpanCollection spans) {
  23. _spans = spans;
  24. }
  25. internal static SourceUnit Make(ScriptEngine engine, NormalizedSnapshotSpanCollection spans) {
  26. return Make(engine, spans, "None");
  27. }
  28. internal static SourceUnit Make(ScriptEngine engine, NormalizedSnapshotSpanCollection spans, string path) {
  29. var textContent = new SnapshotMultipleSpanTextContentProvider(spans);
  30. var languageContext = HostingHelpers.GetLanguageContext(engine);
  31. return new SourceUnit(languageContext, textContent, path, SourceCodeKind.File);
  32. }
  33. #region TextContentProvider
  34. public override SourceCodeReader GetReader() {
  35. return new SourceCodeReader(new SnapshotMultipleSpanSourceCodeReader(_spans), Encoding.Default);
  36. }
  37. #endregion
  38. #region ISnapshotTextContentProvider
  39. public ITextSnapshot Snapshot {
  40. get {
  41. if (_spans.Count > 0) {
  42. return _spans[0].Snapshot;
  43. }
  44. return null;
  45. }
  46. }
  47. #endregion
  48. }
  49. }