Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Attila Kisko committed May 29, 2022
0 parents commit 375a23b
Show file tree
Hide file tree
Showing 13 changed files with 371 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.vs/
bin/
obj/
.DS_Store

37 changes: 37 additions & 0 deletions HighlightNonAscii.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32414.318
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HighlightNonAscii", "HighlightNonAscii\HighlightNonAscii.csproj", "{32ECE961-F594-46EF-8922-588CC18EA929}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{64CEA342-BF64-436E-8D62-9CD6B3E713D9}"
ProjectSection(SolutionItems) = preProject
LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{32ECE961-F594-46EF-8922-588CC18EA929}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{32ECE961-F594-46EF-8922-588CC18EA929}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32ECE961-F594-46EF-8922-588CC18EA929}.Debug|x86.ActiveCfg = Debug|x86
{32ECE961-F594-46EF-8922-588CC18EA929}.Debug|x86.Build.0 = Debug|x86
{32ECE961-F594-46EF-8922-588CC18EA929}.Release|Any CPU.ActiveCfg = Release|Any CPU
{32ECE961-F594-46EF-8922-588CC18EA929}.Release|Any CPU.Build.0 = Release|Any CPU
{32ECE961-F594-46EF-8922-588CC18EA929}.Release|x86.ActiveCfg = Release|x86
{32ECE961-F594-46EF-8922-588CC18EA929}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A550F327-D73E-4ACA-8C08-8EB1395C1B75}
EndGlobalSection
EndGlobal
90 changes: 90 additions & 0 deletions HighlightNonAscii/HighlightNonAscii.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MinimumVisualStudioVersion>17.0</MinimumVisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>{32ECE961-F594-46EF-8922-588CC18EA929}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Enyim.Extensions.HighlightNonAscii</RootNamespace>
<AssemblyName>HighlightNonAscii</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<GeneratePkgDefFile>true</GeneratePkgDefFile>
<UseCodebase>true</UseCodebase>
<IncludeAssemblyInVSIXContainer>true</IncludeAssemblyInVSIXContainer>
<IncludeDebugSymbolsInVSIXContainer>false</IncludeDebugSymbolsInVSIXContainer>
<IncludeDebugSymbolsInLocalVSIXDeployment>false</IncludeDebugSymbolsInLocalVSIXDeployment>
<CopyBuildOutputToOutputDirectory>true</CopyBuildOutputToOutputDirectory>
<CopyOutputSymbolsToOutputDirectory>true</CopyOutputSymbolsToOutputDirectory>
<StartAction>Program</StartAction>
<StartProgram Condition="'$(DevEnvDir)' != ''">$(DevEnvDir)devenv.exe</StartProgram>
<StartArguments>/rootsuffix Exp</StartArguments>
</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>
<Compile Include="NonAsciiTaggerProvider.cs" />
<Compile Include="NonAsciiHighlightFormatDefinition.cs" />
<Compile Include="NonAsciiHighlightTag.cs" />
<Compile Include="NonAsciiTagger.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="HighlightNonAsciiPackage.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="..\LICENSE">
<Link>LICENSE</Link>
<IncludeInVSIX>true</IncludeInVSIX>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.0.31902.203" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.1.4058" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
<!-- 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>
56 changes: 56 additions & 0 deletions HighlightNonAscii/HighlightNonAsciiPackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.VisualStudio.Shell;

namespace Enyim.Extensions.HighlightNonAscii
{
/// <summary>
/// This is the class that implements the package exposed by this assembly.
/// </summary>
/// <remarks>
/// <para>
/// The minimum requirement for a class to be considered a valid package for Visual Studio
/// is to implement the IVsPackage interface and register itself with the shell.
/// This package uses the helper classes defined inside the Managed Package Framework (MPF)
/// to do it: it derives from the Package class that provides the implementation of the
/// IVsPackage interface and uses the registration attributes defined in the framework to
/// register itself and its components with the shell. These attributes tell the pkgdef creation
/// utility what data to put into .pkgdef file.
/// </para>
/// <para>
/// To get loaded into VS, the package must be referred by &lt;Asset Type="Microsoft.VisualStudio.VsPackage" ...&gt; in .vsixmanifest file.
/// </para>
/// </remarks>
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[Guid(HighlightNonAsciiPackage.PackageGuidString)]
public sealed class HighlightNonAsciiPackage : AsyncPackage
{
/// <summary>
/// HighlightNonAsciiPackage GUID string.
/// </summary>
public const string PackageGuidString = "eaf80dd5-5dfd-4d25-a572-41f19f161eea";

#region Package Members

/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
/// where you can put all the initialization code that rely on services provided by VisualStudio.
/// </summary>
/// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
/// <param name="progress">A provider for progress updates.</param>
/// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
// When initialized asynchronously, the current thread may be a background thread at this point.
// Do any initialization that requires the UI thread after switching to the UI thread.
await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
}

#endregion
}
}
27 changes: 27 additions & 0 deletions HighlightNonAscii/NonAsciiHighlightFormatDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Windows.Media;

