diff --git a/src/Stratis.VS.StratisEVM/SolidityCompiler.cs b/src/Stratis.VS.StratisEVM/SolidityCompiler.cs index 7394272..a7cc00f 100644 --- a/src/Stratis.VS.StratisEVM/SolidityCompiler.cs +++ b/src/Stratis.VS.StratisEVM/SolidityCompiler.cs @@ -15,6 +15,7 @@ public class SolidityCompiler : Runtime public static async Task CompileFileAsync(string file) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); + VSUtil.ShowLogOutputWindowPane(ServiceProvider.GlobalProvider, "Solidity Compiler"); ProcessStartInfo info = new ProcessStartInfo(); info.FileName = "cmd.exe"; info.Arguments = "/c solc " + file + " --bin"; @@ -22,38 +23,34 @@ public static async Task CompileFileAsync(string file) info.RedirectStandardError = true; info.UseShellExecute = false; info.CreateNoWindow = true; - var process = new Process(); - process.StartInfo = info; - process.EnableRaisingEvents = true; - process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => + using (var process = new Process()) { - if (e.Data != null && e.Data.Length > 0) + process.StartInfo = info; + process.EnableRaisingEvents = true; + try { - VSUtil.LogInfo("Solidity Compiler", e.Data.Trim()); + if (!process.Start()) + { + VSUtil.LogError("Could not start Solidity Compiler process {process}.", info.FileName + " " + info.Arguments); + return; + } + var stdout = await process.StandardOutput.ReadToEndAsync(); + var stderr = await process.StandardError.ReadToEndAsync(); + if (stdout != null && stdout.Length > 0) + { + VSUtil.LogInfo("Solidity Compiler", stdout); + } + if (stderr != null && stderr.Length > 0) + { + VSUtil.LogError("Solidity Compiler", stderr); + } + await process.WaitForExitAsync(); } - }; - process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => - { - if (e.Data != null && e.Data.Length > 0) - { - VSUtil.LogError("Solidity Compiler", e.Data.Trim()); - } - }; - try - { - if (!process.Start()) + catch (Exception ex) { - VSUtil.LogError("Could not start Solidity Compiler process {process}.", info.FileName + " " + info.Arguments); + VSUtil.LogError("Solidity Compiler", ex); return; } - process.BeginOutputReadLine(); - process.BeginErrorReadLine(); - await process.WaitForExitAsync(); - } - catch (Exception ex) - { - VSUtil.LogError("Solidity Compiler", ex); - return; } } } diff --git a/src/Stratis.VS.StratisEVM/SolidityFileContextActionsProviderFactory.cs b/src/Stratis.VS.StratisEVM/SolidityFileContextActionsProviderFactory.cs index 1407746..b89b0e0 100644 --- a/src/Stratis.VS.StratisEVM/SolidityFileContextActionsProviderFactory.cs +++ b/src/Stratis.VS.StratisEVM/SolidityFileContextActionsProviderFactory.cs @@ -52,7 +52,7 @@ public Task> GetActionsAsync(string filePath, return Task.FromResult>(new IFileContextAction[] { // Word count command: - new MyContextAction( + new SolidityFileContextAction( fileContext, new Tuple(ProviderCommandGroup, StratisEVMPackageIds.Cmd1Id), "Compile Solidity File" + fileContext.DisplayName, @@ -60,18 +60,6 @@ public Task> GetActionsAsync(string filePath, { await SolidityCompiler.CompileFileAsync(filePath); }), - - // Toggle word count type command: - /* - new MyContextAction( - fileContext, - new Tuple(ProviderCommandGroup, StratisEVMPackageIds.Cmd2Id), - "My Action" + fileContext.DisplayName, - async (fCtxt, progress, ct) => - { - await OutputWindowPaneAsync("command 2"); - }), - */ }); } @@ -100,11 +88,11 @@ internal static async Task OutputWindowPaneAsync(string message) outputPane?.OutputStringThreadSafe(message); } - internal class MyContextAction : IFileContextAction, IVsCommandItem + internal class SolidityFileContextAction : IFileContextAction, IVsCommandItem { private Func, CancellationToken, Task> executeAction; - internal MyContextAction( + internal SolidityFileContextAction( FileContext fileContext, Tuple command, string displayName, diff --git a/src/Stratis.VS.StratisEVM/SolidityLanguageClient.cs b/src/Stratis.VS.StratisEVM/SolidityLanguageClient.cs index 1a07f58..92ec70d 100644 --- a/src/Stratis.VS.StratisEVM/SolidityLanguageClient.cs +++ b/src/Stratis.VS.StratisEVM/SolidityLanguageClient.cs @@ -100,8 +100,7 @@ protected bool StartLanguageServerProcess() info.RedirectStandardInput = true; info.RedirectStandardOutput = true; info.UseShellExecute = false; - info.CreateNoWindow = false; - + info.CreateNoWindow = true; var process = new System.Diagnostics.Process(); process.StartInfo = info; process.EnableRaisingEvents = true; diff --git a/src/Stratis.VS.StratisEVM/StratisEVMPackage.cs b/src/Stratis.VS.StratisEVM/StratisEVMPackage.cs index 337283e..fd556e4 100644 --- a/src/Stratis.VS.StratisEVM/StratisEVMPackage.cs +++ b/src/Stratis.VS.StratisEVM/StratisEVMPackage.cs @@ -88,15 +88,17 @@ public void OnAfterLoadAllDeferredProjects() protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress progress) { await base.InitializeAsync(cancellationToken, progress); - Runtime.Info("StratisEVM package initialized."); await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); - - VSUtil.InitializeVSServices(this); + if (VSUtil.InitializeVSServices(ServiceProvider.GlobalProvider)) + { + Runtime.Info("StratisEVM package initialized."); + } + else + { + Runtime.Error("Could not initialize StratisEVM package VS services."); + } // When initialized asynchronously, the current thread may be a background thread at this point. // Do any initialization that requires the UI thread after switching to the UI thread. - VSUtil.LogInfo("Stratis EVM", "log init"); - - } #endregion diff --git a/src/Stratis.VS.StratisEVM/VSUtil.cs b/src/Stratis.VS.StratisEVM/VSUtil.cs index a387913..5613acd 100644 --- a/src/Stratis.VS.StratisEVM/VSUtil.cs +++ b/src/Stratis.VS.StratisEVM/VSUtil.cs @@ -123,6 +123,30 @@ public static bool InitializeVSServices(IServiceProvider provider) return VSServicesInitialized; } + public static void ShowLogOutputWindowPane(IServiceProvider provider, string pane) + { + ThreadHelper.ThrowIfNotOnUIThread(); + IVsWindowFrame windowFrame; + if (uiShell != null) + { + uint flags = (uint)__VSFINDTOOLWIN.FTW_fForceCreate; + uiShell.FindToolWindow(flags, VSConstants.StandardToolWindows.Output, out windowFrame); + windowFrame.Show(); + var p = GetLogOutputPane(pane); + if (p != null) + { + p.Activate(); + } + else + { + Error("Could not get a reference to the VsUIShell."); + } + } + else + { + Error("Could not get a reference to the VsUIShell."); + } + } public static bool VSServicesInitialized = false; } } diff --git a/tests/solidity/test2/BasicContract.sol b/tests/solidity/test2/BasicContract.sol index 2ef5a1d..9c084ea 100644 --- a/tests/solidity/test2/BasicContract.sol +++ b/tests/solidity/test2/BasicContract.sol @@ -18,4 +18,8 @@ contract BasicContract { function foo(uint s) private pure { s = 4; } + + function foo2(string s) { + + } }