Skip to content

Commit 27369cc

Browse files
committed
Merge pull request #38 from PowerShell/daviwil/protocol-change
Final fixes before 0.1.0 release
2 parents b9cfe1f + 1bd59fa commit 27369cc

File tree

23 files changed

+245
-202
lines changed

23 files changed

+245
-202
lines changed

src/PowerShellEditorServices.Host/DebugAdapter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected async Task HandleLaunchRequest(
101101
// Execute the given PowerShell script and send the response.
102102
// Note that we aren't waiting for execution to complete here
103103
// because the debugger could stop while the script executes.
104-
editorSession.PowerShellSession
104+
editorSession.powerShellContext
105105
.ExecuteScriptAtPath(launchParams.Program)
106106
.ContinueWith(
107107
async (t) =>
@@ -138,18 +138,18 @@ protected Task HandleDisconnectRequest(
138138
handler =
139139
async (o, e) =>
140140
{
141-
if (e.NewSessionState == PowerShellSessionState.Ready)
141+
if (e.NewSessionState == PowerShellContextState.Ready)
142142
{
143143
await requestContext.SendResult(null);
144-
editorSession.PowerShellSession.SessionStateChanged -= handler;
144+
editorSession.powerShellContext.SessionStateChanged -= handler;
145145

146146
// TODO: Find a way to exit more gracefully!
147147
Environment.Exit(0);
148148
}
149149
};
150150

151-
editorSession.PowerShellSession.SessionStateChanged += handler;
152-
editorSession.PowerShellSession.AbortExecution();
151+
editorSession.powerShellContext.SessionStateChanged += handler;
152+
editorSession.powerShellContext.AbortExecution();
153153

154154
return Task.FromResult(true);
155155
}

src/PowerShellEditorServices.Host/LanguageServer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,16 @@ protected Task HandleDidCloseTextDocumentNotification(
177177
}
178178

179179
protected Task HandleDidChangeTextDocumentNotification(
180-
DidChangeTextDocumentNotification[] textChangeParams,
180+
DidChangeTextDocumentParams textChangeParams,
181181
EditorSession editorSession,
182182
EventContext eventContext)
183183
{
184184
List<ScriptFile> changedFiles = new List<ScriptFile>();
185185

186186
// A text change notification can batch multiple change requests
187-
foreach (var textChange in textChangeParams)
187+
foreach (var textChange in textChangeParams.ContentChanges)
188188
{
189-
ScriptFile changedFile = editorSession.Workspace.GetFile(textChange.Uri);
189+
ScriptFile changedFile = editorSession.Workspace.GetFile(textChangeParams.Uri);
190190

191191
changedFile.ApplyChange(
192192
GetFileChangeDetails(
@@ -366,7 +366,7 @@ protected async Task HandleCompletionResolveRequest(
366366
if (completionItem.Kind == CompletionItemKind.Function)
367367
{
368368
RunspaceHandle runspaceHandle =
369-
await editorSession.PowerShellSession.GetRunspaceHandle();
369+
await editorSession.powerShellContext.GetRunspaceHandle();
370370

371371
// Get the documentation for the function
372372
CommandInfo commandInfo =

src/PowerShellEditorServices.Host/MessageLoop.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async Task ListenForMessages()
129129
// Set up the PowerShell session
130130
this.editorSession = new EditorSession();
131131
this.editorSession.StartSession(this.consoleHost);
132-
this.editorSession.PowerShellSession.OutputWritten += PowerShellSession_OutputWritten;
132+
this.editorSession.powerShellContext.OutputWritten += powerShellContext_OutputWritten;
133133

134134
if (this.runDebugAdapter)
135135
{
@@ -191,7 +191,7 @@ await this.messageWriter.WriteEvent(
191191
}, null);
192192
}
193193

194-
async void PowerShellSession_OutputWritten(object sender, OutputWrittenEventArgs e)
194+
async void powerShellContext_OutputWritten(object sender, OutputWrittenEventArgs e)
195195
{
196196
await this.messageWriter.WriteEvent(
197197
OutputEvent.Type,

src/PowerShellEditorServices.Protocol/LanguageServer/CompletionMessages.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ public class CompletionItem
7575
public string InsertText { get; set; }
7676

7777
public TextEdit TextEdit { get; set; }
78+
79+
/// <summary>
80+
/// Gets or sets a custom data field that allows the server to mark
81+
/// each completion item with an identifier that will help correlate
82+
/// the item to the previous completion request during a completion
83+
/// resolve request.
84+
/// </summary>
85+
public object Data { get; set; }
7886
}
7987
}
8088

src/PowerShellEditorServices.Protocol/LanguageServer/References.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public static readonly
1616

1717
public class ReferencesParams : TextDocumentPosition
1818
{
19-
public ReferencesOptions Options { get; set; }
19+
public ReferencesContext Context { get; set; }
2020
}
2121

22-
public class ReferencesOptions
22+
public class ReferencesContext
2323
{
2424
public bool IncludeDeclaration { get; set; }
2525
}

src/PowerShellEditorServices.Protocol/LanguageServer/TextDocumentMessages.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,23 @@ public static readonly
4949
EventType<TextDocumentIdentifier>.Create("textDocument/didClose");
5050
}
5151

52-
public class DidChangeTextDocumentNotification : TextDocumentIdentifier
52+
public class DidChangeTextDocumentNotification
5353
{
5454
public static readonly
55-
EventType<DidChangeTextDocumentNotification[]> Type =
56-
EventType<DidChangeTextDocumentNotification[]>.Create("textDocument/didChange");
55+
EventType<DidChangeTextDocumentParams> Type =
56+
EventType<DidChangeTextDocumentParams>.Create("textDocument/didChange");
57+
}
5758

59+
public class DidChangeTextDocumentParams : TextDocumentIdentifier
60+
{
61+
/// <summary>
62+
/// Gets or sets the list of changes to the document content.
63+
/// </summary>
64+
public TextDocumentChangeEvent[] ContentChanges { get; set; }
65+
}
66+
67+
public class TextDocumentChangeEvent
68+
{
5869
/// <summary>
5970
/// Gets or sets the Range where the document was changed. Will
6071
/// be null if the server's TextDocumentSyncKind is Full.

src/PowerShellEditorServices.Protocol/MessageProtocol/MessageReader.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,18 @@ await this.inputStream.ReadAsync(
142142

143143
this.bufferEndOffset += readLength;
144144

145-
return readLength >= 0;
145+
if (readLength == 0)
146+
{
147+
// If ReadAsync returns 0 then it means that the stream was
148+
// closed unexpectedly (usually due to the client application
149+
// ending suddenly). For now, just terminate the language
150+
// server immediately.
151+
// TODO: Provide a more graceful shutdown path
152+
throw new EndOfStreamException(
153+
"MessageReader's input stream ended unexpectedly, terminating.");
154+
}
155+
156+
return true;
146157
}
147158

148159
private bool TryReadMessageHeaders()

src/PowerShellEditorServices/Analysis/AnalysisService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class AnalysisService : IDisposable
3232
/// </summary>
3333
public AnalysisService()
3434
{
35-
// TODO: Share runspace with PowerShellSession? Probably should always
35+
// TODO: Share runspace with PowerShellContext? Probably should always
3636
// run analysis in a local session.
3737
this.analysisRunspace = RunspaceFactory.CreateRunspace(InitialSessionState.CreateDefault2());
3838
this.analysisRunspace.ApartmentState = ApartmentState.STA;

src/PowerShellEditorServices/Debugging/DebugService.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ namespace Microsoft.PowerShell.EditorServices
1414
{
1515
/// <summary>
1616
/// Provides a high-level service for interacting with the
17-
/// PowerShell debugger in the context of a PowerShellSession.
17+
/// PowerShell debugger in the runspace managed by a PowerShellContext.
1818
/// </summary>
1919
public class DebugService
2020
{
2121
#region Fields
2222

23-
private PowerShellSession powerShellSession;
23+
private PowerShellContext powerShellContext;
2424

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

3737
/// <summary>
3838
/// Initializes a new instance of the DebugService class and uses
39-
/// the given PowerShellSession for all future operations.
39+
/// the given PowerShellContext for all future operations.
4040
/// </summary>
41-
/// <param name="powerShellSession">
42-
/// The PowerShellSession to use for all debugging operations.
41+
/// <param name="powerShellContext">
42+
/// The PowerShellContext to use for all debugging operations.
4343
/// </param>
44-
public DebugService(PowerShellSession powerShellSession)
44+
public DebugService(PowerShellContext powerShellContext)
4545
{
46-
Validate.IsNotNull("powerShellSession", powerShellSession);
46+
Validate.IsNotNull("powerShellContext", powerShellContext);
4747

48-
this.powerShellSession = powerShellSession;
49-
this.powerShellSession.DebuggerStop += this.OnDebuggerStop;
50-
this.powerShellSession.BreakpointUpdated += this.OnBreakpointUpdated;
48+
this.powerShellContext = powerShellContext;
49+
this.powerShellContext.DebuggerStop += this.OnDebuggerStop;
50+
this.powerShellContext.BreakpointUpdated += this.OnBreakpointUpdated;
5151
}
5252

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

8383
resultBreakpoints =
84-
await this.powerShellSession.ExecuteCommand<Breakpoint>(
84+
await this.powerShellContext.ExecuteCommand<Breakpoint>(
8585
psCommand);
8686

8787
return
@@ -98,7 +98,7 @@ await this.powerShellSession.ExecuteCommand<Breakpoint>(
9898
/// </summary>
9999
public void Continue()
100100
{
101-
this.powerShellSession.ResumeDebugger(
101+
this.powerShellContext.ResumeDebugger(
102102
DebuggerResumeAction.Continue);
103103
}
104104

@@ -107,7 +107,7 @@ public void Continue()
107107
/// </summary>
108108
public void StepOver()
109109
{
110-
this.powerShellSession.ResumeDebugger(
110+
this.powerShellContext.ResumeDebugger(
111111
DebuggerResumeAction.StepOver);
112112
}
113113

@@ -116,7 +116,7 @@ public void StepOver()
116116
/// </summary>
117117
public void StepIn()
118118
{
119-
this.powerShellSession.ResumeDebugger(
119+
this.powerShellContext.ResumeDebugger(
120120
DebuggerResumeAction.StepInto);
121121
}
122122

@@ -125,7 +125,7 @@ public void StepIn()
125125
/// </summary>
126126
public void StepOut()
127127
{
128-
this.powerShellSession.ResumeDebugger(
128+
this.powerShellContext.ResumeDebugger(
129129
DebuggerResumeAction.StepOut);
130130
}
131131

@@ -137,16 +137,16 @@ public void StepOut()
137137
public void Break()
138138
{
139139
// Break execution in the debugger
140-
this.powerShellSession.BreakExecution();
140+
this.powerShellContext.BreakExecution();
141141
}
142142

143143
/// <summary>
144144
/// Aborts execution of the debugger while it is running, even while
145-
/// it is stopped. Equivalent to calling PowerShellSession.AbortExecution.
145+
/// it is stopped. Equivalent to calling PowerShellContext.AbortExecution.
146146
/// </summary>
147147
public void Abort()
148148
{
149-
this.powerShellSession.AbortExecution();
149+
this.powerShellContext.AbortExecution();
150150
}
151151

152152
/// <summary>
@@ -238,15 +238,15 @@ public VariableDetails GetVariableFromExpression(string variableExpression, int
238238
/// <summary>
239239
/// Evaluates an expression in the context of the stopped
240240
/// debugger. This method will execute the specified expression
241-
/// PowerShellSession.
241+
/// PowerShellContext.
242242
/// </summary>
243243
/// <param name="expressionString">The expression string to execute.</param>
244244
/// <param name="stackFrameId">The ID of the stack frame in which the expression should be executed.</param>
245245
/// <returns>A VariableDetails object containing the result.</returns>
246246
public async Task<VariableDetails> EvaluateExpression(string expressionString, int stackFrameId)
247247
{
248248
var results =
249-
await this.powerShellSession.ExecuteScriptString(
249+
await this.powerShellContext.ExecuteScriptString(
250250
expressionString);
251251

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

305-
await this.powerShellSession.ExecuteCommand<object>(psCommand);
305+
await this.powerShellContext.ExecuteCommand<object>(psCommand);
306306

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

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

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

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

341341
this.callStackFrames =
342342
results

0 commit comments

Comments
 (0)