Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/PowerShellEditorServices.Host/DebugAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected async Task HandleLaunchRequest(
// Execute the given PowerShell script and send the response.
// Note that we aren't waiting for execution to complete here
// because the debugger could stop while the script executes.
editorSession.PowerShellSession
editorSession.powerShellContext
.ExecuteScriptAtPath(launchParams.Program)
.ContinueWith(
async (t) =>
Expand Down Expand Up @@ -138,18 +138,18 @@ protected Task HandleDisconnectRequest(
handler =
async (o, e) =>
{
if (e.NewSessionState == PowerShellSessionState.Ready)
if (e.NewSessionState == PowerShellContextState.Ready)
{
await requestContext.SendResult(null);
editorSession.PowerShellSession.SessionStateChanged -= handler;
editorSession.powerShellContext.SessionStateChanged -= handler;

// TODO: Find a way to exit more gracefully!
Environment.Exit(0);
}
};

editorSession.PowerShellSession.SessionStateChanged += handler;
editorSession.PowerShellSession.AbortExecution();
editorSession.powerShellContext.SessionStateChanged += handler;
editorSession.powerShellContext.AbortExecution();

return Task.FromResult(true);
}
Expand Down
8 changes: 4 additions & 4 deletions src/PowerShellEditorServices.Host/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,16 @@ protected Task HandleDidCloseTextDocumentNotification(
}

protected Task HandleDidChangeTextDocumentNotification(
DidChangeTextDocumentNotification[] textChangeParams,
DidChangeTextDocumentParams textChangeParams,
EditorSession editorSession,
EventContext eventContext)
{
List<ScriptFile> changedFiles = new List<ScriptFile>();

// A text change notification can batch multiple change requests
foreach (var textChange in textChangeParams)
foreach (var textChange in textChangeParams.ContentChanges)
{
ScriptFile changedFile = editorSession.Workspace.GetFile(textChange.Uri);
ScriptFile changedFile = editorSession.Workspace.GetFile(textChangeParams.Uri);

changedFile.ApplyChange(
GetFileChangeDetails(
Expand Down Expand Up @@ -366,7 +366,7 @@ protected async Task HandleCompletionResolveRequest(
if (completionItem.Kind == CompletionItemKind.Function)
{
RunspaceHandle runspaceHandle =
await editorSession.PowerShellSession.GetRunspaceHandle();
await editorSession.powerShellContext.GetRunspaceHandle();

// Get the documentation for the function
CommandInfo commandInfo =
Expand Down
4 changes: 2 additions & 2 deletions src/PowerShellEditorServices.Host/MessageLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async Task ListenForMessages()
// Set up the PowerShell session
this.editorSession = new EditorSession();
this.editorSession.StartSession(this.consoleHost);
this.editorSession.PowerShellSession.OutputWritten += PowerShellSession_OutputWritten;
this.editorSession.powerShellContext.OutputWritten += powerShellContext_OutputWritten;

if (this.runDebugAdapter)
{
Expand Down Expand Up @@ -191,7 +191,7 @@ await this.messageWriter.WriteEvent(
}, null);
}

async void PowerShellSession_OutputWritten(object sender, OutputWrittenEventArgs e)
async void powerShellContext_OutputWritten(object sender, OutputWrittenEventArgs e)
{
await this.messageWriter.WriteEvent(
OutputEvent.Type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public class CompletionItem
public string InsertText { get; set; }

public TextEdit TextEdit { get; set; }

/// <summary>
/// Gets or sets a custom data field that allows the server to mark
/// each completion item with an identifier that will help correlate
/// the item to the previous completion request during a completion
/// resolve request.
/// </summary>
public object Data { get; set; }
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public static readonly

public class ReferencesParams : TextDocumentPosition
{
public ReferencesOptions Options { get; set; }
public ReferencesContext Context { get; set; }
}

public class ReferencesOptions
public class ReferencesContext
{
public bool IncludeDeclaration { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,23 @@ public static readonly
EventType<TextDocumentIdentifier>.Create("textDocument/didClose");
}

public class DidChangeTextDocumentNotification : TextDocumentIdentifier
public class DidChangeTextDocumentNotification
{
public static readonly
EventType<DidChangeTextDocumentNotification[]> Type =
EventType<DidChangeTextDocumentNotification[]>.Create("textDocument/didChange");
EventType<DidChangeTextDocumentParams> Type =
EventType<DidChangeTextDocumentParams>.Create("textDocument/didChange");
}

public class DidChangeTextDocumentParams : TextDocumentIdentifier
{
/// <summary>
/// Gets or sets the list of changes to the document content.
/// </summary>
public TextDocumentChangeEvent[] ContentChanges { get; set; }
}

public class TextDocumentChangeEvent
{
/// <summary>
/// Gets or sets the Range where the document was changed. Will
/// be null if the server's TextDocumentSyncKind is Full.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,18 @@ await this.inputStream.ReadAsync(

this.bufferEndOffset += readLength;

return readLength >= 0;
if (readLength == 0)
{
// If ReadAsync returns 0 then it means that the stream was
// closed unexpectedly (usually due to the client application
// ending suddenly). For now, just terminate the language
// server immediately.
// TODO: Provide a more graceful shutdown path
throw new EndOfStreamException(
"MessageReader's input stream ended unexpectedly, terminating.");
}

return true;
}

private bool TryReadMessageHeaders()
Expand Down
2 changes: 1 addition & 1 deletion src/PowerShellEditorServices/Analysis/AnalysisService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class AnalysisService : IDisposable
/// </summary>
public AnalysisService()
{
// TODO: Share runspace with PowerShellSession? Probably should always
// TODO: Share runspace with PowerShellContext? Probably should always
// run analysis in a local session.
this.analysisRunspace = RunspaceFactory.CreateRunspace(InitialSessionState.CreateDefault2());
this.analysisRunspace.ApartmentState = ApartmentState.STA;
Expand Down
46 changes: 23 additions & 23 deletions src/PowerShellEditorServices/Debugging/DebugService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ namespace Microsoft.PowerShell.EditorServices
{
/// <summary>
/// Provides a high-level service for interacting with the
/// PowerShell debugger in the context of a PowerShellSession.
/// PowerShell debugger in the runspace managed by a PowerShellContext.
/// </summary>
public class DebugService
{
#region Fields

private PowerShellSession powerShellSession;
private PowerShellContext powerShellContext;

// TODO: This needs to be managed per nested session
private Dictionary<string, List<Breakpoint>> breakpointsPerFile =
Expand All @@ -36,18 +36,18 @@ public class DebugService

/// <summary>
/// Initializes a new instance of the DebugService class and uses
/// the given PowerShellSession for all future operations.
/// the given PowerShellContext for all future operations.
/// </summary>
/// <param name="powerShellSession">
/// The PowerShellSession to use for all debugging operations.
/// <param name="powerShellContext">
/// The PowerShellContext to use for all debugging operations.
/// </param>
public DebugService(PowerShellSession powerShellSession)
public DebugService(PowerShellContext powerShellContext)
{
Validate.IsNotNull("powerShellSession", powerShellSession);
Validate.IsNotNull("powerShellContext", powerShellContext);

this.powerShellSession = powerShellSession;
this.powerShellSession.DebuggerStop += this.OnDebuggerStop;
this.powerShellSession.BreakpointUpdated += this.OnBreakpointUpdated;
this.powerShellContext = powerShellContext;
this.powerShellContext.DebuggerStop += this.OnDebuggerStop;
this.powerShellContext.BreakpointUpdated += this.OnBreakpointUpdated;
}

#endregion
Expand Down Expand Up @@ -81,7 +81,7 @@ public async Task<BreakpointDetails[]> SetBreakpoints(
psCommand.AddParameter("Line", lineNumbers.Length > 0 ? lineNumbers : null);

resultBreakpoints =
await this.powerShellSession.ExecuteCommand<Breakpoint>(
await this.powerShellContext.ExecuteCommand<Breakpoint>(
psCommand);

return
Expand All @@ -98,7 +98,7 @@ await this.powerShellSession.ExecuteCommand<Breakpoint>(
/// </summary>
public void Continue()
{
this.powerShellSession.ResumeDebugger(
this.powerShellContext.ResumeDebugger(
DebuggerResumeAction.Continue);
}

Expand All @@ -107,7 +107,7 @@ public void Continue()
/// </summary>
public void StepOver()
{
this.powerShellSession.ResumeDebugger(
this.powerShellContext.ResumeDebugger(
DebuggerResumeAction.StepOver);
}

Expand All @@ -116,7 +116,7 @@ public void StepOver()
/// </summary>
public void StepIn()
{
this.powerShellSession.ResumeDebugger(
this.powerShellContext.ResumeDebugger(
DebuggerResumeAction.StepInto);
}

Expand All @@ -125,7 +125,7 @@ public void StepIn()
/// </summary>
public void StepOut()
{
this.powerShellSession.ResumeDebugger(
this.powerShellContext.ResumeDebugger(
DebuggerResumeAction.StepOut);
}

Expand All @@ -137,16 +137,16 @@ public void StepOut()
public void Break()
{
// Break execution in the debugger
this.powerShellSession.BreakExecution();
this.powerShellContext.BreakExecution();
}

/// <summary>
/// Aborts execution of the debugger while it is running, even while
/// it is stopped. Equivalent to calling PowerShellSession.AbortExecution.
/// it is stopped. Equivalent to calling PowerShellContext.AbortExecution.
/// </summary>
public void Abort()
{
this.powerShellSession.AbortExecution();
this.powerShellContext.AbortExecution();
}

/// <summary>
Expand Down Expand Up @@ -238,15 +238,15 @@ public VariableDetails GetVariableFromExpression(string variableExpression, int
/// <summary>
/// Evaluates an expression in the context of the stopped
/// debugger. This method will execute the specified expression
/// PowerShellSession.
/// PowerShellContext.
/// </summary>
/// <param name="expressionString">The expression string to execute.</param>
/// <param name="stackFrameId">The ID of the stack frame in which the expression should be executed.</param>
/// <returns>A VariableDetails object containing the result.</returns>
public async Task<VariableDetails> EvaluateExpression(string expressionString, int stackFrameId)
{
var results =
await this.powerShellSession.ExecuteScriptString(
await this.powerShellContext.ExecuteScriptString(
expressionString);

// Since this method should only be getting invoked in the debugger,
Expand Down Expand Up @@ -302,7 +302,7 @@ private async Task ClearBreakpointsInFile(ScriptFile scriptFile)
psCommand.AddCommand("Remove-PSBreakpoint");
psCommand.AddParameter("Breakpoint", breakpoints.ToArray());

await this.powerShellSession.ExecuteCommand<object>(psCommand);
await this.powerShellContext.ExecuteCommand<object>(psCommand);

// Clear the existing breakpoints list for the file
breakpoints.Clear();
Expand All @@ -319,7 +319,7 @@ private async Task FetchVariables()
psCommand.AddCommand("Get-Variable");
psCommand.AddParameter("Scope", "Local");

var results = await this.powerShellSession.ExecuteCommand<PSVariable>(psCommand);
var results = await this.powerShellContext.ExecuteCommand<PSVariable>(psCommand);

foreach (var variable in results)
{
Expand All @@ -336,7 +336,7 @@ private async Task FetchStackFrames()
PSCommand psCommand = new PSCommand();
psCommand.AddCommand("Get-PSCallStack");

var results = await this.powerShellSession.ExecuteCommand<CallStackFrame>(psCommand);
var results = await this.powerShellContext.ExecuteCommand<CallStackFrame>(psCommand);

this.callStackFrames =
results
Expand Down
Loading