Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 40fd2f1

Browse files
author
Sébastien Geiser
committedSep 15, 2022
Ajoutez des fichiers projet.
1 parent ff9b6a0 commit 40fd2f1

12 files changed

+391
-0
lines changed
 

‎GetJsonPathFromCursor.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32825.248
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetJsonPathFromCursor", "GetJsonPathFromCursor\GetJsonPathFromCursor.csproj", "{27948223-D4CE-4ECA-BF95-BF2BE0FB845B}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Debug|x86 = Debug|x86
12+
Release|Any CPU = Release|Any CPU
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{27948223-D4CE-4ECA-BF95-BF2BE0FB845B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{27948223-D4CE-4ECA-BF95-BF2BE0FB845B}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{27948223-D4CE-4ECA-BF95-BF2BE0FB845B}.Debug|x86.ActiveCfg = Debug|x86
19+
{27948223-D4CE-4ECA-BF95-BF2BE0FB845B}.Debug|x86.Build.0 = Debug|x86
20+
{27948223-D4CE-4ECA-BF95-BF2BE0FB845B}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{27948223-D4CE-4ECA-BF95-BF2BE0FB845B}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{27948223-D4CE-4ECA-BF95-BF2BE0FB845B}.Release|x86.ActiveCfg = Release|x86
23+
{27948223-D4CE-4ECA-BF95-BF2BE0FB845B}.Release|x86.Build.0 = Release|x86
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {D782E8A3-0B5D-461F-A7CD-113470832CA7}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using EnvDTE;
2+
using System.Collections.Generic;
3+
using System.Text.RegularExpressions;
4+
using System.Windows;
5+
6+
namespace GetJsonPathFromCursor
7+
{
8+
[Command(PackageIds.GetJsonPathCommand)]
9+
internal sealed class GetJsonPathCommand : BaseCommand<GetJsonPathCommand>
10+
{
11+
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
12+
{
13+
var getAllKeyRegex = new Regex(@"^(?<EndOfKey>(\\""|[^""])*"")\s*:");
14+
15+
await Package.JoinableTaskFactory.SwitchToMainThreadAsync();
16+
17+
DocumentView docView = await VS.Documents.GetActiveDocumentViewAsync();
18+
if (docView?.TextView?.TextSnapshot?.ContentType?.DisplayName.Equals("Json", StringComparison.OrdinalIgnoreCase) != true)
19+
{
20+
await VS.MessageBox.ShowWarningAsync("Get full JSON path to cursor", "No \"current\" document found or it's not a JSON document.");
21+
return;
22+
}
23+
24+
string currentText = docView.TextView.TextSnapshot.GetText();
25+
26+
int position = docView.TextView.Caret.Position.BufferPosition.Position;
27+
28+
Match match = getAllKeyRegex.Match(currentText.Substring(position));
29+
30+
if(!match.Success)
31+
{
32+
await VS.MessageBox.ShowWarningAsync("Get full JSON path to cursor", "Impossible to execute : The cursor is not on a JSON key");
33+
return;
34+
}
35+
36+
string textToEndOfPath = currentText.Substring(0, position) + match.Groups["EndOfKey"].Value;
37+
string reversedText = textToEndOfPath.ReverseText();
38+
39+
var reverseKeyList = new List<string>();
40+
41+
string fullKeyPath = string.Join(".", ParseReverse(reverseKeyList, reversedText)).ReverseText();
42+
43+
Clipboard.SetText(fullKeyPath);
44+
}
45+
46+
private List<string> ParseReverse(List<string> reverseKeyList, string reversedText)
47+
{
48+
var reverseStringDetectionRegex = new Regex(@"^""(?<Key>(""\\|[^""])*)""\s*");
49+
var objectStartWithKeyRegex = new Regex(@"^{\s*:\s*");
50+
var objectStartWithoutKeyRegex = new Regex(@"^{\s*");
51+
var otherJsonObject = new Regex(@"^,\s*}(\s+|""(""\\|[^""])*""|:|,|(?<curlyBracket>})|(?<-curlyBracket>{))*{(\s*:\s*""(""\\|[^""])*"")*\s*");
52+
var otherJsonString = new Regex(@"^,\s*""(""\\|[^""])*""\s*:\s*""(""\\|[^""])*""\s*");
53+
54+
while(reversedText.Length > 0)
55+
{
56+
Match keyPartMatch = reverseStringDetectionRegex.Match(reversedText);
57+
58+
if(keyPartMatch.Success)
59+
{
60+
reverseKeyList.Add(keyPartMatch.Groups["Key"].Value);
61+
reversedText = reverseStringDetectionRegex.Replace(reversedText, "");
62+
63+
while(reversedText.Length > 0)
64+
{
65+
if(objectStartWithKeyRegex.IsMatch(reversedText))
66+
{
67+
reversedText = objectStartWithKeyRegex.Replace(reversedText, "");
68+
}
69+
else if(objectStartWithoutKeyRegex.IsMatch(reversedText))
70+
{
71+
reversedText = objectStartWithoutKeyRegex.Replace(reversedText, "");
72+
}
73+
else if(otherJsonObject.IsMatch(reversedText))
74+
{
75+
reversedText = otherJsonObject.Replace(reversedText, "");
76+
}
77+
else if(otherJsonString.IsMatch(reversedText))
78+
{
79+
reversedText = otherJsonString.Replace(reversedText, "");
80+
}
81+
else
82+
{
83+
break;
84+
}
85+
}
86+
}
87+
else
88+
{
89+
VS.MessageBox.ShowWarning("Get full JSON path to cursor", "Format Error. Current decoded path copied");
90+
91+
return reverseKeyList;
92+
}
93+
}
94+
95+
return reverseKeyList;
96+
}
97+
}
98+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
5+
<LangVersion>latest</LangVersion>
6+
</PropertyGroup>
7+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
8+
<PropertyGroup>
9+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
10+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
11+
<SchemaVersion>2.0</SchemaVersion>
12+
<ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
13+
<ProjectGuid>{27948223-D4CE-4ECA-BF95-BF2BE0FB845B}</ProjectGuid>
14+
<OutputType>Library</OutputType>
15+
<AppDesignerFolder>Properties</AppDesignerFolder>
16+
<RootNamespace>GetJsonPathFromCursor</RootNamespace>
17+
<AssemblyName>GetJsonPathFromCursor</AssemblyName>
18+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
19+
<GeneratePkgDefFile>true</GeneratePkgDefFile>
20+
<UseCodebase>true</UseCodebase>
21+
<IncludeAssemblyInVSIXContainer>true</IncludeAssemblyInVSIXContainer>
22+
<IncludeDebugSymbolsInVSIXContainer>true</IncludeDebugSymbolsInVSIXContainer>
23+
<IncludeDebugSymbolsInLocalVSIXDeployment>false</IncludeDebugSymbolsInLocalVSIXDeployment>
24+
<CopyBuildOutputToOutputDirectory>true</CopyBuildOutputToOutputDirectory>
25+
<CopyOutputSymbolsToOutputDirectory>true</CopyOutputSymbolsToOutputDirectory>
26+
<StartAction>Program</StartAction>
27+
<StartProgram Condition="'$(DevEnvDir)' != ''">$(DevEnvDir)devenv.exe</StartProgram>
28+
<StartArguments>/rootsuffix Exp</StartArguments>
29+
</PropertyGroup>
30+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
31+
<DebugSymbols>true</DebugSymbols>
32+
<DebugType>full</DebugType>
33+
<Optimize>false</Optimize>
34+
<OutputPath>bin\Debug\</OutputPath>
35+
<DefineConstants>DEBUG;TRACE</DefineConstants>
36+
<ErrorReport>prompt</ErrorReport>
37+
<WarningLevel>4</WarningLevel>
38+
</PropertyGroup>
39+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
40+
<DebugType>pdbonly</DebugType>
41+
<Optimize>true</Optimize>
42+
<OutputPath>bin\Release\</OutputPath>
43+
<DefineConstants>TRACE</DefineConstants>
44+
<ErrorReport>prompt</ErrorReport>
45+
<WarningLevel>4</WarningLevel>
46+
</PropertyGroup>
47+
<ItemGroup>
48+
<Compile Include="Properties\AssemblyInfo.cs" />
49+
<Compile Include="Commands\GetJsonPathCommand.cs" />
50+
<Compile Include="GetJsonPathFromCursorPackage.cs" />
51+
<Compile Include="source.extension.cs">
52+
<AutoGen>True</AutoGen>
53+
<DesignTime>True</DesignTime>
54+
<DependentUpon>source.extension.vsixmanifest</DependentUpon>
55+
</Compile>
56+
<Compile Include="StringExtensions.cs" />
57+
<Compile Include="VSCommandTable.cs">
58+
<AutoGen>True</AutoGen>
59+
<DesignTime>True</DesignTime>
60+
<DependentUpon>VSCommandTable.vsct</DependentUpon>
61+
</Compile>
62+
</ItemGroup>
63+
<ItemGroup>
64+
<None Include="source.extension.vsixmanifest">
65+
<SubType>Designer</SubType>
66+
<Generator>VsixManifestGenerator</Generator>
67+
<LastGenOutput>source.extension.cs</LastGenOutput>
68+
</None>
69+
<Content Include="Resources\Icon.png">
70+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
71+
<IncludeInVSIX>true</IncludeInVSIX>
72+
</Content>
73+
</ItemGroup>
74+
<ItemGroup>
75+
<VSCTCompile Include="VSCommandTable.vsct">
76+
<ResourceName>Menus.ctmenu</ResourceName>
77+
<Generator>VsctGenerator</Generator>
78+
<LastGenOutput>VSCommandTable.cs</LastGenOutput>
79+
</VSCTCompile>
80+
</ItemGroup>
81+
<ItemGroup>
82+
<Reference Include="PresentationCore" />
83+
<Reference Include="System" />
84+
<Reference Include="System.Design" />
85+
<Reference Include="System.ComponentModel.Composition" />
86+
<Reference Include="System.Xml.Linq" />
87+
</ItemGroup>
88+
<ItemGroup>
89+
<PackageReference Include="Community.VisualStudio.VSCT" Version="16.0.29.6" PrivateAssets="all" />
90+
<PackageReference Include="Community.VisualStudio.Toolkit.17" Version="17.0.430" ExcludeAssets="Runtime" />
91+
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.0.5232" />
92+
</ItemGroup>
93+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
94+
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
95+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
96+
Other similar extension points exist, see Microsoft.Common.targets.
97+
<Target Name="BeforeBuild">
98+
</Target>
99+
<Target Name="AfterBuild">
100+
</Target>
101+
-->
102+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
global using Community.VisualStudio.Toolkit;
2+
global using Microsoft.VisualStudio.Shell;
3+
global using System;
4+
global using Task = System.Threading.Tasks.Task;
5+
using Microsoft.VisualStudio.Package;
6+
using System.Runtime.InteropServices;
7+
using System.Threading;
8+
9+
namespace GetJsonPathFromCursor
10+
{
11+
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
12+
[InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)]
13+
[ProvideMenuResource("Menus.ctmenu", 1)]
14+
[Guid(PackageGuids.GetJsonPathFromCursorString)]
15+
public sealed class GetJsonPathFromCursorPackage : ToolkitPackage
16+
{
17+
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
18+
{
19+
await this.RegisterCommandsAsync();
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using GetJsonPathFromCursor;
2+
using System.Reflection;
3+
using System.Runtime.InteropServices;
4+
5+
[assembly: AssemblyTitle(Vsix.Name)]
6+
[assembly: AssemblyDescription(Vsix.Description)]
7+
[assembly: AssemblyConfiguration("")]
8+
[assembly: AssemblyCompany(Vsix.Author)]
9+
[assembly: AssemblyProduct(Vsix.Name)]
10+
[assembly: AssemblyCopyright(Vsix.Author)]
11+
[assembly: AssemblyTrademark("")]
12+
[assembly: AssemblyCulture("")]
13+
14+
[assembly: ComVisible(false)]
15+
16+
[assembly: AssemblyVersion(Vsix.Version)]
17+
[assembly: AssemblyFileVersion(Vsix.Version)]
18+
19+
namespace System.Runtime.CompilerServices
20+
{
21+
public class IsExternalInit { }
22+
}
266 Bytes
Loading
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Linq;
2+
3+
namespace GetJsonPathFromCursor
4+
{
5+
public static class StringExtensions
6+
{
7+
public static string ReverseText(this string text) => new(text.Reverse().ToArray());
8+
}
9+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// ------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This file was generated by VSIX Synchronizer
4+
// </auto-generated>
5+
// ------------------------------------------------------------------------------
6+
namespace GetJsonPathFromCursor
7+
{
8+
using System;
9+
10+
/// <summary>
11+
/// Helper class that exposes all GUIDs used across VS Package.
12+
/// </summary>
13+
internal sealed partial class PackageGuids
14+
{
15+
public const string GetJsonPathFromCursorString = "d275998e-5f95-4f3a-ae5a-b5878a529d3e";
16+
public static Guid GetJsonPathFromCursor = new Guid(GetJsonPathFromCursorString);
17+
}
18+
/// <summary>
19+
/// Helper class that encapsulates all CommandIDs uses across VS Package.
20+
/// </summary>
21+
internal sealed partial class PackageIds
22+
{
23+
public const int MyMenuGroup = 0x0001;
24+
public const int GetJsonPathCommand = 0x0100;
25+
}
26+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
4+
<Extern href="stdidcmd.h"/>
5+
<Extern href="vsshlids.h"/>
6+
<Include href="KnownImageIds.vsct"/>
7+
<Include href="VSGlobals.vsct"/>
8+
9+
<Commands package="GetJsonPathFromCursor">
10+
<Groups>
11+
<Group guid="GetJsonPathFromCursor" id="MyMenuGroup" priority="0x0600" >
12+
<Parent guid="VSMainMenu" id="Tools"/>
13+
</Group>
14+
</Groups>
15+
16+
<!--This section defines the elements the user can interact with, like a menu command or a button
17+
or combo box in a toolbar. -->
18+
<Buttons>
19+
<Button guid="GetJsonPathFromCursor" id="GetJsonPathCommand" priority="0x0100" type="Button">
20+
<Parent guid="GetJsonPathFromCursor" id="MyMenuGroup" />
21+
<CommandFlag>IconIsMoniker</CommandFlag>
22+
<Strings>
23+
<ButtonText>Get full JSON path to cursor</ButtonText>
24+
<LocCanonicalName>.GetJsonPathFromCursor.GetJsonPathCommand</LocCanonicalName>
25+
</Strings>
26+
</Button>
27+
</Buttons>
28+
</Commands>
29+
30+
<KeyBindings>
31+
<KeyBinding guid="GetJsonPathFromCursor" id="GetJsonPathCommand"
32+
key1="J" mod1="Control Shift" editor="GUID_TextEditorFactory" />
33+
</KeyBindings>
34+
35+
<Symbols>
36+
<GuidSymbol name="GetJsonPathFromCursor" value="{d275998e-5f95-4f3a-ae5a-b5878a529d3e}">
37+
<IDSymbol name="MyMenuGroup" value="0x0001" />
38+
<IDSymbol name="GetJsonPathCommand" value="0x0100" />
39+
</GuidSymbol>
40+
</Symbols>
41+
</CommandTable>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// ------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This file was generated by VSIX Synchronizer
4+
// </auto-generated>
5+
// ------------------------------------------------------------------------------
6+
namespace GetJsonPathFromCursor
7+
{
8+
internal sealed partial class Vsix
9+
{
10+
public const string Id = "GetJsonPathFromCursor.ddf5199e-94cf-4ebd-b609-3fcd3359fda6";
11+
public const string Name = "GetJsonPathFromCursor";
12+
public const string Description = @"Empty VSIX Project.";
13+
public const string Language = "en-US";
14+
public const string Version = "1.0";
15+
public const string Author = "CodingSeb";
16+
public const string Tags = "";
17+
}
18+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<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">
3+
<Metadata>
4+
<Identity Id="GetJsonPathFromCursor.ddf5199e-94cf-4ebd-b609-3fcd3359fda6" Version="1.0" Language="en-US" Publisher="CodingSeb" />
5+
<DisplayName>GetJsonPathFromCursor</DisplayName>
6+
<Description xml:space="preserve">Empty VSIX Project.</Description>
7+
<Icon>Resources\Icon.png</Icon>
8+
<PreviewImage>Resources\Icon.png</PreviewImage>
9+
</Metadata>
10+
<Installation>
11+
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0, 18.0)">
12+
<ProductArchitecture>amd64</ProductArchitecture>
13+
</InstallationTarget>
14+
</Installation>
15+
<Prerequisites>
16+
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.0,)" DisplayName="Visual Studio core editor" />
17+
</Prerequisites>
18+
<Assets>
19+
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
20+
</Assets>
21+
</PackageManifest>

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# GetJsonPathFromCursor

0 commit comments

Comments
 (0)
Please sign in to comment.