Skip to content

Commit e307480

Browse files
committed
Merge pull request #4 from PowerShell/kaylad/language-features
Introduce new language service features
2 parents 755a7a9 + e8d9c5e commit e307480

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2290
-96
lines changed

.gitignore

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ ClientBin/
4343
*.build.csdef
4444
csx/
4545

46-
# Temporarily exclude files generated by Script Analyzer build
47-
PSLanguageService/Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll
48-
PSLanguageService/Microsoft.Windows.PowerShell.ScriptAnalyzer.dll
49-
PSLanguageService/PSScriptAnalyzer.psd1
50-
PSLanguageService/ScriptAnalyzer.format.ps1xml
51-
PSLanguageService/ScriptAnalyzer.types.ps1xml
46+
# Don't include ScriptAnalyzer binaries
47+
PowerShellEditorServices/Microsoft.Windows.PowerShell.ScriptAnalyzer.dll
48+
PowerShellEditorServices/Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll
49+
PowerShellEditorServices/PSScriptAnalyzer.psd1
50+
PowerShellEditorServices/ScriptAnalyzer.format.ps1xml
51+
PowerShellEditorServices/ScriptAnalyzer.types.ps1xml
52+

src/PowerShellEditorServices.Transport.Stdio/Message/MessageParser.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6+
67
using Microsoft.PowerShell.EditorServices.Utility;
78
using Newtonsoft.Json;
89
using Newtonsoft.Json.Linq;

src/PowerShellEditorServices.Transport.Stdio/PowerShellEditorServices.Transport.Stdio.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,23 @@
7979
<Compile Include="Message\MessageWriter.cs" />
8080
<Compile Include="Properties\AssemblyInfo.cs" />
8181
<Compile Include="Request\ChangeFileRequest.cs" />
82+
<Compile Include="Request\CompletionDetailsRequest.cs" />
8283
<Compile Include="Request\CompletionsRequest.cs" />
84+
<Compile Include="Request\DeclarationRequest.cs" />
8385
<Compile Include="Request\ErrorRequest.cs" />
8486
<Compile Include="Request\FileRequest.cs" />
87+
<Compile Include="Request\OccurrencesRequest.cs" />
8588
<Compile Include="Request\OpenFileRequest.cs" />
89+
<Compile Include="Request\ReferencesRequest.cs" />
8690
<Compile Include="Request\ReplExecuteRequest.cs" />
8791
<Compile Include="Request\RequestBase.cs" />
92+
<Compile Include="Response\CompletionDetailsResponse.cs" />
93+
<Compile Include="Response\DefinitionResponse.cs" />
94+
<Compile Include="Response\LocationResponseElements.cs" />
95+
<Compile Include="Response\OccurrencesResponse.cs" />
96+
<Compile Include="Response\ReferencesResponse.cs" />
97+
<Compile Include="Response\SignatureHelpResponse.cs" />
98+
<Compile Include="Request\SignatureHelpRequest.cs" />
8899
<Compile Include="Response\CompletionsResponse.cs" />
89100
<Compile Include="Response\MessageErrorResponse.cs" />
90101
<Compile Include="Response\ReplPromptChoiceResponse.cs" />
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.Language;
7+
using Microsoft.PowerShell.EditorServices.Session;
8+
using Microsoft.PowerShell.EditorServices.Transport.Stdio.Message;
9+
using Microsoft.PowerShell.EditorServices.Transport.Stdio.Response;
10+
using System.Collections.Generic;
11+
12+
namespace Microsoft.PowerShell.EditorServices.Transport.Stdio.Request
13+
{
14+
[MessageTypeName("completionEntryDetails")]
15+
public class CompletionDetailsRequest : FileRequest<CompletionDetailsRequestArgs>
16+
{
17+
public override void ProcessMessage(
18+
EditorSession editorSession,
19+
MessageWriter messageWriter)
20+
{
21+
ScriptFile scriptFile = this.GetScriptFile(editorSession);
22+
23+
CompletionDetails completionDetails =
24+
editorSession.LanguageService.GetCompletionDetailsInFile(
25+
scriptFile,
26+
this.Arguments.Line,
27+
this.Arguments.Offset,
28+
this.Arguments.EntryNames[0]);
29+
30+
var details = new List<CompletionEntryDetails>();
31+
if (completionDetails != null)
32+
{
33+
details.Add(
34+
new CompletionEntryDetails(completionDetails, this.Arguments.EntryNames[0]
35+
));
36+
messageWriter.WriteMessage(
37+
this.PrepareResponse(
38+
new CompletionDetailsResponse
39+
{
40+
Body = details.ToArray()
41+
}));
42+
}
43+
else
44+
{
45+
messageWriter.WriteMessage(
46+
this.PrepareResponse(
47+
new CompletionDetailsResponse{
48+
Body = details.ToArray()
49+
}));
50+
}
51+
}
52+
}
53+
54+
public class CompletionDetailsRequestArgs : FileLocationRequestArgs
55+
{
56+
public string[] EntryNames { get; set; }
57+
}
58+
59+
}

