#pragma warning restore CS0067 public async Task <Connection> ActivateAsync(CancellationToken token) { await Task.Yield(); var vscodeDirectory = Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.UserProfile), ".vscode", "extensions"); if (!Directory.Exists(vscodeDirectory)) { throw new Exception("PowerShell VS Code extension required."); } var extensionDirectory = Directory.GetDirectories(vscodeDirectory) .FirstOrDefault(m => m.Contains("ms-vscode.powershell")); var script = Path.Combine(extensionDirectory, "modules", "PowerShellEditorServices", "Start-EditorServices.ps1"); var info = new ProcessStartInfo { FileName = @"/usr/local/bin/pwsh", Arguments = $@"-NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "" & '{script}' -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '1.5.1' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath '{extensionDirectory}/modules' -EnableConsoleRepl -LogLevel 'Diagnostic' -LogPath '{extensionDirectory}/logs/VSEditorServices.log' -SessionDetailsPath '{extensionDirectory}/logs/PSES-VS' -FeatureFlags @()""", RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true }; var process = new Process(); process.StartInfo = info; if (process.Start()) { //Wait for startup.... string sessionFile = $@"{extensionDirectory}/logs/PSES-VS"; var sessionInfo = await WaitForSessionFileAsync(sessionFile); File.Delete(sessionFile); var sessionInfoJObject = JsonConvert.DeserializeObject <JObject> (sessionInfo); var status = (string)sessionInfoJObject ["status"]; if (status != "started") { LanguageClientLoggingService.Log(sessionInfoJObject.ToString()); var reason = (string)sessionInfoJObject ["reason"]; throw new ApplicationException($"Failed to start PowerShell console. {reason}"); } var languageServicePipeName = (string)sessionInfoJObject ["languageServicePipeName"]; var client = new UnixClient(languageServicePipeName); var stream = client.GetStream(); return(new Connection(stream, stream)); } return(null); }
#pragma warning restore CS0067 /// <summary> /// Requires the Java Language Support extension to be installed into Visual Studio Code /// https://github.com/redhat-developer/vscode-java /// </summary> public Task <Connection> ActivateAsync(CancellationToken token) { string currentDirectory = Path.GetDirectoryName(GetType().Assembly.Location); var vscodeDirectory = Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.UserProfile), ".vscode", "extensions"); if (!Directory.Exists(vscodeDirectory)) { throw new Exception("Java Language Support for Visual Studio Code required."); } var extensionDirectory = Directory.GetDirectories(vscodeDirectory) .FirstOrDefault(m => m.Contains("redhat.java")); if (extensionDirectory == null) { throw new Exception("Java Language Support for Visual Studio Code required."); } string javaBinPath = "/usr/bin/java"; if (!File.Exists(javaBinPath)) { throw new ApplicationException(string.Format("Java not found at '{0}'", javaBinPath)); } string pluginsDirectory = Path.Combine(extensionDirectory, "server", "plugins"); string launcher = Directory.GetFiles(pluginsDirectory, "org.eclipse.equinox.launcher_*.jar") .FirstOrDefault(); if (!File.Exists(launcher)) { throw new ApplicationException(string.Format("Launcher not found.")); } string configDirectory = Path.Combine(extensionDirectory, "server", "config_mac"); var arguments = new StringBuilder(); arguments.Append("-Declipse.application=org.eclipse.jdt.ls.core.id1 "); arguments.Append("-Dosgi.bundles.defaultStartLevel=4 "); arguments.Append("-Declipse.product=org.eclipse.jdt.ls.core.product "); arguments.Append("-Dlog.protocol=true "); arguments.Append("-Dlog.level=ALL "); arguments.AppendFormat("-jar \"{0}\" ", launcher); arguments.AppendFormat("-configuration \"{0}\" ", configDirectory); arguments.AppendFormat("-data \"{0}\" ", currentDirectory); var info = new ProcessStartInfo { FileName = javaBinPath, Arguments = arguments.ToString(), RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true }; LanguageClientLoggingService.Log("{0} {1}", javaBinPath, info.Arguments); var process = new Process(); process.StartInfo = info; Connection connection = null; if (process.Start()) { connection = new Connection(process.StandardOutput.BaseStream, process.StandardInput.BaseStream); } return(Task.FromResult(connection)); }