Skip to content

Commit dfc0f22

Browse files
committed
Merge pull request #48 from PowerShell/dfinke/online-help
Added online help
2 parents 8701ec1 + 8554298 commit dfc0f22

File tree

5 files changed

+74
-30
lines changed

5 files changed

+74
-30
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ csx/
4747
PowerShellEditorServices/**
4848

4949

50+
PowerShellEditorServices.sln.ide/edb.chk
51+
PowerShellEditorServices.sln.ide/edbres00001.jrs
52+
PowerShellEditorServices.sln.ide/storage.ide
53+
*.jrs

src/PowerShellEditorServices.Host/LanguageServer.cs

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public void Initialize()
5353
this.AddRequestHandler(DocumentSymbolRequest.Type, this.HandleDocumentSymbolRequest);
5454
this.AddRequestHandler(WorkspaceSymbolRequest.Type, this.HandleWorkspaceSymbolRequest);
5555

56+
this.AddRequestHandler(ShowOnlineHelpRequest.Type, this.HandleShowOnlineHelpRequest);
57+
5658
this.AddRequestHandler(DebugAdapterMessages.EvaluateRequest.Type, this.HandleEvaluateRequest);
5759
}
5860

@@ -66,22 +68,22 @@ public void AddRequestHandler<TParams, TResult, TError>(
6668
}
6769

6870
public void AddEventHandler<TParams>(
69-
EventType<TParams> eventType,
71+
EventType<TParams> eventType,
7072
Func<TParams, EditorSession, EventContext, Task> eventHandler)
7173
{
7274
this.messageDispatcher.AddEventHandler(
7375
eventType,
7476
eventHandler);
7577
}
76-
78+
7779
public async Task ProcessMessage(
78-
Message messageToProcess,
79-
EditorSession editorSession,
80+
Message messageToProcess,
81+
EditorSession editorSession,
8082
MessageWriter messageWriter)
8183
{
8284
await this.messageDispatcher.DispatchMessage(
83-
messageToProcess,
84-
editorSession,
85+
messageToProcess,
86+
editorSession,
8587
messageWriter);
8688
}
8789

@@ -127,6 +129,25 @@ protected Task HandleShutdownRequest(
127129
return Task.FromResult(true);
128130
}
129131

132+
protected async Task HandleShowOnlineHelpRequest(
133+
object helpParams,
134+
EditorSession editorSession,
135+
RequestContext<object, object> requestContext)
136+
{
137+
var psCommand = new PSCommand();
138+
139+
if (helpParams == null) { helpParams = "get-help"; }
140+
141+
var script = string.Format("get-help {0} -Online", helpParams);
142+
143+
psCommand.AddScript(script);
144+
145+
var result = await editorSession.powerShellContext.ExecuteCommand<object>(
146+
psCommand);
147+
148+
await requestContext.SendResult(null);
149+
}
150+
130151
protected Task HandleExitNotification(
131152
object exitParams,
132153
EditorSession editorSession,
@@ -144,7 +165,7 @@ protected Task HandleDidOpenTextDocumentNotification(
144165
{
145166
ScriptFile openedFile =
146167
editorSession.Workspace.GetFileBuffer(
147-
openParams.Uri,
168+
openParams.Uri,
148169
openParams.Text);
149170

150171
// TODO: Get all recently edited files in the workspace
@@ -210,7 +231,7 @@ protected async Task HandleDefinitionRequest(
210231
EditorSession editorSession,
211232
RequestContext<Location[], object> requestContext)
212233
{
213-
ScriptFile scriptFile =
234+
ScriptFile scriptFile =
214235
editorSession.Workspace.GetFile(
215236
textDocumentPosition.Uri);
216237

@@ -250,7 +271,7 @@ protected async Task HandleReferencesRequest(
250271
EditorSession editorSession,
251272
RequestContext<Location[], object> requestContext)
252273
{
253-
ScriptFile scriptFile =
274+
ScriptFile scriptFile =
254275
editorSession.Workspace.GetFile(
255276
referencesParams.Uri);
256277

@@ -298,7 +319,7 @@ protected async Task HandleCompletionRequest(
298319
int cursorLine = textDocumentPosition.Position.Line + 1;
299320
int cursorColumn = textDocumentPosition.Position.Character + 1;
300321

301-
ScriptFile scriptFile =
322+
ScriptFile scriptFile =
302323
editorSession.Workspace.GetFile(
303324
textDocumentPosition.Uri);
304325

@@ -309,7 +330,7 @@ await editorSession.LanguageService.GetCompletionsInFile(
309330
cursorColumn);
310331

311332
CompletionItem[] completionItems = null;
312-
333+
313334
if (completionResults != null)
314335
{
315336
// By default, insert the completion at the current location
@@ -344,8 +365,8 @@ await editorSession.LanguageService.GetCompletionsInFile(
344365
.Completions
345366
.Select(
346367
c => CreateCompletionItem(
347-
c,
348-
textDocumentPosition.Position.Line,
368+
c,
369+
textDocumentPosition.Position.Line,
349370
startEditColumn,
350371
endEditColumn))
351372
.ToArray();
@@ -369,9 +390,9 @@ protected async Task HandleCompletionResolveRequest(
369390
await editorSession.powerShellContext.GetRunspaceHandle();
370391

371392
// Get the documentation for the function
372-
CommandInfo commandInfo =
393+
CommandInfo commandInfo =
373394
CommandHelpers.GetCommandInfo(
374-
completionItem.Label,
395+
completionItem.Label,
375396
runspaceHandle.Runspace);
376397

377398
if (commandInfo != null)
@@ -394,7 +415,7 @@ protected async Task HandleSignatureHelpRequest(
394415
EditorSession editorSession,
395416
RequestContext<SignatureHelp, object> requestContext)
396417
{
397-
ScriptFile scriptFile =
418+
ScriptFile scriptFile =
398419
editorSession.Workspace.GetFile(
399420
textDocumentPosition.Uri);
400421

@@ -446,7 +467,7 @@ protected async Task HandleDocumentHighlightRequest(
446467
EditorSession editorSession,
447468
RequestContext<DocumentHighlight[], object> requestContext)
448469
{
449-
ScriptFile scriptFile =
470+
ScriptFile scriptFile =
450471
editorSession.Workspace.GetFile(
451472
textDocumentPosition.Uri);
452473

@@ -486,7 +507,7 @@ protected async Task HandleHoverRequest(
486507
EditorSession editorSession,
487508
RequestContext<Hover, object> requestContext)
488509
{
489-
ScriptFile scriptFile =
510+
ScriptFile scriptFile =
490511
editorSession.Workspace.GetFile(
491512
textDocumentPosition.Uri);
492513

@@ -553,12 +574,14 @@ protected async Task HandleDocumentSymbolRequest(
553574
symbols =
554575
foundSymbols
555576
.FoundOccurrences
556-
.Select(r =>
577+
.Select(r =>
557578
{
558-
return new SymbolInformation {
579+
return new SymbolInformation
580+
{
559581
ContainerName = containerName,
560582
Kind = GetSymbolKind(r.SymbolType),
561-
Location = new Location {
583+
Location = new Location
584+
{
562585
Uri = new Uri(r.FilePath).AbsolutePath,
563586
Range = GetRangeFromScriptRegion(r.ScriptRegion)
564587
},
@@ -625,13 +648,14 @@ protected async Task HandleWorkspaceSymbolRequest(
625648
foundSymbols
626649
.FoundOccurrences
627650
.Where(r => IsQueryMatch(workspaceSymbolParams.Query, r.SymbolName))
628-
.Select(r =>
651+
.Select(r =>
629652
{
630-
return new SymbolInformation
653+
return new SymbolInformation
631654
{
632655
ContainerName = containerName,
633656
Kind = r.SymbolType == SymbolType.Variable ? SymbolKind.Variable : SymbolKind.Function,
634-
Location = new Location {
657+
Location = new Location
658+
{
635659
Uri = new Uri(r.FilePath).AbsoluteUri,
636660
Range = GetRangeFromScriptRegion(r.ScriptRegion)
637661
},
@@ -717,7 +741,7 @@ private static FileChange GetFileChangeDetails(Range changeRange, string insertS
717741

718742
private Task RunScriptDiagnostics(
719743
ScriptFile[] filesToAnalyze,
720-
EditorSession editorSession,
744+
EditorSession editorSession,
721745
EventContext eventContext)
722746
{
723747
// If there's an existing task, attempt to cancel it
@@ -810,8 +834,8 @@ await eventContext.SendEvent(
810834
new PublishDiagnosticsNotification
811835
{
812836
Uri = scriptFile.ClientFilePath,
813-
Diagnostics =
814-
allMarkers
837+
Diagnostics =
838+
allMarkers
815839
.Select(GetDiagnosticFromMarker)
816840
.ToArray()
817841
});
@@ -867,9 +891,9 @@ private static CompletionItemKind MapCompletionKind(CompletionType completionTyp
867891
}
868892

869893
private static CompletionItem CreateCompletionItem(
870-
CompletionDetails completionDetails,
871-
int lineNumber,
872-
int startColumn,
894+
CompletionDetails completionDetails,
895+
int lineNumber,
896+
int startColumn,
873897
int endColumn)
874898
{
875899
string detailString = null;

src/PowerShellEditorServices.Host/PowerShellEditorServices.Host.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<WarningLevel>4</WarningLevel>
3737
</PropertyGroup>
3838
<ItemGroup>
39+
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" />
3940
<Reference Include="Nito.AsyncEx, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL">
4041
<HintPath>..\..\packages\Nito.AsyncEx.3.0.1\lib\net45\Nito.AsyncEx.dll</HintPath>
4142
<Private>True</Private>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
7+
8+
namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer
9+
{
10+
public class ShowOnlineHelpRequest
11+
{
12+
public static readonly RequestType<object, object, object> Type = RequestType<object, object, object>.Create("showonlinehelp");
13+
}
14+
}

src/PowerShellEditorServices.Protocol/PowerShellEditorServices.Protocol.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<Compile Include="LanguageServer\Definition.cs" />
9393
<Compile Include="LanguageServer\DocumentHighlight.cs" />
9494
<Compile Include="LanguageServer\Hover.cs" />
95+
<Compile Include="LanguageServer\ShowOnlineHelpRequest.cs" />
9596
<Compile Include="LanguageServer\SignatureHelp.cs" />
9697
<Compile Include="LanguageServer\WorkspaceSymbols.cs" />
9798
<Compile Include="MessageProtocol\EventContext.cs" />

0 commit comments

Comments
 (0)