using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;

namespace Enyim.Extensions.HighlightNonAscii
{
[Export(typeof(EditorFormatDefinition))]
[Name(NonAsciiHighlightFormatDefinition.TAG)]
[UserVisible(true)]
internal class NonAsciiHighlightFormatDefinition : MarkerFormatDefinition
{
public const string TAG = "MarkerFormatDefinition/" + nameof(NonAsciiHighlightFormatDefinition);

public NonAsciiHighlightFormatDefinition()
{
ForegroundColor = Colors.Red;
BackgroundColor = Colors.LightSalmon;
DisplayName = "Highlight Non-Ascii";
ZOrder = 100;
}
}
}
15 changes: 15 additions & 0 deletions HighlightNonAscii/NonAsciiHighlightTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Linq;
using System.Collections.Generic;

using Microsoft.VisualStudio.Text.Tagging;

namespace Enyim.Extensions.HighlightNonAscii
{
internal class NonAsciiHighlightTag : TextMarkerTag
{
public NonAsciiHighlightTag() : base(NonAsciiHighlightFormatDefinition.TAG)
{
}
}
}
29 changes: 29 additions & 0 deletions HighlightNonAscii/NonAsciiTagger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Linq;
using System.Collections.Generic;

using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Tagging;

namespace Enyim.Extensions.HighlightNonAscii
{
internal class NonAsciiTagger : ITagger<NonAsciiHighlightTag>
{
public event EventHandler<SnapshotSpanEventArgs> TagsChanged;

public IEnumerable<ITagSpan<NonAsciiHighlightTag>> GetTags(NormalizedSnapshotSpanCollection spans)
{
foreach (var span in spans)
{
for (var i = span.Start.Position; i < span.End.Position; i++)
{
var c = span.Snapshot[i];
if (c > 127)
{
yield return new TagSpan<NonAsciiHighlightTag>(new SnapshotSpan(new SnapshotPoint(span.Snapshot, i), 1), new NonAsciiHighlightTag());
}
}
}
}
}
}
27 changes: 27 additions & 0 deletions HighlightNonAscii/NonAsciiTaggerProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel.Composition;

using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Utilities;

namespace Enyim.Extensions.HighlightNonAscii
{
[Export(typeof(IViewTaggerProvider))]
[ContentType("text")]
[ContentType("code")]
[TagType(typeof(TextMarkerTag))]
[TextViewRole(PredefinedTextViewRoles.Document)]
internal class NonAsciiTaggerProvider : IViewTaggerProvider
{
public ITagger<T> CreateTagger<T>(ITextView textView, ITextBuffer buffer) where T : ITag
{
if (textView.TextBuffer != buffer) return null;

return buffer.Properties.GetOrCreateSingletonProperty(() => new NonAsciiTagger()) as ITagger<T>;
}
}
}
33 changes: 33 additions & 0 deletions HighlightNonAscii/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("HighlightNonAscii")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("enyim.com")]
[assembly: AssemblyProduct("HighlightNonAscii")]
[assembly: AssemblyCopyright("(c) 2022 enyim.com, Attila Kiskó")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]
24 changes: 24 additions & 0 deletions HighlightNonAscii/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="HighlightNonAscii.6b083210-9e15-4654-a0e9-18c4603deee8" Version="1.0.2" Language="en-US" Publisher="Attila Kiskó" />
<DisplayName>HighlightNonAscii</DisplayName>
<Description xml:space="preserve">Highlights characters in source that are above ASCII 127 (international, non-printable symbols, etc.)</Description>
<License>LICENSE</License>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0, 18.0)">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
</Dependencies>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.0,18.0)" DisplayName="Visual Studio core editor" />
</Prerequisites>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" />
</Assets>
</PackageManifest>
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 enyim.com, Attila Kiskó

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# What is this

Highlights characters in source that are above ASCII 127 (international, non-printable symbols, etc.)

# Demo

![demo](demo.png)
Binary file added demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 375a23b

Please sign in to comment.