From 6473beaeed3b98721bd5419cd5ae75ed0e72e3dc Mon Sep 17 00:00:00 2001 From: Tareq Imbasher Date: Sun, 10 Dec 2023 16:49:43 +0300 Subject: [PATCH 1/4] Fixes not auto-adding Using statement in some cases --- .../src/core/@plugins/omnisharp/utils/text-change-util.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Apps/NetPad.Apps.App/App/src/core/@plugins/omnisharp/utils/text-change-util.ts b/src/Apps/NetPad.Apps.App/App/src/core/@plugins/omnisharp/utils/text-change-util.ts index 78cb55fb..d076771c 100644 --- a/src/Apps/NetPad.Apps.App/App/src/core/@plugins/omnisharp/utils/text-change-util.ts +++ b/src/Apps/NetPad.Apps.App/App/src/core/@plugins/omnisharp/utils/text-change-util.ts @@ -84,8 +84,10 @@ export class TextChangeUtil { } private static getNamespacesFromUsings(textChange: LinePositionSpanTextChange): string[] { - return textChange.newText?.split("\n") - .filter(l => !!l && l.trim()) + return textChange.newText + ?.split("\n") + .map(l => l?.trim()) // to remove empty parts + .filter(l => !!l) .map(l => Util.trimWord(l, "using ")) .map(l => Util.trimEnd(l, ";")) .map(l => l.trim()) From 11edeb473cb858179224d6daabd40685cfaefa4b Mon Sep 17 00:00:00 2001 From: Tareq Imbasher Date: Sun, 10 Dec 2023 16:50:38 +0300 Subject: [PATCH 2/4] Fixes language features not updating when a namespace is added in some cases --- .../Services/AppOmniSharpServer.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Plugins/NetPad.Plugins.OmniSharp/Services/AppOmniSharpServer.cs b/src/Plugins/NetPad.Plugins.OmniSharp/Services/AppOmniSharpServer.cs index cf7f9359..d0a2cc8a 100644 --- a/src/Plugins/NetPad.Plugins.OmniSharp/Services/AppOmniSharpServer.cs +++ b/src/Plugins/NetPad.Plugins.OmniSharp/Services/AppOmniSharpServer.cs @@ -277,10 +277,7 @@ private void InitializeEventHandlers() Subscribe(async ev => { if (ev.Script.Id != _environment.Script.Id) return; - - var script = _environment.Script; - var parsingResult = _codeParser.Parse(script.Code, script.Config.Kind, script.Config.Namespaces); - await UpdateOmniSharpCodeBufferWithBootstrapperProgramAsync(parsingResult); + await UpdateOmniSharpCodeBufferAsync(); }); Subscribe(async ev => @@ -385,8 +382,6 @@ private async Task UpdateOmniSharpCodeBufferWithDataConnectionAsync(DataConnecti // Needed to trigger diagnostics and semantic highlighting for script file await Task.Delay(1000); await UpdateOmniSharpCodeBufferAsync(); - - await _eventBus.PublishAsync(new OmniSharpAsyncBufferUpdateCompletedEvent(_environment.Script.Id)); } private async Task UpdateOmniSharpCodeBufferWithDataConnectionProgramAsync(Task? sourceCodeTask) @@ -438,5 +433,7 @@ await OmniSharpServer.SendAsync(new UpdateBufferRequest { semaphore.Release(); } + + await _eventBus.PublishAsync(new OmniSharpAsyncBufferUpdateCompletedEvent(_environment.Script.Id)); } } From 068f327478a7883ad625a3bb7a3979e911426549 Mon Sep 17 00:00:00 2001 From: Tareq Imbasher Date: Sun, 10 Dec 2023 17:01:42 +0300 Subject: [PATCH 3/4] Rename IKeyValueDataStore to ITrivialDataStore --- src/Apps/NetPad.Apps.App/Startup.cs | 2 +- src/Core/NetPad.Domain/Data/IKeyValueDataStore.cs | 11 ----------- src/Core/NetPad.Domain/Data/ITrivialDataStore.cs | 12 ++++++++++++ .../UiInterop/ElectronWindowService.cs | 10 +++++----- ...lueDataStore.cs => FileSystemTrivialDataStore.cs} | 2 +- 5 files changed, 19 insertions(+), 18 deletions(-) delete mode 100644 src/Core/NetPad.Domain/Data/IKeyValueDataStore.cs create mode 100644 src/Core/NetPad.Domain/Data/ITrivialDataStore.cs rename src/Infrastructure/NetPad.Infrastructure/{FileSystemKeyValueDataStore.cs => FileSystemTrivialDataStore.cs} (97%) diff --git a/src/Apps/NetPad.Apps.App/Startup.cs b/src/Apps/NetPad.Apps.App/Startup.cs index 61b6c449..c282ef55 100644 --- a/src/Apps/NetPad.Apps.App/Startup.cs +++ b/src/Apps/NetPad.Apps.App/Startup.cs @@ -78,7 +78,7 @@ public void ConfigureServices(IServiceCollection services) services.AddTransient(); services.AddTransient(); services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); // Scripts services.AddTransient(); diff --git a/src/Core/NetPad.Domain/Data/IKeyValueDataStore.cs b/src/Core/NetPad.Domain/Data/IKeyValueDataStore.cs deleted file mode 100644 index a8dd6d5f..00000000 --- a/src/Core/NetPad.Domain/Data/IKeyValueDataStore.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace NetPad.Data; - -/// -/// Represents a key-value data store. -/// -public interface IKeyValueDataStore -{ - TValue? Get(string key) where TValue : class; - void Set(string key, TValue value); - bool Contains(string key); -} diff --git a/src/Core/NetPad.Domain/Data/ITrivialDataStore.cs b/src/Core/NetPad.Domain/Data/ITrivialDataStore.cs new file mode 100644 index 00000000..1a559a09 --- /dev/null +++ b/src/Core/NetPad.Domain/Data/ITrivialDataStore.cs @@ -0,0 +1,12 @@ +namespace NetPad.Data; + +/// +/// Represents a key-value data store that stores trivial data. Trivial data is data +/// that is not essential to the functionality of the application or the user experience. +/// +public interface ITrivialDataStore +{ + TValue? Get(string key) where TValue : class; + void Set(string key, TValue value); + bool Contains(string key); +} diff --git a/src/Infrastructure/NetPad.Electron/UiInterop/ElectronWindowService.cs b/src/Infrastructure/NetPad.Electron/UiInterop/ElectronWindowService.cs index 72ea5860..2f08a86d 100644 --- a/src/Infrastructure/NetPad.Electron/UiInterop/ElectronWindowService.cs +++ b/src/Infrastructure/NetPad.Electron/UiInterop/ElectronWindowService.cs @@ -11,14 +11,14 @@ namespace NetPad.Electron.UiInterop; public class ElectronWindowService : IUiWindowService { private readonly WindowManager _windowManager; - private readonly IKeyValueDataStore _keyValueDataStore; + private readonly ITrivialDataStore _trivialDataStore; private readonly Settings _settings; private readonly ILogger _logger; - public ElectronWindowService(WindowManager windowManager, IKeyValueDataStore keyValueDataStore, Settings settings, ILogger logger) + public ElectronWindowService(WindowManager windowManager, ITrivialDataStore trivialDataStore, Settings settings, ILogger logger) { _windowManager = windowManager; - _keyValueDataStore = keyValueDataStore; + _trivialDataStore = trivialDataStore; _settings = settings; _logger = logger; } @@ -44,7 +44,7 @@ private async Task RestoreMainWindowPositionAsync(BrowserWindow window) { try { - var savedBounds = _keyValueDataStore.Get("main-window.bounds"); + var savedBounds = _trivialDataStore.Get("main-window.bounds"); if (savedBounds != null) { window.SetBounds(savedBounds); @@ -67,7 +67,7 @@ private async Task RestoreMainWindowPositionAsync(BrowserWindow window) window.OnClose += async () => { - _keyValueDataStore.Set("main-window.bounds", await window.GetBoundsAsync()); + _trivialDataStore.Set("main-window.bounds", await window.GetBoundsAsync()); }; } diff --git a/src/Infrastructure/NetPad.Infrastructure/FileSystemKeyValueDataStore.cs b/src/Infrastructure/NetPad.Infrastructure/FileSystemTrivialDataStore.cs similarity index 97% rename from src/Infrastructure/NetPad.Infrastructure/FileSystemKeyValueDataStore.cs rename to src/Infrastructure/NetPad.Infrastructure/FileSystemTrivialDataStore.cs index 43d7fdf7..096623ad 100644 --- a/src/Infrastructure/NetPad.Infrastructure/FileSystemKeyValueDataStore.cs +++ b/src/Infrastructure/NetPad.Infrastructure/FileSystemTrivialDataStore.cs @@ -8,7 +8,7 @@ namespace NetPad; -public class FileSystemKeyValueDataStore : IKeyValueDataStore +public class FileSystemTrivialDataStore : ITrivialDataStore { private static readonly FilePath _storeFilePath = AppDataProvider.AppDataDirectoryPath.CombineFilePath("key-values.txt"); private static readonly object _fileLock = new(); From 4f8f200b715e084b385a79fa7c9cdfcada8b46a6 Mon Sep 17 00:00:00 2001 From: Tareq Imbasher Date: Sun, 10 Dec 2023 17:10:27 +0300 Subject: [PATCH 4/4] Session will now remember the last active script across between app lifetimes --- .../NetPad.Application/Sessions/Session.cs | 25 +++++++++++++++---- .../NetPad.Tests/Helpers/SessionTestHelper.cs | 2 ++ .../Services/NullTrivialDataStore.cs | 20 +++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 src/Tests/NetPad.Tests/Services/NullTrivialDataStore.cs diff --git a/src/Core/NetPad.Application/Sessions/Session.cs b/src/Core/NetPad.Application/Sessions/Session.cs index 6475ce2e..6ff5c181 100644 --- a/src/Core/NetPad.Application/Sessions/Session.cs +++ b/src/Core/NetPad.Application/Sessions/Session.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using NetPad.Data; using NetPad.Events; using NetPad.Exceptions; using NetPad.Scripts; @@ -7,7 +8,10 @@ namespace NetPad.Sessions; public class Session : ISession { + private const string CurrentActiveSaveKey = "session.active"; + private readonly IScriptEnvironmentFactory _scriptEnvironmentFactory; + private readonly ITrivialDataStore _trivialDataStore; private readonly IEventBus _eventBus; private readonly ILogger _logger; private readonly List _environments; @@ -15,10 +19,12 @@ public class Session : ISession public Session( IScriptEnvironmentFactory scriptEnvironmentFactory, + ITrivialDataStore trivialDataStore, IEventBus eventBus, ILogger logger) { _scriptEnvironmentFactory = scriptEnvironmentFactory; + _trivialDataStore = trivialDataStore; _eventBus = eventBus; _logger = logger; _environments = new List(); @@ -53,17 +59,21 @@ public async Task OpenAsync(Script script, bool activate = true) public async Task OpenAsync(IEnumerable