Skip to content

Commit

Permalink
add CORE Gripper, and fix document edit bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Huajiang Wei committed Dec 11, 2023
1 parent be38f5c commit 7db4d8c
Show file tree
Hide file tree
Showing 45 changed files with 756 additions and 753 deletions.
5 changes: 0 additions & 5 deletions editor/src/RoslynPad.Common.UI/RoslynPad.Common.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
<PropertyGroup>
<RootNamespace>RoslynPad.UI</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>key.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<Optimize>false</Optimize>
</PropertyGroup>
<ItemGroup>
<None Remove="RoslynPad.Common.UI.csproj.DotSettings" />
Expand Down
17 changes: 7 additions & 10 deletions editor/src/RoslynPad.Common.UI/ViewModels/MainViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public MainViewModelBase(IServiceProvider serviceProvider, ITelemetryProvider te
NewDocumentCommand = commands.Create(CreateNewDocument);
OpenFileCommand = commands.CreateAsync(OpenFile);
CloseCurrentDocumentCommand = commands.CreateAsync(CloseCurrentDocument);
CloseDocumentCommand = commands.CreateAsync<OpenDocumentViewModel>(CloseDocument);
CloseDocumentCommand = commands.CreateAsync<IOpenDocumentViewModel>(CloseDocument);
ClearErrorCommand = commands.Create(() => _telemetryProvider.ClearLastError());
ReportProblemCommand = commands.Create(ReportProblem);
EditUserDocumentPathCommand = commands.Create(EditUserDocumentPath);
Expand Down Expand Up @@ -115,16 +115,17 @@ public async Task Initialize()
typeof(MainViewModelBase).Assembly);
protected virtual ImmutableArray<Type> TypeNamespaceImports => ImmutableArray.Create(typeof(Runtime.ObjectExtensions));


private async Task InitializeInternal()
{
RoslynHost = await Task.Run(() => new RoslynHost(CompositionAssemblies,
RoslynHostReferences.NamespaceDefault.With(typeNamespaceImports: TypeNamespaceImports),
disabledDiagnostics: ImmutableArray.Create("CS1701", "CS1702")))
.ConfigureAwait(true);

if(!OpenDocumentFromCommandLine())
await OpenAutoSavedDocuments().ConfigureAwait(true);

OpenDocumentFromCommandLine();
await OpenAutoSavedDocuments().ConfigureAwait(true);
/*
if (HasCachedUpdate())
{
HasUpdate = true;
Expand All @@ -133,10 +134,10 @@ private async Task InitializeInternal()
{
// ReSharper disable once UnusedVariable
var task = Task.Run(CheckForUpdates);
}
}*/
}

private bool OpenDocumentFromCommandLine()
private void OpenDocumentFromCommandLine()
{
string[] args = Environment.GetCommandLineArgs();

Expand All @@ -148,10 +149,8 @@ private bool OpenDocumentFromCommandLine()
{
var document = DocumentViewModel.FromPath(filePath);
OpenDocument(document);
return true;
}
}
return false;
}

private async Task OpenAutoSavedDocuments()
Expand Down Expand Up @@ -388,7 +387,6 @@ public async Task CloseDocument(IOpenDocumentViewModel document)
{
return;
}

