Permalink
Browse files

Fixed up all but one unit test

  • Loading branch information...
1 parent b482c10 commit 140ff28d07137ee9d1be6001efc1d8f17f9060b3 @jaredpar committed Dec 7, 2011
View
@@ -0,0 +1,26 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EditorUtils", "EditorUtils\EditorUtils.csproj", "{FB418222-C105-4942-8EEB-832DDCFFD89D}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EditorUtilsTest", "EditorUtilsTest\EditorUtilsTest.csproj", "{BAED09B7-25D9-4DD8-8558-BAC9730BA3F3}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {FB418222-C105-4942-8EEB-832DDCFFD89D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FB418222-C105-4942-8EEB-832DDCFFD89D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FB418222-C105-4942-8EEB-832DDCFFD89D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FB418222-C105-4942-8EEB-832DDCFFD89D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {BAED09B7-25D9-4DD8-8558-BAC9730BA3F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {BAED09B7-25D9-4DD8-8558-BAC9730BA3F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {BAED09B7-25D9-4DD8-8558-BAC9730BA3F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {BAED09B7-25D9-4DD8-8558-BAC9730BA3F3}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -59,8 +59,10 @@
<ItemGroup>
<Compile Include="Contract.cs" />
<Compile Include="Extensions.cs" />
+ <Compile Include="IAdhocOutliner.cs" />
<Compile Include="IAsyncTaggerSource.cs" />
<Compile Include="IBasicTaggerSource.cs" />
+ <Compile Include="Implementation\Outlining\AdhocOutliner.cs" />
<Compile Include="Implementation\Tagging\AsyncTagger.cs" />
<Compile Include="Implementation\Tagging\BasicTagger.cs" />
<Compile Include="Implementation\Tagging\CountedTagger.cs" />
@@ -2,17 +2,14 @@
using System.Collections.Generic;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Tagging;
+using System.Collections.ObjectModel;
-namespace Vim.UnitTest
+namespace EditorUtils
{
/// <summary>
/// Allows callers to create outlining regions over arbitrary SnapshotSpan values
- ///
- /// The Visual Studio editor provides the ability to create outlining regions over arbitrary
- /// SnapshotSpan values while Vim only provides for line based regions. This class is useful
- /// for simulating Visual Studio's abilities as VsVim still needs to interact with them
/// </summary>
- public interface IAdhocOutliner : ITagger<OutliningRegionTag>
+ public interface IAdhocOutliner
{
/// <summary>
/// Get the ITextBuffer associated with this instance
@@ -22,7 +19,7 @@ public interface IAdhocOutliner : ITagger<OutliningRegionTag>
/// <summary>
/// Get all of the regions in the given ITextSnapshot
/// </summary>
- IEnumerable<ITagSpan<OutliningRegionTag>> GetRegions(ITextSnapshot snapshot);
+ ReadOnlyCollection<ITagSpan<OutliningRegionTag>> GetRegions(SnapshotSpan span);
/// <summary>
/// Create an outlining region over the given SnapshotSpan. The int value returned is
@@ -36,13 +33,14 @@ public interface IAdhocOutliner : ITagger<OutliningRegionTag>
bool DeleteOutliningRegion(int cookie);
/// <summary>
- /// Raised when any regions change in the ITextBuffer
+ /// Raised when any outlining regions change
/// </summary>
- event EventHandler<SnapshotSpanEventArgs> Changed;
+ event EventHandler Changed;
}
/// <summary>
- /// Factory for acquiring instances of the IAdhocOutliner
+ /// Factory for acquiring instances of the IAdhocOutliner. This type is available as a MEF
+ /// service
/// </summary>
public interface IAdhocOutlinerFactory
{
@@ -0,0 +1,206 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel.Composition;
+using Microsoft.VisualStudio.Text;
+using Microsoft.VisualStudio.Text.Editor;
+using Microsoft.VisualStudio.Text.Tagging;
+using Microsoft.VisualStudio.Utilities;
+
+namespace EditorUtils.Implementation.Outlining
+{
+ /// <summary>
+ /// Implementation of the IAdhocOutliner service. This class is only used for testing
+ /// so it's focused on creating the simplest implementation vs. the most efficient
+ /// </summary>
+ internal sealed class AdhocOutliner : IAdhocOutliner, IBasicTaggerSource<OutliningRegionTag>
+ {
+ struct OutliningData
+ {
+ internal readonly ITrackingSpan TrackingSpan;
+ internal readonly string Text;
+ internal readonly string Hint;
+
+ internal OutliningData(
+ ITrackingSpan trackingSpan,
+ string text,
+ string hint)
+ {
+ TrackingSpan = trackingSpan;
+ Text = text;
+ Hint = hint;
+ }
+ }
+
+ private static readonly ReadOnlyCollection<ITagSpan<OutliningRegionTag>> s_emptyCollection = new ReadOnlyCollection<ITagSpan<OutliningRegionTag>>(new List<ITagSpan<OutliningRegionTag>>());
+ private Dictionary<int, OutliningData> _optionalMap;
+ private readonly ITextBuffer _textBuffer;
+ private int m_counter;
+ private event EventHandler _changed;
+
+ internal AdhocOutliner(ITextBuffer textBuffer)
+ {
+ _textBuffer = textBuffer;
+ }
+
+ private void EnsureMapCreated()
+ {
+ if (_optionalMap == null)
+ {
+ _optionalMap = new Dictionary<int, OutliningData>();
+ }
+ }
+
+ /// <summary>
+ /// Get all of the values which map to the given ITextSnapshot
+ /// </summary>
+ private ReadOnlyCollection<ITagSpan<OutliningRegionTag>> GetRegions(SnapshotSpan span)
+ {
+ // Avoid allocating a map or new collection if we are simply empty
+ if (_optionalMap == null || _optionalMap.Count == 0)
+ {
+ return s_emptyCollection;
+ }
+
+ var snapshot = span.Snapshot;
+ var list = new List<ITagSpan<OutliningRegionTag>>();
+ foreach (var cur in _optionalMap.Values)
+ {
+ var currentSpan = cur.TrackingSpan.GetSpanSafe(snapshot);
+ if (currentSpan.HasValue && currentSpan.Value.IntersectsWith(span))
+ {
+ var tag = new OutliningRegionTag(cur.Text, cur.Hint);
+ list.Add(new TagSpan<OutliningRegionTag>(currentSpan.Value, tag));
+ }
+ }
+
+ return list.ToReadOnlyCollectionShallow();
+ }
+
+ private int CreateOutliningRegion(SnapshotSpan span, string text, string hint)
+ {
+ EnsureMapCreated();
+
+ var snapshot = span.Snapshot;
+ var trackingSpan = snapshot.CreateTrackingSpan(span.Span, SpanTrackingMode.EdgeInclusive);
+ var data = new OutliningData(trackingSpan, text: text, hint: hint);
+ m_counter++;
+ _optionalMap[m_counter] = data;
+ RaiseChanged();
+ return m_counter;
+ }
+
+ /// <summary>
+ /// Notify that our tags have changed. Not going to get too fancy here since it's just for
+ /// test code. Just raise the event for the entire ITextSnapshot
+ /// </summary>
+ private void RaiseChanged()
+ {
+ var handler = _changed;
+ if (handler != null)
+ {
+ handler(this, EventArgs.Empty);
+ }
+ }
+
+ #region IAdhocOutliner
+
+ ITextBuffer IAdhocOutliner.TextBuffer
+ {
+ get { return _textBuffer; }
+ }
+
+ ReadOnlyCollection<ITagSpan<OutliningRegionTag>> IAdhocOutliner.GetRegions(SnapshotSpan span)
+ {
+ return GetRegions(span);
+ }
+
+ int IAdhocOutliner.CreateOutliningRegion(SnapshotSpan span, string text, string hint)
+ {
+ return CreateOutliningRegion(span, text, hint);
+ }
+
+ bool IAdhocOutliner.DeleteOutliningRegion(int cookie)
+ {
+ if (_optionalMap == null)
+ {
+ return false;
+ }
+
+ var success = _optionalMap.Remove(cookie);
+ if (success)
+ {
+ RaiseChanged();
+ }
+ return success;
+ }
+
+ event EventHandler IAdhocOutliner.Changed
+ {
+ add { _changed += value; }
+ remove { _changed -= value; }
+ }
+
+ #endregion
+
+ #region IBasicTagger<OutliningRegionTag>
+
+ ITextSnapshot IBasicTaggerSource<OutliningRegionTag>.TextSnapshot
+ {
+ get { return _textBuffer.CurrentSnapshot; }
+ }
+
+ ReadOnlyCollection<ITagSpan<OutliningRegionTag>> IBasicTaggerSource<OutliningRegionTag>.GetTags(SnapshotSpan span)
+ {
+ return GetRegions(span);
+ }
+
+ event EventHandler IBasicTaggerSource<OutliningRegionTag>.Changed
+ {
+ add { _changed += value; }
+ remove { _changed -= value; }
+ }
+
+ #endregion
+ }
+
+ /// <summary>
+ /// Responsible for managing instances of IAdhocOutliner for a given ITextBuffer
+ /// </summary>
+ [Export(typeof(IAdhocOutlinerFactory))]
+ [Export(typeof(ITaggerProvider))]
+ [ContentType("any")]
+ [TextViewRole(PredefinedTextViewRoles.Structured)]
+ [TagType(typeof(OutliningRegionTag))]
+ internal sealed class AdhocOutlinerFactory : IAdhocOutlinerFactory, ITaggerProvider
+ {
+ private readonly object _adhocOutlinerKey = new object();
+ private readonly object _taggerKey = new object();
+ private readonly ITaggerFactory _taggerFactory;
+
+ [ImportingConstructor]
+ internal AdhocOutlinerFactory(ITaggerFactory taggerFactory)
+ {
+ _taggerFactory = taggerFactory;
+ }
+
+ private AdhocOutliner GetOrCreateOutliner(ITextBuffer textBuffer)
+ {
+ return textBuffer.Properties.GetOrCreateSingletonProperty(_adhocOutlinerKey, () => new AdhocOutliner(textBuffer));
+ }
+
+ IAdhocOutliner IAdhocOutlinerFactory.GetAdhocOutliner(ITextBuffer textBuffer)
+ {
+ return GetOrCreateOutliner(textBuffer);
+ }
+
+ ITagger<T> ITaggerProvider.CreateTagger<T>(ITextBuffer buffer)
+ {
+ var tagger = _taggerFactory.CreateBasicTaggerCounted(
+ _taggerKey,
+ buffer.Properties,
+ () => GetOrCreateOutliner(buffer));
+ return (ITagger<T>)(object)tagger;
+ }
+ }
+}
@@ -23,7 +23,7 @@ internal sealed class TaggerFactory : ITaggerFactory
ITagger<TTag> ITaggerFactory.CreateBasicTagger<TTag>(IBasicTaggerSource<TTag> basicTaggerSource)
{
- throw new NotImplementedException();
+ return new BasicTagger<TTag>(basicTaggerSource);
}
ITagger<TTag> ITaggerFactory.CreateBasicTaggerCounted<TTag>(object key, PropertyCollection propertyCollection, Func<IBasicTaggerSource<TTag>> createFunc)
@@ -1,72 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>8.0.30703</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{FB418222-C105-4942-8EEB-832DDCFFD89D}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>Vim</RootNamespace>
- <AssemblyName>Vim.Interfaces</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="Microsoft.VisualStudio.CoreUtility, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\References\Microsoft.VisualStudio.CoreUtility.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.VisualStudio.Text.Data, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\References\Microsoft.VisualStudio.Text.Data.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.VisualStudio.Text.Internal, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\References\Microsoft.VisualStudio.Text.Internal.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.VisualStudio.Text.Logic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\References\Microsoft.VisualStudio.Text.Logic.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.VisualStudio.Text.UI, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\References\Microsoft.VisualStudio.Text.UI.dll</HintPath>
- </Reference>
- <Reference Include="System" />
- <Reference Include="System.Core" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="LineRange.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Resources.cs" />
- <Compile Include="SnapshotLineRange.cs" />
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
Oops, something went wrong.

0 comments on commit 140ff28

Please sign in to comment.