PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms 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
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  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. }