Skip to content

Commit

Permalink
Fix compile file menu action. Don't replace build system if running i…
Browse files Browse the repository at this point in the history
…n release. vscode-solidity->Solidity.
  • Loading branch information
allisterb committed Dec 11, 2024
1 parent fbc4df6 commit ef1f20b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/Stratis.VS.StratisEVM/SolidityCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions src/Stratis.VS.StratisEVM/SolidityLanguageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,22 @@ public async Task<Connection> 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;
}
}
Expand Down Expand Up @@ -219,7 +219,7 @@ public Task AttachForCustomMessageAsync(JsonRpc rpc)

public Task<InitializationFailureContext> 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}";
Expand Down Expand Up @@ -265,7 +265,7 @@ public async Task HandleNotificationAsync(string methodName, JToken methodParam,

public async Task<JToken> HandleRequestAsync(string methodName, JToken methodParam, Func<JToken, Task<JToken>> 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)");
Expand All @@ -279,7 +279,7 @@ public async Task<JToken> 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<string>().Replace("### ", "").Replace("#", ""));
resp.Root["contents"]["value"] = JValue.CreateString(resp.Root["contents"]["value"].Value<string>().Replace("### ", "").Replace("#", "").Trim());
}
else
{
Expand Down
17 changes: 17 additions & 0 deletions src/Stratis.VS.StratisEVM/StratisEVMPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand All @@ -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
Expand Down

0 comments on commit ef1f20b

Please sign in to comment.