From ef1f20bd23fc357e380ca6bcdd5081e5a6d6f887 Mon Sep 17 00:00:00 2001 From: Allister Beharry Date: Wed, 11 Dec 2024 19:40:57 -0400 Subject: [PATCH] Fix compile file menu action. Don't replace build system if running in release. vscode-solidity->Solidity. --- src/Stratis.VS.StratisEVM/SolidityCompiler.cs | 9 +++++---- .../SolidityLanguageClient.cs | 14 +++++++------- src/Stratis.VS.StratisEVM/StratisEVMPackage.cs | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/Stratis.VS.StratisEVM/SolidityCompiler.cs b/src/Stratis.VS.StratisEVM/SolidityCompiler.cs index a14ec0e..5136181 100644 --- a/src/Stratis.VS.StratisEVM/SolidityCompiler.cs +++ b/src/Stratis.VS.StratisEVM/SolidityCompiler.cs @@ -22,18 +22,19 @@ public static async Task CompileFileAsync(string file, string workspaceDir) VSUtil.ShowLogOutputWindowPane(ServiceProvider.GlobalProvider, "Solidity Compiler"); VSUtil.LogInfo("Solidity Compiler", string.Format("Compiling {0} in {1}...", file, workspaceDir)); await TaskScheduler.Default; - var binfiles = Directory.GetFiles(AssemblyLocation, "*.bin", SearchOption.TopDirectoryOnly); + var binfiles = Directory.GetFiles(workspaceDir, "*.bin", SearchOption.TopDirectoryOnly); foreach ( var binfile in binfiles ) { File.Delete(binfile); } var cmd = "cmd.exe"; - var args = "/c node " + Path.Combine("node_modules", "solc", "solc.js") + " --base-path=\"" + workspaceDir + "\"" + " \"" + file + "\" --bin"; + var solcpath = File.Exists(Path.Combine(workspaceDir, "node_modules", "solc", "solc.js")) ? Path.Combine(workspaceDir, "node_modules", "solc", "solc.js") : Path.Combine(AssemblyLocation, "node_modules", "solc", "solc.js"); + var args = "/c node " + solcpath + " --base-path=\"" + workspaceDir + "\"" + " \"" + file + "\" --bin"; if (Directory.Exists(Path.Combine(workspaceDir, "node_modules"))) { args += " --include-path=" + Path.Combine(workspaceDir, "node_modules"); } - var output = await RunCmdAsync(cmd, args, AssemblyLocation); + var output = await RunCmdAsync(cmd, args, workspaceDir); if (CheckRunCmdError(output)) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); @@ -54,7 +55,7 @@ public static async Task CompileFileAsync(string file, string workspaceDir) } else { - binfiles = Directory.GetFiles(AssemblyLocation, "*.bin", SearchOption.TopDirectoryOnly); + binfiles = Directory.GetFiles(workspaceDir, "*.bin", SearchOption.TopDirectoryOnly); if (binfiles is null || binfiles.Length == 0) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); diff --git a/src/Stratis.VS.StratisEVM/SolidityLanguageClient.cs b/src/Stratis.VS.StratisEVM/SolidityLanguageClient.cs index dfbff4f..d730717 100644 --- a/src/Stratis.VS.StratisEVM/SolidityLanguageClient.cs +++ b/src/Stratis.VS.StratisEVM/SolidityLanguageClient.cs @@ -151,22 +151,22 @@ public async Task ActivateAsync(CancellationToken token) } if (Directory.Exists(Path.Combine(Runtime.AssemblyLocation, "node_modules")) && File.Exists(Path.Combine(Runtime.AssemblyLocation, "node_modules", "solidity", "dist", "cli", "server.js"))) { - VSUtil.LogInfo("Stratis EVM", "vscode-solidity language server present."); + VSUtil.LogInfo("Stratis EVM", "Solidity language server present."); } else { VSUtil.ShowLogOutputWindowPane(ServiceProvider.GlobalProvider, "Stratis EVM"); - VSUtil.LogInfo("Stratis EVM", "Installing vscode-solidity language server..."); + VSUtil.LogInfo("Stratis EVM", "Installing Solidity language server..."); await TaskScheduler.Default; var output = await InstallVSCodeSolidityLanguageServerAsync(); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (CheckRunCmdOutput(output, "Run `npm audit` for details.")) { - VSUtil.LogInfo("Stratis EVM", "vscode-solidity language server installed."); + VSUtil.LogInfo("Stratis EVM", "Solidity language server installed."); } else { - VSUtil.LogError("Stratis EVM", "Could not install vscode-solidity language server."); + VSUtil.LogError("Stratis EVM", "Could not install Solidity language server."); return null; } } @@ -219,7 +219,7 @@ public Task AttachForCustomMessageAsync(JsonRpc rpc) public Task OnServerInitializeFailedAsync(ILanguageClientInitializationInfo initializationState) { - string message = "vscode-solidity language server failed to initialize."; + string message = "Solidity language server failed to initialize."; Error(message); string exception = initializationState.InitializationException?.ToString() ?? string.Empty; message = $"{message}\n {exception}"; @@ -265,7 +265,7 @@ public async Task HandleNotificationAsync(string methodName, JToken methodParam, public async Task HandleRequestAsync(string methodName, JToken methodParam, Func> sendRequest) { - try //Handle exceptions raised by vscode-solidity server like https://github.com/juanfranblanco/vscode-solidity/issues/446 + try //Handle exceptions raised by Solidity server like https://github.com/juanfranblanco/Solidity/issues/446 { var resp = await sendRequest(methodParam); Info("Request {req} {param}: {resp}", methodName, methodParam?.ToString() ?? "", resp?.ToString() ?? "(null)"); @@ -279,7 +279,7 @@ public async Task HandleRequestAsync(string methodName, JToken methodPar resp.Root["contents"]["kind"] = JValue.CreateString("plaintext"); if (resp.Root["contents"]["value"] != null) { - resp.Root["contents"]["value"] = JValue.CreateString(resp.Root["contents"]["value"].Value().Replace("### ", "").Replace("#", "")); + resp.Root["contents"]["value"] = JValue.CreateString(resp.Root["contents"]["value"].Value().Replace("### ", "").Replace("#", "").Trim()); } else { diff --git a/src/Stratis.VS.StratisEVM/StratisEVMPackage.cs b/src/Stratis.VS.StratisEVM/StratisEVMPackage.cs index 00b2e24..c3b01d4 100644 --- a/src/Stratis.VS.StratisEVM/StratisEVMPackage.cs +++ b/src/Stratis.VS.StratisEVM/StratisEVMPackage.cs @@ -132,6 +132,7 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke public static async Task InstallBuildSystemAsync() { +#if DEBUG await Runtime.CopyDirectoryAsync(Runtime.AssemblyLocation.CombinePath("BuildSystem"), Runtime.LocalAppDataDir.CombinePath("CustomProjectSystems", "Solidity"), true); if (!Directory.Exists(Runtime.LocalAppDataDir.CombinePath("CustomProjectSystems", "Solidity", "Tools"))) @@ -143,6 +144,22 @@ public static async Task InstallBuildSystemAsync() { await Runtime.CopyFileAsync(Runtime.AssemblyLocation.CombinePath("CompactJson.dll"), Runtime.LocalAppDataDir.CombinePath("CustomProjectSystems", "Solidity", "Tools", "CompactJson.dll")); } +#else + if (!Directory.Exists(Runtime.LocalAppDataDir.CombinePath("CustomProjectSystems", "Solidity"))) + { + await Runtime.CopyDirectoryAsync(Runtime.AssemblyLocation.CombinePath("BuildSystem"), Runtime.LocalAppDataDir.CombinePath("CustomProjectSystems", "Solidity"), true); + + if (!Directory.Exists(Runtime.LocalAppDataDir.CombinePath("CustomProjectSystems", "Solidity", "Tools"))) + { + Directory.CreateDirectory(Runtime.LocalAppDataDir.CombinePath("CustomProjectSystems", "Solidity", "Tools")); + } + await Runtime.CopyFileAsync(Runtime.AssemblyLocation.CombinePath("Stratis.VS.SolidityProjectBuildTasks.dll"), Runtime.LocalAppDataDir.CombinePath("CustomProjectSystems", "Solidity", "Tools", "Stratis.VS.SolidityProjectBuildTasks.dll")); + if (!File.Exists(Runtime.LocalAppDataDir.CombinePath("CustomProjectSystems", "Solidity", "Tools", "CompactJson.dll"))) + { + await Runtime.CopyFileAsync(Runtime.AssemblyLocation.CombinePath("CompactJson.dll"), Runtime.LocalAppDataDir.CombinePath("CustomProjectSystems", "Solidity", "Tools", "CompactJson.dll")); + } + } +#endif await File.WriteAllTextAsync(Runtime.LocalAppDataDir.CombinePath("CustomProjectSystems", "Solidity", "extdir.txt"), Runtime.AssemblyLocation); } #endregion