Skip to content

Commit c0eb58d

Browse files
committed
cleanup & refactoring
1 parent 3a1f1de commit c0eb58d

17 files changed

+257
-109
lines changed

CodeConnect.Gistify.Extension/CodeAnalysis/CodeAnalyzer.cs CodeConnect.Gistify.Engine/CodeAnalyzer.cs

+5-10
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
using System.Text;
66
using System.Threading.Tasks;
77

8-
namespace CodeConnect.Gistify.Extension.CodeAnalysis
8+
namespace CodeConnect.Gistify.Engine
99
{
1010
public static class CodeAnalyzer
1111
{
12-
public static string GetGistFromSnippet(int startPosition, int endPosition, string filePath)
12+
public static string AugmentSelection(Document document, int startPosition, int endPosition)
1313
{
14-
var document = VSIntegration.GetDocument(filePath);
1514
var tree = document.GetSyntaxTreeAsync().Result;
1615
var model = document.GetSemanticModelAsync().Result;
1716
var objectInfos = FindDeclarations(tree, model, startPosition, endPosition);
18-
var gist = GenerateGist(objectInfos, tree, startPosition, endPosition);
19-
return gist;
17+
var augmentedSelection = AugmentSnippet(objectInfos, tree, startPosition, endPosition);
18+
return augmentedSelection;
2019
}
2120

2221
/// <summary>
@@ -26,7 +25,7 @@ public static string GetGistFromSnippet(int startPosition, int endPosition, stri
2625
/// </summary>
2726
/// <param name="snippet">Snippet of code to analyze</param>
2827
/// <returns>Strign representation of the gist</returns>
29-
public static string GenerateGist(IEnumerable<ObjectInformation> objectInfos, SyntaxTree snippet, int startPosition, int endPosition)
28+
public static string AugmentSnippet(IEnumerable<ObjectInformation> objectInfos, SyntaxTree snippet, int startPosition, int endPosition)
3029
{
3130
var usingStatements = SyntaxBuilder.GetUsingStatements(objectInfos);
3231
var declarations = SyntaxBuilder.GetDeclarations(objectInfos);
@@ -43,10 +42,6 @@ public static string GenerateGist(IEnumerable<ObjectInformation> objectInfos, Sy
4342
/// <returns>List whose key is the position and value is the name of a declared variable</returns>
4443
public static IEnumerable<ObjectInformation> FindDeclarations(SyntaxTree syntax, SemanticModel model, int startPosition, int endPosition)
4544
{
46-
// use a walker to visit all declarations
47-
// use a semantic model to discover what actually are these declarations (what do they depend on)
48-
// TODO: get compilation of a document
49-
5045
var walker = new DiscoveryWalker(startPosition, endPosition, model);
5146
walker.Visit(syntax.GetRoot());
5247
return walker.DefinedOutside;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{E69B2ECE-7A34-4A9D-8FA9-7DA36FD0B914}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>CodeConnect.Gistify.Engine</RootNamespace>
11+
<AssemblyName>CodeConnect.Gistify.Engine</AssemblyName>
12+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="Microsoft.CodeAnalysis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
35+
<HintPath>..\packages\Microsoft.CodeAnalysis.Common.1.0.0\lib\net45\Microsoft.CodeAnalysis.dll</HintPath>
36+
<Private>True</Private>
37+
</Reference>
38+
<Reference Include="Microsoft.CodeAnalysis.CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
39+
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.1.0.0\lib\net45\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
40+
<Private>True</Private>
41+
</Reference>
42+
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
43+
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.0.0\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll</HintPath>
44+
<Private>True</Private>
45+
</Reference>
46+
<Reference Include="Microsoft.CodeAnalysis.Workspaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
47+
<HintPath>..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll</HintPath>
48+
<Private>True</Private>
49+
</Reference>
50+
<Reference Include="Microsoft.CodeAnalysis.Workspaces.Desktop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
51+
<HintPath>..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll</HintPath>
52+
<Private>True</Private>
53+
</Reference>
54+
<Reference Include="System" />
55+
<Reference Include="System.Collections.Immutable, Version=1.1.36.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
56+
<HintPath>..\packages\System.Collections.Immutable.1.1.36\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
57+
<Private>True</Private>
58+
</Reference>
59+
<Reference Include="System.Composition.AttributedModel, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
60+
<HintPath>..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll</HintPath>
61+
<Private>True</Private>
62+
</Reference>
63+
<Reference Include="System.Composition.Convention, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
64+
<HintPath>..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll</HintPath>
65+
<Private>True</Private>
66+
</Reference>
67+
<Reference Include="System.Composition.Hosting, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
68+
<HintPath>..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll</HintPath>
69+
<Private>True</Private>
70+
</Reference>
71+
<Reference Include="System.Composition.Runtime, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
72+
<HintPath>..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll</HintPath>
73+
<Private>True</Private>
74+
</Reference>
75+
<Reference Include="System.Composition.TypedParts, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
76+
<HintPath>..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll</HintPath>
77+
<Private>True</Private>
78+
</Reference>
79+
<Reference Include="System.Core" />
80+
<Reference Include="System.Reflection.Metadata, Version=1.0.21.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
81+
<HintPath>..\packages\System.Reflection.Metadata.1.0.21\lib\portable-net45+win8\System.Reflection.Metadata.dll</HintPath>
82+
<Private>True</Private>
83+
</Reference>
84+
<Reference Include="System.Xml.Linq" />
85+
<Reference Include="System.Data.DataSetExtensions" />
86+
<Reference Include="Microsoft.CSharp" />
87+
<Reference Include="System.Data" />
88+
<Reference Include="System.Net.Http" />
89+
<Reference Include="System.Xml" />
90+
</ItemGroup>
91+
<ItemGroup>
92+
<Compile Include="CodeAnalyzer.cs" />
93+
<Compile Include="DiscoveryWalker.cs" />
94+
<Compile Include="ObjectInformation.cs" />
95+
<Compile Include="Properties\AssemblyInfo.cs" />
96+
<Compile Include="SyntaxBuilder.cs" />
97+
</ItemGroup>
98+
<ItemGroup>
99+
<None Include="app.config" />
100+
<None Include="packages.config" />
101+
</ItemGroup>
102+
<ItemGroup>
103+
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.0.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
104+
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.0.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
105+
</ItemGroup>
106+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
107+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
108+
Other similar extension points exist, see Microsoft.Common.targets.
109+
<Target Name="BeforeBuild">
110+
</Target>
111+
<Target Name="AfterBuild">
112+
</Target>
113+
-->
114+
</Project>

CodeConnect.Gistify.Extension/CodeAnalysis/DiscoveryWalker.cs CodeConnect.Gistify.Engine/DiscoveryWalker.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Threading.Tasks;
88
using Microsoft.CodeAnalysis.CSharp.Syntax;
99

10-
namespace CodeConnect.Gistify.Extension.CodeAnalysis
10+
namespace CodeConnect.Gistify.Engine
1111
{
1212
public class DiscoveryWalker : CSharpSyntaxWalker
1313
{

CodeConnect.Gistify.Extension/CodeAnalysis/ObjectInformation.cs CodeConnect.Gistify.Engine/ObjectInformation.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Threading.Tasks;
66
using Microsoft.CodeAnalysis;
77

8-
namespace CodeConnect.Gistify.Extension.CodeAnalysis
8+
namespace CodeConnect.Gistify.Engine
99
{
1010
public struct ObjectInformation
1111
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("CodeConnect.Gistify.Engine")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("CodeConnect.Gistify.Engine")]
13+
[assembly: AssemblyCopyright("Copyright © 2015")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("e69b2ece-7a34-4a9d-8fa9-7da36fd0b914")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

CodeConnect.Gistify.Extension/CodeAnalysis/SyntaxBuilder.cs CodeConnect.Gistify.Engine/SyntaxBuilder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Text;
77
using System.Linq;
88

9-
namespace CodeConnect.Gistify.Extension.CodeAnalysis
9+
namespace CodeConnect.Gistify.Engine
1010
{
1111
public class SyntaxBuilder
1212
{

CodeConnect.Gistify.Engine/app.config

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<runtime>
4+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5+
<dependentAssembly>
6+
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
7+
<bindingRedirect oldVersion="0.0.0.0-1.1.37.0" newVersion="1.1.37.0" />
8+
</dependentAssembly>
9+
</assemblyBinding>
10+
</runtime>
11+
</configuration>
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.CodeAnalysis.Analyzers" version="1.0.0" targetFramework="net46" />
4+
<package id="Microsoft.CodeAnalysis.Common" version="1.0.0" targetFramework="net46" />
5+
<package id="Microsoft.CodeAnalysis.CSharp" version="1.0.0" targetFramework="net46" />
6+
<package id="Microsoft.CodeAnalysis.CSharp.Workspaces" version="1.0.0" targetFramework="net46" />
7+
<package id="Microsoft.CodeAnalysis.Workspaces.Common" version="1.0.0" targetFramework="net46" />
8+
<package id="Microsoft.Composition" version="1.0.27" targetFramework="net46" />
9+
<package id="System.Collections.Immutable" version="1.1.36" targetFramework="net46" />
10+
<package id="System.Reflection.Metadata" version="1.0.21" targetFramework="net46" />
11+
</packages>

CodeConnect.Gistify.Extension/CodeConnect.Gistify.Extension.csproj

+12-10
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,17 @@
5353
<WarningLevel>4</WarningLevel>
5454
</PropertyGroup>
5555
<ItemGroup>
56-
<Compile Include="CodeAnalysis\CodeAnalyzer.cs" />
57-
<Compile Include="CodeAnalysis\DiscoveryWalker.cs" />
58-
<Compile Include="CodeAnalysis\ObjectInformation.cs" />
59-
<Compile Include="CodeAnalysis\SyntaxBuilder.cs" />
60-
<Compile Include="CodeAnalysis\VSIntegration.cs" />
6156
<Compile Include="GistifyCommand.cs" />
6257
<Compile Include="GistifyCommandPackage.cs" />
63-
<Compile Include="GistifyEngine.cs" />
6458
<Compile Include="Properties\AssemblyInfo.cs" />
6559
<Compile Include="SolutionManager.cs" />
6660
<Compile Include="StatusBar.cs" />
6761
<Compile Include="TextManagerExtensions.cs" />
6862
<Compile Include="ThirdParties\GitHubConnection.cs" />
63+
<Compile Include="VSIntegration.cs" />
6964
</ItemGroup>
7065
<ItemGroup>
66+
<None Include="app.config" />
7167
<None Include="packages.config" />
7268
<None Include="source.extension.vsixmanifest">
7369
<SubType>Designer</SubType>
@@ -213,16 +209,16 @@
213209
<HintPath>..\packages\Microsoft.VisualStudio.Validation.14.0.50702\lib\net45\Microsoft.VisualStudio.Validation.dll</HintPath>
214210
<Private>True</Private>
215211
</Reference>
216-
<Reference Include="Octokit, Version=0.14.0.0, Culture=neutral, processorArchitecture=MSIL">
217-
<HintPath>..\packages\Octokit.0.14.0\lib\net45\Octokit.dll</HintPath>
212+
<Reference Include="Octokit, Version=0.16.0.0, Culture=neutral, processorArchitecture=MSIL">
213+
<HintPath>..\packages\Octokit.0.16.0\lib\net45\Octokit.dll</HintPath>
218214
<Private>True</Private>
219215
</Reference>
220216
<Reference Include="stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
221217
<EmbedInteropTypes>False</EmbedInteropTypes>
222218
</Reference>
223219
<Reference Include="System" />
224-
<Reference Include="System.Collections.Immutable, Version=1.1.36.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
225-
<HintPath>..\packages\System.Collections.Immutable.1.1.36\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
220+
<Reference Include="System.Collections.Immutable, Version=1.1.37.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
221+
<HintPath>..\packages\System.Collections.Immutable.1.1.37\lib\dotnet\System.Collections.Immutable.dll</HintPath>
226222
<Private>True</Private>
227223
</Reference>
228224
<Reference Include="System.Composition.AttributedModel, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
@@ -266,6 +262,12 @@
266262
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.0.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
267263
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.0.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
268264
</ItemGroup>
265+
<ItemGroup>
266+
<ProjectReference Include="..\CodeConnect.Gistify.Engine\CodeConnect.Gistify.Engine.csproj">
267+
<Project>{e69b2ece-7a34-4a9d-8fa9-7da36fd0b914}</Project>
268+
<Name>CodeConnect.Gistify.Engine</Name>
269+
</ProjectReference>
270+
</ItemGroup>
269271
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
270272
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
271273
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

CodeConnect.Gistify.Extension/GistifyCommand.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
using Microsoft.VisualStudio.Shell;
1111
using Microsoft.VisualStudio.Shell.Interop;
1212
using Microsoft.VisualStudio.TextManager.Interop;
13+
using CodeConnect.Gistify.Extension.ThirdParties;
14+
using CodeConnect.Gistify.Engine;
1315

1416
namespace CodeConnect.Gistify.Extension
1517
{
@@ -108,8 +110,9 @@ private void MenuItemCallback(object sender, EventArgs e)
108110
StatusBar.ShowStatus($"To create a gist, select a snippet of C# code first.");
109111
return;
110112
}
111-
var target = GistifyEngine.PrepareGist(filePath, startPosition, endPosition);
112-
GistifyEngine.GoToGist(target);
113+
var document = VSIntegration.GetDocument(filePath);
114+
var augmentedSnippet = CodeAnalyzer.AugmentSelection(document, startPosition, endPosition);
115+
GitHubIntegration.HandleAugmentedSnippet(augmentedSnippet);
113116
}
114117
else
115118
{

CodeConnect.Gistify.Extension/GistifyEngine.cs

-55
This file was deleted.

0 commit comments

Comments
 (0)