var result = await document.Save(promptSave: true).ConfigureAwait(true);
if (result == SaveResult.Cancel)
{
Expand Down Expand Up @@ -764,7 +762,6 @@ private void OnDocumentFileChanged(DocumentFileChanged data)
{
case DocumentFileChangeType.Renamed:
Debug.Assert(data.NewPath != null);
if (data.NewPath == null) return;
current.ChangePath(data.NewPath);
// move it to the correct place
parent.InternalChildren.Remove(current);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public string ILText
}
public void Dispose()
{
if(_results!=null)
if (_results != null)
{
_results.Clear();
}
Expand Down Expand Up @@ -156,13 +156,8 @@ public OpenDocumentViewModel(IServiceProvider serviceProvider, MainViewModelBase
NuGet.RestoreCompleted += OnNuGetRestoreCompleted;

_dispatcher = appDispatcher;
List<ExecutionPlatform> platforms = new List<ExecutionPlatform>();
foreach (var f in serviceProvider.GetService<IPlatformsFactory>()
.GetExecutionPlatforms())
if (f.IsDesktop && f.Architecture == Architecture.X86)
platforms.Add(f);
AvailablePlatforms = platforms.ToImmutableArray();

AvailablePlatforms = serviceProvider.GetService<IPlatformsFactory>()
.GetExecutionPlatforms().ToImmutableArray();

OpenBuildPathCommand = commands.Create(() => OpenBuildPath());
SaveCommand = commands.CreateAsync(() => Save(promptSave: false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<RootNamespace>RoslynPad.Editor</RootNamespace>
<Version>$(EditorPackageVersion)</Version>
<Description>Provides a Roslyn-based code editor using AvalonEdit (WPF platform) with completion, diagnostics, and quick actions</Description>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>key.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
Expand All @@ -26,7 +24,7 @@
<ProjectReference Include="..\RoslynPad.Roslyn\RoslynPad.Roslyn.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AvalonEdit" Version="6.3.0.90" />
<PackageReference Include="AvalonEdit" Version="5.0.4" />
<PackageReference Include="System.Reactive.Linq" Version="4.1.2" />
</ItemGroup>
<ItemGroup>
Expand Down
41 changes: 4 additions & 37 deletions editor/src/RoslynPad.Hosting/AssemblyExecutionHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,46 +170,13 @@ private void InitializeBuildPath(bool stop)
private void CleanupBuildPath()
{
StopProcess();

foreach (var file in IOUtilities.EnumerateFiles(BuildPath))
{
IOUtilities.PerformIO(() => File.Delete(file));
}
}
public async Task ExecuteAsync2(string code, bool disaseemble, OptimizationLevel? optimizationLevel)
{
await new NoContextYieldAwaitable();
try
{
_running = true;

using var executeCts = new CancellationTokenSource();
var cancellationToken = executeCts.Token;

_assemblyPath = Path.Combine(BuildPath, $"RoslynPad-{Name}.dll");

//CopyDependencies();

var script = CreateScriptRunner(code, optimizationLevel, OutputKind.ConsoleApplication);
//var diagnostics = await script.SaveAssembly(_assemblyPath, cancellationToken).ConfigureAwait(false);
await script.RunAsync(cancellationToken);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
finally
{
_executeCts = null;
_running = false;

if (_initializeBuildPathAfterRun)
{
_initializeBuildPathAfterRun = false;
InitializeBuildPath(stop: false);
}
}
}
public async Task ExecuteAsync(string code, bool disassemble, OptimizationLevel? optimizationLevel)
{
await new NoContextYieldAwaitable();
Expand Down Expand Up @@ -238,7 +205,7 @@ public async Task ExecuteAsync(string code, bool disassemble, OptimizationLevel?

if (disassemble)
{
//Disassemble();
Disassemble();
}

_executeCts = executeCts;
Expand Down Expand Up @@ -328,7 +295,7 @@ private static bool CopyIfNewer(string source, string destination)
return false;
}

private ScriptRunner CreateScriptRunner(string code, OptimizationLevel? optimizationLevel, OutputKind outputKind= OutputKind.ConsoleApplication)
private ScriptRunner CreateScriptRunner(string code, OptimizationLevel? optimizationLevel)
{
Platform platform = Platform.Architecture == Architecture.X86
? Microsoft.CodeAnalysis.Platform.AnyCpu32BitPreferred
Expand All @@ -337,7 +304,7 @@ private ScriptRunner CreateScriptRunner(string code, OptimizationLevel? optimiza
return new ScriptRunner(code: null,
syntaxTrees: ImmutableList.Create(InitHostSyntax, ParseCode(code)),
_parseOptions,
outputKind,
OutputKind.ConsoleApplication,
platform,
_scriptOptions.MetadataReferences,
_scriptOptions.Imports,
Expand Down
1 change: 1 addition & 0 deletions editor/src/RoslynPad.Hosting/DotNetConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static XDocument CreateNetFxAppConfig(IList<string> references)
runtime.Add(element);
}
}

var startup = new XElement("startup", new XAttribute("useLegacyV2RuntimeActivationPolicy", "true"));
var config = new XElement("System.Windows.Forms.ApplicationConfigurationSection",
new XElement("add", new XAttribute("key", "DpiAwareness"), new XAttribute("value", "PerMonitorV2")),
Expand Down
2 changes: 0 additions & 2 deletions editor/src/RoslynPad.Hosting/RoslynPad.Hosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<OutputType>Library</OutputType>
<RootNamespace>RoslynPad.Hosting</RootNamespace>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>key.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\RoslynPad.Runtime\RoslynPad.Runtime.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
<Version>$(RoslynAssemblyVersion)</Version>
<PackageVersion>$(RoslynPackageVersion)</PackageVersion>
<Description>Provides platform-specific (WPF) implementations for UI elements required by the RoslynPad.Roslyn package.</Description>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>key.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
Expand Down
2 changes: 2 additions & 0 deletions editor/src/RoslynPad.Roslyn/AssemblyAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[assembly: InternalsVisibleTo("RoslynPad")]
[assembly: InternalsVisibleTo("RoslynPad.Common.UI")]
[assembly: InternalsVisibleTo("RoslynPad.Editor.Avalonia")]
[assembly: InternalsVisibleTo("RoslynPad.Editor.Windows")]
[assembly: InternalsVisibleTo("RoslynPad.Roslyn.Avalonia")]
[assembly: InternalsVisibleTo("RoslynPad.Roslyn.Windows")]
[assembly: InternalsVisibleTo("RoslynPad.Hosting")]
2 changes: 0 additions & 2 deletions editor/src/RoslynPad.Roslyn/RoslynPad.Roslyn.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
<Version>$(RoslynAssemblyVersion)</Version>
<PackageVersion>$(RoslynPackageVersion)</PackageVersion>
<Description>Exposes many Roslyn editor services that are currently internal. The version of this package corresponds to the Roslyn packages.</Description>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>key.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IgnoresAccessChecksToGenerator" Version="0.4.0" PrivateAssets="All" />
Expand Down
1 change: 1 addition & 0 deletions editor/src/RoslynPad.Roslyn/Scripting/ScriptRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ private static MethodInfo GetEntryPointRuntimeMethod(IMethodSymbol entryPoint, A
{
var entryPointTypeName = BuildQualifiedName(entryPoint.ContainingNamespace.MetadataName, entryPoint.ContainingType.MetadataName);
var entryPointMethodName = entryPoint.MetadataName;

var entryPointType = assembly.GetType(entryPointTypeName, throwOnError: true, ignoreCase: false);
return entryPointType.GetTypeInfo().GetDeclaredMethod(entryPointMethodName);
}
Expand Down
2 changes: 0 additions & 2 deletions editor/src/RoslynPad.Runtime/RoslynPad.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>key.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>

<!-- Do not add any references or packages to this assembly -->
Expand Down
1 change: 0 additions & 1 deletion editor/src/RoslynPad.Runtime/Utilities/IOUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public static IEnumerable<string> EnumerateDirectories(string path, string searc
var dir = new DirectoryInfo(enumerator.Current);
var att = dir.Attributes;
if (((int)att & (int)FileAttributes.Hidden) > 0) continue;
//if (dir.Name.StartsWith(".")) continue;
yield return enumerator.Current;
}
}
Expand Down
27 changes: 1 addition & 26 deletions editor/src/RoslynPad.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.34301.259
VisualStudioVersion = 16.0.28407.52
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RoslynPad", "RoslynPad\RoslynPad.csproj", "{2F7723C1-297B-416F-9A78-153156D319B9}"
EndProject
Expand All @@ -27,12 +27,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Hosting", "Hosting", "{E219
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Roslyn", "Roslyn", "{33A4C07C-3BBB-4BA5-8A4E-CC22883B8ED5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "STARLine", "STARLine", "{29CEF494-6CCD-404B-9EB4-AEBBBE424C8A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "STARLine", "..\..\src\STARLine\STARLine.csproj", "{B2BFEA5D-3909-4CA3-8F18-901E2A0D557A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfApp1", "WpfApp1\WpfApp1.csproj", "{E50DF474-F338-4384-814C-F500F673DB93}"
EndProject
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "CSharp4Venus", "CSharp4Venus\CSharp4Venus.wapproj", "{EB7B8287-0660-40A2-BCB0-1ACCF4F4DF29}"
EndProject
Global
Expand Down Expand Up @@ -212,26 +208,6 @@ Global
{B2BFEA5D-3909-4CA3-8F18-901E2A0D557A}.Release|x64.Build.0 = Release|Any CPU
{B2BFEA5D-3909-4CA3-8F18-901E2A0D557A}.Release|x86.ActiveCfg = Release|Any CPU
{B2BFEA5D-3909-4CA3-8F18-901E2A0D557A}.Release|x86.Build.0 = Release|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Debug|ARM.ActiveCfg = Debug|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Debug|ARM.Build.0 = Debug|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Debug|ARM64.Build.0 = Debug|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Debug|x64.ActiveCfg = Debug|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Debug|x64.Build.0 = Debug|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Debug|x86.ActiveCfg = Debug|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Debug|x86.Build.0 = Debug|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Release|Any CPU.Build.0 = Release|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Release|ARM.ActiveCfg = Release|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Release|ARM.Build.0 = Release|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Release|ARM64.ActiveCfg = Release|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Release|ARM64.Build.0 = Release|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Release|x64.ActiveCfg = Release|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Release|x64.Build.0 = Release|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Release|x86.ActiveCfg = Release|Any CPU
{E50DF474-F338-4384-814C-F500F673DB93}.Release|x86.Build.0 = Release|Any CPU
{EB7B8287-0660-40A2-BCB0-1ACCF4F4DF29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB7B8287-0660-40A2-BCB0-1ACCF4F4DF29}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB7B8287-0660-40A2-BCB0-1ACCF4F4DF29}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
Expand Down Expand Up @@ -274,7 +250,6 @@ Global
{47C8DFA4-E7E9-4E44-86C4-B906229A25E0} = {52BBDF63-C2F5-439C-AFD6-E7BAC5A868C8}
{075292F0-DBCD-4A01-9791-9637D396CCB8} = {33A4C07C-3BBB-4BA5-8A4E-CC22883B8ED5}
{7FB0604B-44CD-4DB1-99C5-E89EA6C20AEC} = {09BCD791-CCF8-48DB-98E4-6B18105D2DDB}
{B2BFEA5D-3909-4CA3-8F18-901E2A0D557A} = {29CEF494-6CCD-404B-9EB4-AEBBBE424C8A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6E595517-397C-4164-83BB-D80FC9B19D36}
Expand Down
4 changes: 3 additions & 1 deletion editor/src/RoslynPad/DocumentTreeView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:roslynPad="clr-namespace:RoslynPad"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance ui:MainViewModel}"
d:DesignHeight="300"
d:DesignWidth="300">
<FrameworkElement.Resources>

<Style x:Key="{x:Type ToolBar}" TargetType="{x:Type ToolBar}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
Expand Down Expand Up @@ -125,7 +127,7 @@
<controls:TreeListView Grid.Row="1"
ShowSeparator="False"
ItemContainerStyle="{StaticResource DocumentItemContainerStyle}"
ItemsSource="{Binding DocumentRoot.Children, Converter={StaticResource FilterCollectionViewConverter}, NotifyOnSourceUpdated=True}" />
ItemsSource="{Binding DocumentRoot.Children, Converter={StaticResource FilterCollectionViewConverter}}" />

<ToolBar Grid.Row="2" ToolBarTray.IsLocked="True"
Background="Transparent"
Expand Down
4 changes: 2 additions & 2 deletions editor/src/RoslynPad/DocumentTreeView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ private async void DocumentsContextMenu_Delete_Click(object sender, RoutedEventA
if (MessageBox.Show("Are you sure to delete this file?", "delete confirm", MessageBoxButton.OKCancel, MessageBoxImage.Question)
!= MessageBoxResult.OK)
return;
for(int i=0;i<_viewModel.OpenDocuments.Count;i++)
for (int i = 0; i < _viewModel.OpenDocuments.Count; i++)
{
var doc = _viewModel.OpenDocuments[i];
if (doc.Document!=null && doc.Document.Path == documentViewModel.Path)
if (doc.Document != null && doc.Document.Path == documentViewModel.Path)
{
await _viewModel.CloseDocument(doc);
break;
Expand Down
7 changes: 3 additions & 4 deletions editor/src/RoslynPad/DocumentView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
xmlns:controls="clr-namespace:RoslynPad.Controls"
xmlns:ui="clr-namespace:RoslynPad.UI;assembly=RoslynPad.Common.UI"
xmlns:editor="clr-namespace:RoslynPad.Editor;assembly=RoslynPad.Editor.Windows"
xmlns:local="clr-namespace:RoslynPad"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance ui:OpenDocumentViewModel}">
<UserControl.Resources>
Expand Down Expand Up @@ -43,7 +42,7 @@
<StatusBar DockPanel.Dock="Bottom" Background="Transparent" >
<StatusBar.ItemsPanel>
<ItemsPanelTemplate>
<DockPanel LastChildFill="False"/>
<DockPanel LastChildFill="False" />
</ItemsPanelTemplate>
</StatusBar.ItemsPanel>
<StatusBarItem>
Expand Down Expand Up @@ -238,14 +237,14 @@
ToolTip="Rename Symbol (F2)"
Command="{Binding RenameSymbolCommand, Mode=OneTime}" />
</ToolBar>
<editor:RoslynCodeEditor x:Name="Editor"
<editor:RoslynCodeEditor x:Name="Editor"
x:FieldModifier="private"
ContextActionsIcon="{StaticResource Bulb}"
IsBraceCompletionEnabled="{Binding MainViewModel.Settings.EnableBraceCompletion}"
FontFamily="Consolas"
Grid.Row="1"
Grid.Column="0"
Loaded="Editor_OnLoaded" TextChanged="EditorTextChanged" />
Loaded="Editor_OnLoaded" />
<GridSplitter Grid.Row="2"
Grid.Column="0"
Background="#ccc"
Expand Down
Loading

0 comments on commit 7db4d8c

Please sign in to comment.