Skip to content

Commit

Permalink
Cleanup and simplification
Browse files Browse the repository at this point in the history
[release]
  • Loading branch information
madskristensen committed Dec 23, 2021
1 parent ef778d2 commit 10033bf
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.ComponentModel.Composition;
using BaseClasses;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion;
using Microsoft.VisualStudio.Text.BraceCompletion;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Utilities;
Expand Down Expand Up @@ -29,4 +30,20 @@ internal sealed class BraceMatchingTaggerProvider : BraceMatchingBase
// This will match parenthesis, curly brackets, and square brackets by default.
// Override the BraceList property to modify the list of braces to match.
}

[Export(typeof(IAsyncCompletionCommitManagerProvider))]
[ContentType(Constants.LanguageName)]
[Name(Constants.LanguageName)]
internal sealed class CompletionCommitManager : CompletionCommitManagerBase
{
public override IEnumerable<char> CommitChars => new char[] { ' ', '\'', '"', ',', '.', ';', ':' };
}

[Export(typeof(IViewTaggerProvider))]
[ContentType(Constants.LanguageName)]
[TagType(typeof(TextMarkerTag))]
public class SameWordHighlighter : SameWordHighlighterBase
{
// This is a default implementation of same word highlighting
}
}
2 changes: 1 addition & 1 deletion src/Language/ClassificationTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag
}
}

internal class ClassificationTagger : LexTaggerConsumerBase<IClassificationTag, LexTag>
internal class ClassificationTagger : LexTaggerConsumerBase<IClassificationTag>
{
private static Dictionary<ItemType, ClassificationTag> _map;

Expand Down
1 change: 0 additions & 1 deletion src/Language/ErrorListManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ private IEnumerable<ErrorListItem> CreateErrorListItem(ParseItem item)
protected override void Closed(IWpfTextView textView)
{
_document.Processed -= ParseErrors;
_document.Dispose();
_dataSource.CleanAllErrors();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Language/ErrorTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag
}
}

public class ErrorTagger : LexTaggerConsumerBase<IErrorTag, LexTag>
public class ErrorTagger : LexTaggerConsumerBase<IErrorTag>
{
public ErrorTagger(ITagAggregator<LexTag> lexTags) : base(lexTags)
{ }
Expand Down
3 changes: 2 additions & 1 deletion src/Language/LexTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void ReParse(object sender = null, EventArgs e = null)
SnapshotSpan span = new(_buffer.CurrentSnapshot, 0, _buffer.CurrentSnapshot.Length);
TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(span));

}, VsTaskRunContext.UIThreadBackgroundPriority);
}, VsTaskRunContext.UIThreadIdlePriority);
}

private void AddTagToList(Dictionary<ParseItem, ITagSpan<LexTag>> list, ParseItem item)
Expand All @@ -79,6 +79,7 @@ public void Dispose()
if (!_isDisposed)
{
_document.Processed -= ReParse;
_document.Dispose();
}

_isDisposed = true;
Expand Down
10 changes: 5 additions & 5 deletions src/Language/LexTaggerConsumerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

namespace PkgdefLanguage
{
public abstract class LexTaggerConsumerBase<TTag, TLexTag> : ITagger<TTag>, IDisposable where TTag : ITag where TLexTag : ITag
public abstract class LexTaggerConsumerBase<TTag> : ITagger<TTag>, IDisposable where TTag : ITag
{
private readonly ITagAggregator<TLexTag> _lexTags;
private readonly ITagAggregator<LexTag> _lexTags;
private bool _isDisposed;

public LexTaggerConsumerBase(ITagAggregator<TLexTag> lexTags)
public LexTaggerConsumerBase(ITagAggregator<LexTag> lexTags)
{
_lexTags = lexTags;
_lexTags.TagsChanged += LexTagsChanged;
Expand All @@ -28,15 +28,15 @@ public IEnumerable<ITagSpan<TTag>> GetTags(NormalizedSnapshotSpanCollection span
{
List<ITagSpan<TTag>> list = new();

foreach (IMappingTagSpan<TLexTag> tagSpan in _lexTags.GetTags(spans))
foreach (IMappingTagSpan<LexTag> tagSpan in _lexTags.GetTags(spans))
{
list.AddRange(GetTags(tagSpan));
}

return list;
}

public abstract IEnumerable<ITagSpan<TTag>> GetTags(IMappingTagSpan<TLexTag> span);
public abstract IEnumerable<ITagSpan<TTag>> GetTags(IMappingTagSpan<LexTag> span);

public void Dispose()
{
Expand Down
14 changes: 14 additions & 0 deletions src/Language/SameWordHighlighter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Utilities;

namespace PkgdefLanguage
{
[Export(typeof(IViewTaggerProvider))]
[ContentType(Constants.LanguageName)]
[TagType(typeof(TextMarkerTag))]
public class SameWordHighlighter : SameWordHighlighterBase
{

}
}
2 changes: 1 addition & 1 deletion src/Language/StructureTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag
}
}

public class StructureTagger : LexTaggerConsumerBase<IStructureTag, LexTag>
public class StructureTagger : LexTaggerConsumerBase<IStructureTag>
{
public StructureTagger(ITagAggregator<LexTag> lexTags) : base(lexTags)
{ }
Expand Down
3 changes: 2 additions & 1 deletion src/PkgdefDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ public void Dispose()
if (!_isDisposed)
{
_buffer.Changed -= BufferChanged;
_isDisposed = true;
}

_isDisposed = true;
}
}

Expand Down
11 changes: 3 additions & 8 deletions src/PkgdefLanguage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
<TargetFrameworkProfile />
<LangVersion>10</LangVersion>
<UseCodebase>true</UseCodebase>
<AppDesignerFolder>Properties</AppDesignerFolder>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -74,7 +70,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Community.VisualStudio.Toolkit.16" ExcludeAssets="runtime">
<Version>16.0.357</Version>
<Version>16.0.359</Version>
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VSSDK.BuildTools">
Expand All @@ -94,9 +90,8 @@
<Compile Include="Language\LexTagger.cs" />
<Compile Include="Language\PredefinedVariables.cs" />
<Compile Include="Language\ErrorListManager.cs" />
<Compile Include="Language\BraceCompletion.cs" />
<Compile Include="Language\BasicLanguageFeatures.cs" />
<Compile Include="Language\ClassificationTagger.cs" />
<Compile Include="Language\CompletionCommitManager.cs" />
<Compile Include="Language\CompletionSource.cs" />
<Compile Include="Language\ErrorTagger.cs" />
<Compile Include="Language\Language.cs" />
Expand Down
2 changes: 1 addition & 1 deletion test/PkgdefLanguage.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Compile Remove="C:\Users\madsk\.nuget\packages\community.visualstudio.toolkit.16\16.0.357\build\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Community.VisualStudio.Toolkit.16" Version="16.0.357" />
<PackageReference Include="Community.VisualStudio.Toolkit.16" Version="16.0.359" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
Expand Down

0 comments on commit 10033bf

Please sign in to comment.