Skip to content

Commit

Permalink
Merge pull request #2 from roberthusak/feature/v2
Browse files Browse the repository at this point in the history
Overhaul and integrate into Visual Studio
  • Loading branch information
roberthusak authored Dec 9, 2024
2 parents 006b2e3 + b17f6db commit 8e2bb52
Show file tree
Hide file tree
Showing 219 changed files with 8,135 additions and 6,160 deletions.
10 changes: 10 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>
<PropertyGroup>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../../slicito.snk</AssemblyOriginatorKeyFile>
<AssemblyVersion>0.2.0.0</AssemblyVersion>
</PropertyGroup>
</Project>
32 changes: 32 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<RoslynVersion>4.11.0</RoslynVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AutomaticGraphLayout.WpfGraphControl" Version="1.1.12" />
<PackageVersion Include="Community.VisualStudio.VSCT" Version="16.0.29.6" />
<PackageVersion Include="Community.VisualStudio.Toolkit.17" Version="17.0.507" />
<PackageVersion Include="Dotnet.Script.Core" Version="1.6.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="FluentAssertions.Analyzers" Version="0.31.0" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="AutomaticGraphLayout" Version="1.1.12" />
<PackageVersion Include="AutomaticGraphLayout.Drawing" Version="1.1.12" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Html.Abstractions" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageVersion Include="Microsoft.Build.Locator" Version="1.7.8" />
<PackageVersion Include="Microsoft.CodeAnalysis" Version="$(RoslynVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="$(RoslynVersion)" />
<PackageVersion Include="Microsoft.DotNet.Interactive" Version="1.0.0-beta.22606.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.VisualStudio.LanguageServices" Version="$(RoslynVersion)" />
<PackageVersion Include="Microsoft.VSSDK.BuildTools" Version="17.9.3168" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageVersion Include="MSTest.TestFramework" Version="3.1.1" />
<PackageVersion Include="StrongNamer" Version="0.2.5" />
<PackageVersion Include="System.Drawing.Common" Version="6.0.0" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
</ItemGroup>
</Project>
76 changes: 53 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,75 @@
_Work in progress._ The [paper from the doctoral consortium at ICSOFT 2022](docs/icsoft_dc_2022_paper.pdf) explains the motivation behind the project.

Slicito
=======
Slicito - Visual Studio Extension for Analysis of C# Code
=========================================================

**Slice your code into edible pieces**

Understanding a complex codebase is time-consuming and difficult.
Slicito aims to be a toolbox which you can use to make this task much faster and simpler.
Currently, it serves only for simple visualisations of project structure, but more features are on their way.
Slicito aims to be a toolbox of program analysis and visualization techniques which you can use to make this task much faster and simpler.
It's currently in the research prototype stage, so only a subset of C# features is supported.

> **Note:**
> The tool was overhauled since its [publication at ICPC 2023](https://ieeexplore.ieee.org/document/10174103) where we presented it as an extension to computational notebooks in VS Code (see the corresponding version at the [`v0.1.0` tag](https://github.com/roberthusak/slicito/tree/v0.1.0)).
> Although the support for computational notebooks and other IDEs can be added in the future, Slicito is now primarily a Visual Studio extension.
Sample usage
------------

Compile the solution:
**Requirements:**

```
dotnet build Slicito.sln
- Visual Studio 2022 (tested with the version 17.12.3)

**Steps:**

1. Download and install the latest VSIX file from the [releases page](https://github.com/roberthusak/slicito/releases) to your Visual Studio.

2. Clone or download this repository and open the sample solution `tests/inputs/AnalysisSamples/AnalysisSamples.sln` in Visual Studio.

3. In the main menu, select `Tools` > `Slicito` to open the Slicito tool window.
It should appear at the same panel as the Solution Explorer.

4. In the Slicito tool window, click the button *Open* located right from the label *Script*.
A new C# script file `slicito.csx` should be created in the solution directory with the content similar to:

```csharp
#r "c:\users\husak\appdata\local\microsoft\visualstudio\17.0_ae45ee82exp\extensions\robert husak\slicito\0.2\Slicito.Abstractions.dll"
#r "c:\users\husak\appdata\local\microsoft\visualstudio\17.0_ae45ee82exp\extensions\robert husak\slicito\0.2\Slicito.ProgramAnalysis.dll"
#r "c:\users\husak\appdata\local\microsoft\visualstudio\17.0_ae45ee82exp\extensions\robert husak\slicito\0.2\Slicito.Common.dll"
#r "c:\users\husak\appdata\local\microsoft\visualstudio\17.0_ae45ee82exp\extensions\robert husak\slicito\0.2\Slicito.DotNet.dll"

using Slicito.Common;
using Slicito.DotNet;
using Slicito.ProgramAnalysis;

using static Slicito.Common.Extensibility.ScriptContext;
```

Install the extension [Polyglot Notebooks](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.dotnet-interactive-vscode) to VS Code and open the notebook [`samples/notebooks/NamespaceHierarchy.ipynb`](samples/notebooks/NamespaceHierarchy.ipynb).
When you execute its first cell, an image similar to this should appear:
5. This is a central "plumbing" code which loads the Slicito libraries and provides the context for the script.
You can use the `SlicitoContext` property of the `ScriptContext` class to access the Slicito features via the fluent interface.
Insert the following code for creating a call graph starting with the method `Caller` and displaying it:

![Sample hierarchy of Slicito itself](docs/hierarchy_sample.svg)
```csharp
var slice = SlicitoContext.WholeSlice;

It shows the namespaces of Slicito itself, and allows you to navigate through its structure.
If you have an instance of Microsoft Visual Studio opened, the elements you click in the schema will be shown to you there.
Replace the reference to `Slicito.csproj` with your C# project to inspect the structure of your code.
You can also extract and visualize dependencies as shown in the second cell of the [sample notebook](samples/notebooks/NamespaceHierarchy.ipynb).
var method = await SlicitoContext.FindSingleMethodAsync(slice, "Caller");

Plans
-----
var callGraph = await SlicitoContext.CreateCallGraphBuilder(slice)
.AddCallerRoot(method)
.BuildAsync();

* Make turning code into graphs as straightforward as possible.
* Document all the provided abstraction and visualization techniques.
* Use advanced techniques from [AskTheCode](https://github.com/roberthusak/AskTheCode) to reason precisely about program behaviour.
return SlicitoContext.CreateCallGraphExplorer(callGraph);
```

Disclaimer
----------
6. Click the *Run* button in the Slicito tool window to execute the script.
The call graph should be displayed in a newly opened tool window.

Current plans
-------------

There has been no release of the tool yet.
Therefore, the public interface is currently under rapid development, and as such, it can change without warning.
- Add examples of using data-flow analysis and symbolic execution.
- Extend the set of supported C# features to handle real-life codebases.
- Evaluate on real program comprehension tasks in industry.

Contact me
----------
Expand Down
Loading

0 comments on commit 8e2bb52

Please sign in to comment.