/// <summary> /// Starts the debug service with the specified TCP socket port. /// </summary> /// <param name="debugServicePort">The port number for the debug service.</param> public void StartDebugService(int debugServicePort, ProfilePaths profilePaths) { this.debugAdapter = new DebugAdapter( hostDetails, profilePaths, new TcpSocketServerChannel(debugServicePort), this.languageServer?.EditorOperations); this.debugAdapter.SessionEnded += (obj, args) => { Logger.Write( LogLevel.Normal, "Previous debug session ended, restarting debug service..."); this.StartDebugService(debugServicePort, profilePaths); }; this.debugAdapter.Start().Wait(); Logger.Write( LogLevel.Normal, string.Format( "Debug service started, listening on port {0}", debugServicePort)); }
internal NamedPipePsesLanguageServer( ILoggerFactory factory, LogLevel minimumLogLevel, bool enableConsoleRepl, bool useLegacyReadLine, HashSet <string> featureFlags, HostDetails hostDetails, string[] additionalModules, PSHost internalHost, ProfilePaths profilePaths, string namedPipeName, string outNamedPipeName) : base( factory, minimumLogLevel, enableConsoleRepl, useLegacyReadLine, featureFlags, hostDetails, additionalModules, internalHost, profilePaths) { _namedPipeName = namedPipeName; _outNamedPipeName = outNamedPipeName; }
private EditorSession CreateDebugSession( HostDetails hostDetails, ProfilePaths profilePaths, IMessageSender messageSender, IMessageHandlers messageHandlers, IEditorOperations editorOperations, bool enableConsoleRepl) { EditorSession editorSession = new EditorSession(this.logger); PowerShellContext powerShellContext = new PowerShellContext(this.logger); EditorServicesPSHostUserInterface hostUserInterface = enableConsoleRepl ? (EditorServicesPSHostUserInterface) new TerminalPSHostUserInterface(powerShellContext, this.logger) : new ProtocolPSHostUserInterface(powerShellContext, messageSender, this.logger); EditorServicesPSHost psHost = new EditorServicesPSHost( powerShellContext, hostDetails, hostUserInterface, this.logger); Runspace initialRunspace = PowerShellContext.CreateRunspace(psHost); powerShellContext.Initialize(profilePaths, initialRunspace, true, hostUserInterface); editorSession.StartDebugSession( powerShellContext, hostUserInterface, editorOperations); return(editorSession); }
public static IServiceCollection AddPsesLanguageServices( this IServiceCollection collection, ProfilePaths profilePaths, HashSet <string> featureFlags, bool enableConsoleRepl, bool useLegacyReadLine, PSHost internalHost, HostDetails hostDetails, string[] additionalModules) { return(collection.AddSingleton <WorkspaceService>() .AddSingleton <SymbolsService>() .AddSingleton <ConfigurationService>() .AddSingleton <PowerShellContextService>( (provider) => PowerShellContextService.Create( provider.GetService <ILoggerFactory>(), provider.GetService <OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(), profilePaths, featureFlags, enableConsoleRepl, useLegacyReadLine, internalHost, hostDetails, additionalModules)) .AddSingleton <TemplateService>() .AddSingleton <EditorOperationsService>() .AddSingleton <RemoteFileManagerService>() .AddSingleton <ExtensionService>( (provider) => { var extensionService = new ExtensionService( provider.GetService <PowerShellContextService>(), provider.GetService <OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>()); extensionService.InitializeAsync( serviceProvider: provider, editorOperations: provider.GetService <EditorOperationsService>()) .Wait(); return extensionService; }) .AddSingleton <AnalysisService>( (provider) => { return AnalysisService.Create( provider.GetService <ConfigurationService>(), provider.GetService <OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(), provider.GetService <ILoggerFactory>().CreateLogger <AnalysisService>()); })); }
private ProfilePaths SetProfileVariableInCurrentRunspace(HostDetails hostDetails) { // Get the profile paths for the host name ProfilePaths profilePaths = new ProfilePaths( hostDetails.ProfileId, this.currentRunspace); // Create the $profile variable PSObject profile = new PSObject(profilePaths.CurrentUserCurrentHost); profile.Members.Add( new PSNoteProperty( nameof(profilePaths.AllUsersAllHosts), profilePaths.AllUsersAllHosts)); profile.Members.Add( new PSNoteProperty( nameof(profilePaths.AllUsersCurrentHost), profilePaths.AllUsersCurrentHost)); profile.Members.Add( new PSNoteProperty( nameof(profilePaths.CurrentUserAllHosts), profilePaths.CurrentUserAllHosts)); profile.Members.Add( new PSNoteProperty( nameof(profilePaths.CurrentUserCurrentHost), profilePaths.CurrentUserCurrentHost)); Logger.Write( LogLevel.Verbose, string.Format( "Setting $profile variable in runspace. Current user host profile path: {0}", profilePaths.CurrentUserCurrentHost)); // Set the variable in the runspace this.powerShell.Commands.Clear(); this.powerShell .AddCommand("Set-Variable") .AddParameter("Name", "profile") .AddParameter("Value", profile) .AddParameter("Option", "None"); this.powerShell.Invoke(); this.powerShell.Commands.Clear(); return(profilePaths); }
/// <summary> /// Starts the debug service with the specified config. /// </summary> /// <param name="config">The config that contains information on the communication protocol that will be used.</param> /// <param name="profilePaths">The profiles that will be loaded in the session.</param> /// <param name="useExistingSession">Determines if we will reuse the session that we have.</param> public void StartDebugService( EditorServiceTransportConfig config, ProfilePaths profilePaths, bool useExistingSession) { this.debugServiceListener = CreateServiceListener(MessageProtocolType.DebugAdapter, config); this.debugServiceListener.ClientConnect += OnDebugServiceClientConnect; this.debugServiceListener.Start(); this.logger.Write( LogLevel.Normal, string.Format( "Debug service started, type = {0}, endpoint = {1}", config.TransportType, config.Endpoint)); }
/// <summary> /// Starts the language service with the specified TCP socket port. /// </summary> /// <param name="languageServicePort">The port number for the language service.</param> /// <param name="profilePaths">The object containing the profile paths to load for this session.</param> public void StartLanguageService(EditorServiceTransportConfig config, ProfilePaths profilePaths) { this.profilePaths = profilePaths; this.languageServiceListener = CreateServiceListener(MessageProtocolType.LanguageServer, config); this.languageServiceListener.ClientConnect += this.OnLanguageServiceClientConnect; this.languageServiceListener.Start(); this.logger.Write( LogLevel.Normal, string.Format( "Language service started, type = {0}, endpoint = {1}", config.TransportType, config.Endpoint)); }
/// <summary> /// Starts the session using the provided IConsoleHost implementation /// for the ConsoleService. /// </summary> /// <param name="hostDetails"> /// Provides details about the host application. /// </param> /// <param name="profilePaths"> /// An object containing the profile paths for the session. /// </param> public void StartSession(HostDetails hostDetails, ProfilePaths profilePaths) { // Initialize all services this.PowerShellContext = new PowerShellContext(hostDetails, profilePaths); this.LanguageService = new LanguageService(this.PowerShellContext); this.DebugService = new DebugService(this.PowerShellContext); this.ConsoleService = new ConsoleService(this.PowerShellContext); this.ExtensionService = new ExtensionService(this.PowerShellContext); this.TemplateService = new TemplateService(this.PowerShellContext); this.InstantiateAnalysisService(); // Create a workspace to contain open files this.Workspace = new Workspace(this.PowerShellContext.LocalPowerShellVersion.Version); }
/// <summary> /// Starts a debug-only session using the provided IConsoleHost implementation /// for the ConsoleService. /// </summary> /// <param name="hostDetails"> /// Provides details about the host application. /// </param> /// <param name="profilePaths"> /// An object containing the profile paths for the session. /// </param> /// <param name="editorOperations"> /// An IEditorOperations implementation used to interact with the editor. /// </param> public void StartDebugSession( HostDetails hostDetails, ProfilePaths profilePaths, IEditorOperations editorOperations) { // Initialize all services this.PowerShellContext = new PowerShellContext(hostDetails, profilePaths); this.ConsoleService = new ConsoleService(this.PowerShellContext); this.DebugService = new DebugService( this.PowerShellContext, new RemoteFileManager(this.PowerShellContext, editorOperations)); // Create a workspace to contain open files this.Workspace = new Workspace(this.PowerShellContext.LocalPowerShellVersion.Version); }
public DebugAdapter( HostDetails hostDetails, ProfilePaths profilePaths, ChannelBase serverChannel, IEditorOperations editorOperations) : base(serverChannel) { this.editorSession = new EditorSession(); this.editorSession.StartDebugSession(hostDetails, profilePaths, editorOperations); this.editorSession.PowerShellContext.RunspaceChanged += this.powerShellContext_RunspaceChanged; this.editorSession.DebugService.DebuggerStopped += this.DebugService_DebuggerStopped; this.editorSession.ConsoleService.OutputWritten += this.powerShellContext_OutputWritten; // Set up the output debouncer to throttle output event writes this.outputDebouncer = new OutputDebouncer(this); }
/// <summary> /// Starts the language service with the specified TCP socket port. /// </summary> /// <param name="languageServicePort">The port number for the language service.</param> /// <param name="profilePaths">The object containing the profile paths to load for this session.</param> public void StartLanguageService(int languageServicePort, ProfilePaths profilePaths) { this.languageServer = new LanguageServer( hostDetails, profilePaths, new TcpSocketServerChannel(languageServicePort)); this.languageServer.Start().Wait(); Logger.Write( LogLevel.Normal, string.Format( "Language service started, listening on port {0}", languageServicePort)); }
/// <summary> /// Starts the language service with the specified TCP socket port. /// </summary> /// <param name="languageServicePort">The port number for the language service.</param> /// <param name="profilePaths">The object containing the profile paths to load for this session.</param> public void StartLanguageService(int languageServicePort, ProfilePaths profilePaths) { this.profilePaths = profilePaths; this.languageServiceListener = new TcpSocketServerListener( MessageProtocolType.LanguageServer, languageServicePort, this.logger); this.languageServiceListener.ClientConnect += this.OnLanguageServiceClientConnect; this.languageServiceListener.Start(); this.logger.Write( LogLevel.Normal, string.Format( "Language service started, listening on port {0}", languageServicePort)); }
internal StdioPsesLanguageServer( ILoggerFactory factory, LogLevel minimumLogLevel, HashSet <string> featureFlags, HostDetails hostDetails, string[] additionalModules, PSHost internalHost, ProfilePaths profilePaths) : base( factory, minimumLogLevel, // Stdio server can't support an integrated console so we pass in false. false, featureFlags, hostDetails, additionalModules, internalHost, profilePaths) { }
/// <summary> /// Starts the debug service with the specified TCP socket port. /// </summary> /// <param name="debugServicePort">The port number for the debug service.</param> public void StartDebugService( int debugServicePort, ProfilePaths profilePaths, bool useExistingSession) { this.debugServiceListener = new TcpSocketServerListener( MessageProtocolType.DebugAdapter, debugServicePort, this.logger); this.debugServiceListener.ClientConnect += OnDebugServiceClientConnect; this.debugServiceListener.Start(); this.logger.Write( LogLevel.Normal, string.Format( "Debug service started, listening on port {0}", debugServicePort)); }
internal PsesLanguageServer( ILoggerFactory factory, LogLevel minimumLogLevel, bool enableConsoleRepl, HashSet <string> featureFlags, HostDetails hostDetails, string[] additionalModules, PSHost internalHost, ProfilePaths profilePaths) { LoggerFactory = factory; _minimumLogLevel = minimumLogLevel; _enableConsoleRepl = enableConsoleRepl; _featureFlags = featureFlags; _hostDetails = hostDetails; _additionalModules = additionalModules; _internalHost = internalHost; _profilePaths = profilePaths; _serverStart = new TaskCompletionSource <bool>(); }
private EditorSession CreateSession( HostDetails hostDetails, ProfilePaths profilePaths, IMessageSender messageSender, IMessageHandlers messageHandlers, bool enableConsoleRepl) { EditorSession editorSession = new EditorSession(this.logger); PowerShellContext powerShellContext = new PowerShellContext(this.logger); EditorServicesPSHostUserInterface hostUserInterface = enableConsoleRepl ? (EditorServicesPSHostUserInterface) new TerminalPSHostUserInterface(powerShellContext, this.logger) : new ProtocolPSHostUserInterface(powerShellContext, messageSender, this.logger); EditorServicesPSHost psHost = new EditorServicesPSHost( powerShellContext, hostDetails, hostUserInterface, this.logger); Runspace initialRunspace = PowerShellContext.CreateRunspace(psHost); powerShellContext.Initialize(profilePaths, initialRunspace, true, hostUserInterface); editorSession.StartSession(powerShellContext, hostUserInterface); // TODO: Move component registrations elsewhere! editorSession.Components.Register(this.logger); editorSession.Components.Register(messageHandlers); editorSession.Components.Register(messageSender); editorSession.Components.Register(powerShellContext); CodeLensFeature.Create(editorSession.Components, editorSession); DocumentSymbolFeature.Create(editorSession.Components, editorSession); return(editorSession); }
public DebugAdapter(HostDetails hostDetails, ProfilePaths profilePaths) : this(hostDetails, profilePaths, new StdioServerChannel(), null) { }
private void Initialize(HostDetails hostDetails, Runspace initialRunspace) { Validate.IsNotNull("initialRunspace", initialRunspace); this.SessionState = PowerShellContextState.NotStarted; this.initialRunspace = initialRunspace; this.currentRunspace = initialRunspace; this.currentRunspace.Debugger.BreakpointUpdated += OnBreakpointUpdated; this.currentRunspace.Debugger.DebuggerStop += OnDebuggerStop; this.powerShell = PowerShell.Create(); this.powerShell.Runspace = this.currentRunspace; // TODO: Should this be configurable? this.SetExecutionPolicy(ExecutionPolicy.RemoteSigned); // Get the PowerShell runtime version this.PowerShellVersion = GetPowerShellVersion(); // Write out the PowerShell version for tracking purposes Logger.Write( LogLevel.Normal, string.Format( "PowerShell runtime version: {0}", this.PowerShellVersion)); if (PowerShellVersion >= new Version(5, 0)) { this.versionSpecificOperations = new PowerShell5Operations(); } else if (PowerShellVersion.Major == 4) { this.versionSpecificOperations = new PowerShell4Operations(); } else if (PowerShellVersion.Major == 3) { this.versionSpecificOperations = new PowerShell3Operations(); } else { throw new NotSupportedException( "This computer has an unsupported version of PowerShell installed: " + PowerShellVersion.ToString()); } // Configure the runspace's debugger this.versionSpecificOperations.ConfigureDebugger( this.currentRunspace); // Set the $profile variable in the runspace this.profilePaths = this.SetProfileVariableInCurrentRunspace( hostDetails); // Now that initialization is complete we can watch for InvocationStateChanged this.powerShell.InvocationStateChanged += powerShell_InvocationStateChanged; this.SessionState = PowerShellContextState.Ready; // Now that the runspace is ready, enqueue it for first use RunspaceHandle runspaceHandle = new RunspaceHandle(this.currentRunspace, this); this.runspaceWaitQueue.EnqueueAsync(runspaceHandle).Wait(); }