src/PowerShellEditorServices.Transport.Stdio/Request/CompletionsRequest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public override void ProcessMessage(
3131
completions)));
3232
}
3333
}
34-
3534
public class CompletionsRequestArgs : FileLocationRequestArgs
3635
{
3736
public string Prefix { get; set; }
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.Language;
7+
using Microsoft.PowerShell.EditorServices.Session;
8+
using Microsoft.PowerShell.EditorServices.Transport.Stdio.Message;
9+
using Microsoft.PowerShell.EditorServices.Transport.Stdio.Response;
10+
11+
namespace Microsoft.PowerShell.EditorServices.Transport.Stdio.Request
12+
{
13+
[MessageTypeName("definition")]
14+
public class DeclarationRequest : FileRequest<FileLocationRequestArgs>
15+
{
16+
public override void ProcessMessage(
17+
EditorSession editorSession,
18+
MessageWriter messageWriter)
19+
{
20+
ScriptFile scriptFile = this.GetScriptFile(editorSession);
21+
22+
GetDefinitionResult definition =
23+
editorSession.LanguageService.GetDefinitionInFile(
24+
scriptFile,
25+
this.Arguments.Line,
26+
this.Arguments.Offset);
27+
28+
if (definition != null)
29+
{
30+
DefinitionResponse defResponse =
31+
DefinitionResponse.Create(definition.FoundDefinition, this.Arguments.File);
32+
33+
messageWriter.WriteMessage(
34+
this.PrepareResponse(defResponse));
35+
}
36+
}
37+
}
38+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.Language;
7+
using Microsoft.PowerShell.EditorServices.Session;
8+
using Microsoft.PowerShell.EditorServices.Transport.Stdio.Message;
9+
using Microsoft.PowerShell.EditorServices.Transport.Stdio.Response;
10+
11+
namespace Microsoft.PowerShell.EditorServices.Transport.Stdio.Request
12+
{
13+
[MessageTypeName("occurrences")]
14+
public class OccurrencesRequest : FileRequest<FileLocationRequestArgs>
15+
{
16+
public override void ProcessMessage(
17+
EditorSession editorSession,
18+
MessageWriter messageWriter)
19+
{
20+
ScriptFile scriptFile = this.GetScriptFile(editorSession);
21+
22+
FindOccurrencesResult occurrencesResult =
23+
editorSession.LanguageService.FindOccurrencesInFile(
24+
scriptFile,
25+
this.Arguments.Line,
26+
this.Arguments.Offset);
27+
28+
OccurrencesResponse occurrencesResponce =
29+
OccurrencesResponse.Create(occurrencesResult, this.Arguments.File);
30+
31+
messageWriter.WriteMessage(
32+
this.PrepareResponse(
33+
occurrencesResponce));
34+
}
35+
}
36+
}

src/PowerShellEditorServices.Transport.Stdio/Request/OpenFileRequest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using Microsoft.PowerShell.EditorServices.Session;
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.Session;
27
using Microsoft.PowerShell.EditorServices.Transport.Stdio.Message;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
88

99
namespace Microsoft.PowerShell.EditorServices.Transport.Stdio.Request
1010
{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.Language;
7+
using Microsoft.PowerShell.EditorServices.Session;
8+
using Microsoft.PowerShell.EditorServices.Transport.Stdio.Message;
9+
using Microsoft.PowerShell.EditorServices.Transport.Stdio.Response;
10+
11+
namespace Microsoft.PowerShell.EditorServices.Transport.Stdio.Request
12+
{
13+
[MessageTypeName("references")]
14+
public class ReferencesRequest : FileRequest<FileLocationRequestArgs>
15+
{
16+
public override void ProcessMessage(
17+
EditorSession editorSession,
18+
MessageWriter messageWriter)
19+
{
20+
ScriptFile scriptFile = this.GetScriptFile(editorSession);
21+
22+
FindReferencesResult referencesResult =
23+
editorSession.LanguageService.FindReferencesInFile(
24+
scriptFile,
25+
this.Arguments.Line,
26+
this.Arguments.Offset);
27+
28+
ReferencesResponse referencesResponse =
29+
ReferencesResponse.Create(referencesResult, this.Arguments.File);
30+
31+
messageWriter.WriteMessage(
32+
this.PrepareResponse(
33+
referencesResponse));
34+
}
35+
}
36+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.Language;
7+
using Microsoft.PowerShell.EditorServices.Session;
8+
using Microsoft.PowerShell.EditorServices.Transport.Stdio.Message;
9+
using Microsoft.PowerShell.EditorServices.Transport.Stdio.Response;
10+
11+
namespace Microsoft.PowerShell.EditorServices.Transport.Stdio.Request
12+
{
13+
[MessageTypeName("signatureHelp")]
14+
public class SignatureHelpRequest : FileRequest<SignatureHelpRequestArgs>
15+
{
16+
public override void ProcessMessage(
17+
EditorSession editorSession,
18+
MessageWriter messageWriter)
19+
{
20+
ScriptFile scriptFile = this.GetScriptFile(editorSession);
21+
22+
ParameterSetSignatures parameterSetSigs =
23+
editorSession.LanguageService.FindParameterSetsInFile(
24+
scriptFile,
25+
this.Arguments.Line,
26+
this.Arguments.Offset);
27+
28+
SignatureHelpResponse sigHelpResponce =
29+
SignatureHelpResponse.Create(parameterSetSigs);
30+
31+
messageWriter.WriteMessage(
32+
this.PrepareResponse(
33+
sigHelpResponce));
34+
}
35+
}
36+
37+
public class SignatureHelpRequestArgs : FileLocationRequestArgs
38+
{
39+
}
40+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.Language;
7+
using Microsoft.PowerShell.EditorServices.Transport.Stdio.Message;
8+
using System.Text.RegularExpressions;
9+
10+
namespace Microsoft.PowerShell.EditorServices.Transport.Stdio.Response
11+
{
12+
[MessageTypeName("completionEntryDetails")]
13+
public class CompletionDetailsResponse : ResponseBase<CompletionEntryDetails[]>
14+
{
15+
}
16+
17+
public class CompletionEntryDetails
18+
{
19+
public CompletionEntryDetails(CompletionDetails completionResult, string entryName)
20+
{
21+
22+
Kind = null;
23+
KindModifiers = null;
24+
DisplayParts = null;
25+
Documentation = null;
26+
DocString = null;
27+
28+
// if the result type is a command return null
29+
if (completionResult != null &&
30+
!(completionResult.CompletionType.Equals(CompletionType.Command)))
31+
{
32+
//find matches on square brackets in the the tool tip
33+
var matches =
34+
Regex.Matches(completionResult.ToolTipText, @"^\[(.+)\]");
35+
string strippedEntryName =
36+
Regex.Replace(entryName, @"^[$_-]", "").Replace("{", "").Replace("}", "");
37+
38+
if (matches.Count > 0 && matches[0].Groups.Count > 1)
39+
{
40+
Name = matches[0].Groups[1].Value;
41+
}
42+
// if there are nobracets and the only content is the completion name
43+
else if (completionResult.ToolTipText.Equals(strippedEntryName))
44+
{
45+
Name = null;
46+
}
47+
else
48+
{
49+
Name = null;
50+
DocString = completionResult.ToolTipText;
51+
}
52+
}
53+
54+
else { Name = null; }
55+
}
56+
public string Name { get; set; }
57+
58+
public string Kind { get; set; }
59+
60+
public string KindModifiers { get; set; }
61+
62+
public SymbolDisplayPart[] DisplayParts { get; set; }
63+
64+
public SymbolDisplayPart[] Documentation { get; set; }
65+
66+
public string DocString { get; set; }
67+
68+
}
69+
70+
public class SymbolDisplayPart
71+
{
72+
public string Text { get; set; }
73+
74+
public string Kind { get; set; }
75+
}
76+
}

src/PowerShellEditorServices.Transport.Stdio/Response/CompletionsResponse.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,15 @@ private static string GetCompletionKind(CompletionType completionType)
4545
}
4646
}
4747
}
48+
public class CompletionEntry
49+
{
50+
public string Name { get; set; }
51+
52+
public string Kind { get; set; }
53+
54+
public string KindModifiers { get; set; }
55+
56+
public string SortText { get; set; }
57+
}
58+
4859
}

0 commit comments

Comments
 (0)