diff options
author | Miguel Costa <miguel.costa@qt.io> | 2021-04-19 11:49:29 +0200 |
---|---|---|
committer | Miguel Costa <miguel.costa@qt.io> | 2021-04-20 09:25:13 +0000 |
commit | 8fa9987ac0bf08f204f37f3d22b07b211b0565d0 (patch) | |
tree | 420bdfc0d1b518a86b70e37b3ebee805c8f8333d /src | |
parent | 4cbf4a4537a11e489da68130a5f608c6664211f3 (diff) |
Highlight C#-macro syntax
When editing files with a .csmacro extension, the macro statement
will be syntax-highlighted, overlayed on the default C# highlighting.
Change-Id: I3c02307528d1f125222f303d134007b8abc5d1cc
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qtvstest/QtVsTest.cs | 18 | ||||
-rw-r--r-- | src/qtvstest/QtVsTest.csproj | 30 | ||||
-rw-r--r-- | src/qtvstest/csmacro.tmLanguage_TT | 529 | ||||
-rw-r--r-- | src/qtvstest/csmacro.tmTheme_TT | 68 |
4 files changed, 645 insertions, 0 deletions
diff --git a/src/qtvstest/QtVsTest.cs b/src/qtvstest/QtVsTest.cs index 10cbd2d0..ee192a8a 100644 --- a/src/qtvstest/QtVsTest.cs +++ b/src/qtvstest/QtVsTest.cs @@ -38,6 +38,7 @@ using Task = System.Threading.Tasks.Task; namespace QtVsTest { using Macros; + using System.IO; [Guid(PackageGuidString)] [InstalledProductRegistration( @@ -63,6 +64,23 @@ namespace QtVsTest CancellationToken cancellationToken, IProgress<ServiceProgressData> progress) { + // Install .csmacro syntax highlighting + var uri = new Uri(System.Reflection.Assembly + .GetExecutingAssembly().EscapedCodeBase); + var pkgInstallPath = Path.GetDirectoryName( + Uri.UnescapeDataString(uri.AbsolutePath)) + @"\"; + var grammarFilesPath = Environment. + ExpandEnvironmentVariables(@"%USERPROFILE%\.vs\Extensions\qtcsmacro"); + Directory.CreateDirectory(grammarFilesPath); + File.Copy( + Path.Combine(pkgInstallPath, "csmacro.tmLanguage"), + Path.Combine(grammarFilesPath, "csmacro.tmLanguage"), + overwrite: true); + File.Copy( + Path.Combine(pkgInstallPath, "csmacro.tmTheme"), + Path.Combine(grammarFilesPath, "csmacro.tmTheme"), + overwrite: true); + // Start macro server loop as background task await Task.Run(() => MacroServer.LoopAsync().Forget()); } diff --git a/src/qtvstest/QtVsTest.csproj b/src/qtvstest/QtVsTest.csproj index d2135c46..20e03af0 100644 --- a/src/qtvstest/QtVsTest.csproj +++ b/src/qtvstest/QtVsTest.csproj @@ -87,9 +87,36 @@ <SubType>Designer</SubType> </None> <Content Include="Resources\QtVsTest.ico" /> + <T4Template Include="csmacro.tmLanguage_TT"> + <Generator>TextTemplatingFileGenerator</Generator> + <OutputFile>csmacro.tmLanguage</OutputFile> + <DependsOn>$(SolutionDir)\common.tt</DependsOn> + <LastGenOutput>csmacro.tmLanguage</LastGenOutput> + </T4Template> + <Content Include="csmacro.tmLanguage"> + <AutoGen>True</AutoGen> + <DesignTime>True</DesignTime> + <DependentUpon>csmacro.tmLanguage_TT</DependentUpon> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + <IncludeInVSIX>true</IncludeInVSIX> + </Content> + <T4Template Include="csmacro.tmTheme_TT"> + <Generator>TextTemplatingFileGenerator</Generator> + <OutputFile>csmacro.tmTheme</OutputFile> + <DependsOn>$(SolutionDir)\common.tt</DependsOn> + <LastGenOutput>csmacro.tmTheme</LastGenOutput> + </T4Template> + <Content Include="csmacro.tmTheme"> + <AutoGen>True</AutoGen> + <DesignTime>True</DesignTime> + <DependentUpon>csmacro.tmTheme_TT</DependentUpon> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + <IncludeInVSIX>true</IncludeInVSIX> + </Content> </ItemGroup> <Import Project="..\config\$(VisualStudioVersion)\qtvstools.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <Import Project="$(SolutionDir)\transform.targets" /> <Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" /> <PropertyGroup> <MetaInfo> @@ -159,4 +186,7 @@ namespace MSBuild.MetaInfo { <EmbedInteropTypes>False</EmbedInteropTypes> </Reference> </ItemGroup> + <ItemGroup> + <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /> + </ItemGroup> </Project>
\ No newline at end of file diff --git a/src/qtvstest/csmacro.tmLanguage_TT b/src/qtvstest/csmacro.tmLanguage_TT new file mode 100644 index 00000000..86b361fb --- /dev/null +++ b/src/qtvstest/csmacro.tmLanguage_TT @@ -0,0 +1,529 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ***************************************************************************** + ** + ** Copyright (C) 2021 The Qt Company Ltd. + ** Contact: https://www.qt.io/licensing/ + ** + ** This file is part of the Qt VS Tools. + ** + ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ + ** Commercial License Usage + ** Licensees holding valid commercial Qt licenses may use this file in + ** accordance with the commercial license agreement provided with the + ** Software or, alternatively, in accordance with the terms contained in + ** a written agreement between you and The Qt Company. For licensing terms + ** and conditions see https://www.qt.io/terms-conditions. For further + ** information use the contact form at https://www.qt.io/contact-us. + ** + ** GNU General Public License Usage + ** Alternatively, this file may be used under the terms of the GNU + ** General Public License version 3 as published by the Free Software + ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT + ** included in the packaging of this file. Please review the following + ** information to ensure the GNU General Public License requirements will + ** be met: https://www.gnu.org/licenses/gpl-3.0.html. + ** + ** $QT_END_LICENSE$ + ** + ***************************************************************************** +<#@output extension="tmLanguage" #> +<#@include file="$(SolutionDir)\common.tt" #> +<# + var csGrammarFile = Path.Combine(DevEnvDir, + @"CommonExtensions\Microsoft\TextMate\Starterkit\Extensions\csharp\Syntaxes", + "csharp.tmLanguage"); +#> + ** <#=WARNING_GENERATED_FILE#> + ***************************************************************************** +--> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> + <dict> + <key>name</key> + <string>C#</string> + <key>scopeName</key> + <string>source.cs</string> + <key>fileTypes</key> + <array> + <string>csmacro</string> + </array> + <key>patterns</key> + <array> + <!-- + ///////////////////////////////////////////////////////////////////////////////////////////// + //# using "<namespace>" + ///////////////////////////////////////////////////////////////////////////////////////// --> + <dict> + <key>match</key> + <string>(//#\s*using)\s+(\"[^\"\r\n]+")([^\r\n]*)\r?\n</string> + <key>captures</key> + <dict> + <key>1</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>2</key> + <dict> + <key>name</key> + <string>string.quoted.double.cs</string> + </dict> + <key>3</key> + <dict> + <key>name</key> + <string>comment.line.double-slash.cs</string> + </dict> + </dict> + </dict> + <!-- + ///////////////////////////////////////////////////////////////////////////////////////////// + //# using <namespace> + ///////////////////////////////////////////////////////////////////////////////////////// --> + <dict> + <key>match</key> + <string>(//#\s*using)\s+([\w\.]*)([^\r\n]*)\r?\n</string> + <key>captures</key> + <dict> + <key>1</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>2</key> + <dict> + <key>name</key> + <string>entity.name.cs</string> + </dict> + <key>3</key> + <dict> + <key>name</key> + <string>comment.line.double-slash.cs</string> + </dict> + </dict> + </dict> + <!-- + ///////////////////////////////////////////////////////////////////////////////////////////// + //# macro <macro name> + ///////////////////////////////////////////////////////////////////////////////////////// --> + <dict> + <key>match</key> + <string>(//#\s*macro)\s+([^\r\n]*)\r?\n</string> + <key>captures</key> + <dict> + <key>1</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>2</key> + <dict> + <key>name</key> + <string>entity.name.cs</string> + </dict> + </dict> + </dict> + <!-- + ///////////////////////////////////////////////////////////////////////////////////////////// + //# call <macro> + ///////////////////////////////////////////////////////////////////////////////////////// --> + <dict> + <key>match</key> + <string>(//#\s*call)\s+([^\r\n]*)\r?\n</string> + <key>captures</key> + <dict> + <key>1</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>2</key> + <dict> + <key>name</key> + <string>entity.name.cs</string> + </dict> + </dict> + </dict> + <!-- + ///////////////////////////////////////////////////////////////////////////////////////////// + //# thread <ui | default> + ///////////////////////////////////////////////////////////////////////////////////////// --> + <dict> + <key>match</key> + <string>(//#\s*thread)\s+(ui|default)([^\r\n]*)\r?\n</string> + <key>captures</key> + <dict> + <key>1</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>2</key> + <dict> + <key>name</key> + <string>keyword.cs</string> + </dict> + <key>3</key> + <dict> + <key>name</key> + <string>comment.line.double-slash.cs</string> + </dict> + </dict> + </dict> + <!-- + ///////////////////////////////////////////////////////////////////////////////////////////// + //# ref <assembly name> [namespace] [namespace] ... + ///////////////////////////////////////////////////////////////////////////////////////// --> + <dict> + <key>match</key> + <string>(//#\s*ref(?:erence)?)\s+((?:\"[^\"\r\n]*\")|(?:[\w\.]+))((?:\s+[\w\.]+)*)([^\r\n]*)\r?\n</string> + <key>captures</key> + <dict> + <key>1</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>2</key> + <dict> + <key>name</key> + <string>string.quoted.double.cs</string> + </dict> + <key>3</key> + <dict> + <key>name</key> + <string>entity.name.cs</string> + </dict> + <key>4</key> + <dict> + <key>name</key> + <string>comment.line.double-slash.cs</string> + </dict> + </dict> + </dict> + <!-- + ///////////////////////////////////////////////////////////////////////////////////////////// + //# var <type> <name> => <initial value> + ///////////////////////////////////////////////////////////////////////////////////////// --> + <dict> + <key>begin</key> + <string>(//#\s*var)\s+([\w\.]+)\s+(\w+)\s+(=>)</string> + <key>beginCaptures</key> + <dict> + <key>1</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>2</key> + <dict> + <key>name</key> + <string>entity.name.type.class.cs</string> + </dict> + <key>3</key> + <dict> + <key>name</key> + <string>entity.name.variable.cs</string> + </dict> + <key>4</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + </dict> + <key>end</key> + <string>^</string> + <key>patterns</key> + <array> + <dict> + <key>include</key> + <string>#expression</string> + </dict> + </array> + </dict> + <!-- + ///////////////////////////////////////////////////////////////////////////////////////////// + //# var <type> <name> + ///////////////////////////////////////////////////////////////////////////////////////// --> + <dict> + <key>match</key> + <string>(//#\s*var)\s+([\w\.]+)\s+(\w+)([^\r\n]*)\r?\n</string> + <key>captures</key> + <dict> + <key>1</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>2</key> + <dict> + <key>name</key> + <string>entity.name.type.class.cs</string> + </dict> + <key>3</key> + <dict> + <key>name</key> + <string>entity.name.variable.cs</string> + </dict> + <key>4</key> + <dict> + <key>name</key> + <string>comment.line.double-slash.cs</string> + </dict> + </dict> + </dict> + <!-- + ///////////////////////////////////////////////////////////////////////////////////////////// + //# service <var name> <service interface> [service type] + ///////////////////////////////////////////////////////////////////////////////////////// --> + <dict> + <key>match</key> + <string>(//#\s*service)\s+(\w+)\s+([\w\.]+)(?:\s+([\w\.]+))?([^\r\n]*)\r?\n</string> + <key>captures</key> + <dict> + <key>1</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>2</key> + <dict> + <key>name</key> + <string>entity.name.variable.cs</string> + </dict> + <key>3</key> + <dict> + <key>name</key> + <string>entity.name.type.interface.cs</string> + </dict> + <key>4</key> + <dict> + <key>name</key> + <string>entity.name.type.class.cs</string> + </dict> + <key>5</key> + <dict> + <key>name</key> + <string>comment.line.double-slash.cs</string> + </dict> + </dict> + </dict> + <!-- + ///////////////////////////////////////////////////////////////////////////////////////////// + //# wait [timeout] [ <var type> <var name> ] => <expr> + ///////////////////////////////////////////////////////////////////////////////////////// --> + <dict> + <key>begin</key> + <string>(//#\s*wait)\s+(?:(\d+)\s+)?(?:([\w\.]+)\s+(\w+)\s+)?(=>)</string> + <key>beginCaptures</key> + <dict> + <key>1</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>2</key> + <dict> + <key>name</key> + <string>constant.numeric.decimal.cs</string> + </dict> + <key>3</key> + <dict> + <key>name</key> + <string>entity.name.type.class.cs</string> + </dict> + <key>4</key> + <dict> + <key>name</key> + <string>entity.name.variable.cs</string> + </dict> + <key>5</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + </dict> + <key>end</key> + <string>^</string> + <key>patterns</key> + <array> + <dict> + <key>include</key> + <string>#expression</string> + </dict> + </array> + </dict> + <!-- + ///////////////////////////////////////////////////////////////////////////////////////////// + //# ui context [ VS [timeout] ] => _string_ [, _string_, ... ] + //# ui context HWND => _int_ + ///////////////////////////////////////////////////////////////////////////////////////// --> + <dict> + <key>begin</key> + <string>(//#\s*ui)\s+(context)\s+(?:(?:(?:(VS)(?:\s+(\d+))?)|(HWND))\s+)?(=>)</string> + <key>beginCaptures</key> + <dict> + <key>1</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>2</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>3</key> + <dict> + <key>name</key> + <string>keyword.cs</string> + </dict> + <key>4</key> + <dict> + <key>name</key> + <string>constant.numeric.decimal.cs</string> + </dict> + <key>5</key> + <dict> + <key>name</key> + <string>keyword.cs</string> + </dict> + <key>6</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + </dict> + <key>end</key> + <string>^</string> + <key>patterns</key> + <array> + <dict> + <key>include</key> + <string>#expression</string> + </dict> + <dict> + <key>include</key> + <string>#punctuation-comma</string> + </dict> + </array> + </dict> + <!-- + ///////////////////////////////////////////////////////////////////////////////////////////// + //# ui pattern <_TypeName_> <_VarName_> [ => _string_ [, _string_, ... ] ] + //# ui pattern Invoke [ => _string_ [, _string_, ... ] ] + //# ui pattern Toggle [ => _string_ [, _string_, ... ] ] + ///////////////////////////////////////////////////////////////////////////////////////// --> + <dict> + <key>begin</key> + <string>(//#\s*ui)\s+(pattern)\s+([\w\.]+)\s+(?:(\w+)\s+)?(=>)</string> + <key>beginCaptures</key> + <dict> + <key>1</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>2</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>3</key> + <dict> + <key>name</key> + <string>entity.name.type.class.cs</string> + </dict> + <key>4</key> + <dict> + <key>name</key> + <string>entity.name.variable.cs</string> + </dict> + <key>5</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + </dict> + <key>end</key> + <string>^</string> + <key>patterns</key> + <array> + <dict> + <key>include</key> + <string>#expression</string> + </dict> + <dict> + <key>include</key> + <string>#punctuation-comma</string> + </dict> + </array> + </dict> + <!-- + ///////////////////////////////////////////////////////////////////////////////////////////// + //# ui pattern <_TypeName_> <_VarName_> + ///////////////////////////////////////////////////////////////////////////////////////// --> + <dict> + <key>match</key> + <string>(//#\s*ui)\s+(pattern)\s+([\w\.]+)\s+(\w+)([^\r\n]*)\r?\n</string> + <key>captures</key> + <dict> + <key>1</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>2</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>3</key> + <dict> + <key>name</key> + <string>entity.name.type.class.cs</string> + </dict> + <key>4</key> + <dict> + <key>name</key> + <string>entity.name.variable.cs</string> + </dict> + <key>5</key> + <dict> + <key>name</key> + <string>comment.line.double-slash.cs</string> + </dict> + </dict> + </dict> + <!-- + ///////////////////////////////////////////////////////////////////////////////////////////// + //# quit + ///////////////////////////////////////////////////////////////////////////////////////// --> + <dict> + <key>match</key> + <string>(//#\s*quit)([^\r\n]*)\r?\n</string> + <key>captures</key> + <dict> + <key>1</key> + <dict> + <key>name</key> + <string>keyword.control.inline.csmacro</string> + </dict> + <key>2</key> + <dict> + <key>name</key> + <string>comment.line.double-slash.cs</string> + </dict> + </dict> + </dict> + <!-- BEGIN Generated Text <#=XML_COMMENT_END#> +<#=string.Join("\r\n", File.ReadAllLines(csGrammarFile) + .SkipWhile(x => !x.Contains("<key>patterns</key>")) + .Skip(2) + .TakeWhile(x => !x.Contains("</plist>")))#> +<#=XML_COMMENT_BEGIN#> END Generated Text --> + <!-- <#/* --> + </array> + </dict> + <!-- */#> --> +</plist> diff --git a/src/qtvstest/csmacro.tmTheme_TT b/src/qtvstest/csmacro.tmTheme_TT new file mode 100644 index 00000000..a942a4e2 --- /dev/null +++ b/src/qtvstest/csmacro.tmTheme_TT @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ***************************************************************************** + ** + ** Copyright (C) 2021 The Qt Company Ltd. + ** Contact: https://www.qt.io/licensing/ + ** + ** This file is part of the Qt VS Tools. + ** + ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ + ** Commercial License Usage + ** Licensees holding valid commercial Qt licenses may use this file in + ** accordance with the commercial license agreement provided with the + ** Software or, alternatively, in accordance with the terms contained in + ** a written agreement between you and The Qt Company. For licensing terms + ** and conditions see https://www.qt.io/terms-conditions. For further + ** information use the contact form at https://www.qt.io/contact-us. + ** + ** GNU General Public License Usage + ** Alternatively, this file may be used under the terms of the GNU + ** General Public License version 3 as published by the Free Software + ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT + ** included in the packaging of this file. Please review the following + ** information to ensure the GNU General Public License requirements will + ** be met: https://www.gnu.org/licenses/gpl-3.0.html. + ** + ** $QT_END_LICENSE$ + ** + ***************************************************************************** +<#@output extension="tmTheme" #> +<#@include file="$(SolutionDir)\common.tt" #> +<# + var themeFile = Path.Combine(DevEnvDir, + @"CommonExtensions\Microsoft\TextMate\Starterkit\Themes", + "vs.tmTheme"); +#> + ** <#=WARNING_GENERATED_FILE#> + ***************************************************************************** +--> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> + <dict> + <key>name</key> + <string>csmacro Theme</string> + <key>settings</key> + <array> + <dict> + <key>name</key> + <string>csmacro-stmt</string> + <key>scope</key> + <string>keyword.control.inline.csmacro</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#66ff33</string> + </dict> + </dict> + <!-- BEGIN Generated Text <#=XML_COMMENT_END#> +<#=string.Join("\r\n", File.ReadAllLines(themeFile) + .SkipWhile(x => !x.Contains("<key>settings</key>")) + .Skip(2) + .TakeWhile(x => !x.Contains("</plist>")))#> +<#=XML_COMMENT_BEGIN#> END Generated Text --> + <!-- <#/* --> + </array> + </dict> + <!-- */#> --> +</plist> |