|
21 | 21 | using System.Threading;
|
22 | 22 | using System.Threading.Tasks;
|
23 | 23 | using DebugAdapterMessages = Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter;
|
| 24 | +using System.Collections; |
24 | 25 |
|
25 | 26 | namespace Microsoft.PowerShell.EditorServices.Protocol.Server
|
26 | 27 | {
|
@@ -149,7 +150,7 @@ protected override void Initialize()
|
149 | 150 | this.SetRequestHandler(ScriptRegionRequest.Type, this.HandleGetFormatScriptRegionRequest);
|
150 | 151 |
|
151 | 152 | this.SetRequestHandler(GetPSHostProcessesRequest.Type, this.HandleGetPSHostProcessesRequest);
|
152 |
| - |
| 153 | + this.SetRequestHandler(CommentHelpRequest.Type, this.HandleCommentHelpRequest); |
153 | 154 | // Initialize the extension service
|
154 | 155 | // TODO: This should be made awaited once Initialize is async!
|
155 | 156 | this.editorSession.ExtensionService.Initialize(
|
@@ -243,9 +244,9 @@ private async Task HandleSetPSSARulesRequest(
|
243 | 244 | var ruleInfos = dynParams.ruleInfos;
|
244 | 245 | foreach (dynamic ruleInfo in ruleInfos)
|
245 | 246 | {
|
246 |
| - if ((Boolean) ruleInfo.isEnabled) |
| 247 | + if ((Boolean)ruleInfo.isEnabled) |
247 | 248 | {
|
248 |
| - activeRules.Add((string) ruleInfo.name); |
| 249 | + activeRules.Add((string)ruleInfo.name); |
249 | 250 | }
|
250 | 251 | }
|
251 | 252 | editorSession.AnalysisService.ActiveRules = activeRules.ToArray();
|
@@ -309,7 +310,8 @@ private async Task HandleScriptFileMarkersRequest(
|
309 | 310 | var markers = await editorSession.AnalysisService.GetSemanticMarkersAsync(
|
310 | 311 | editorSession.Workspace.GetFile(requestParams.fileUri),
|
311 | 312 | editorSession.AnalysisService.GetPSSASettingsHashtable(requestParams.settings));
|
312 |
| - await requestContext.SendResult(new ScriptFileMarkerRequestResultParams { |
| 313 | + await requestContext.SendResult(new ScriptFileMarkerRequestResultParams |
| 314 | + { |
313 | 315 | markers = markers
|
314 | 316 | });
|
315 | 317 | }
|
@@ -571,7 +573,7 @@ protected async Task HandleDidChangeConfigurationNotification(
|
571 | 573 | {
|
572 | 574 | bool oldLoadProfiles = this.currentSettings.EnableProfileLoading;
|
573 | 575 | bool oldScriptAnalysisEnabled =
|
574 |
| - this.currentSettings.ScriptAnalysis.Enable.HasValue ? this.currentSettings.ScriptAnalysis.Enable.Value : false ; |
| 576 | + this.currentSettings.ScriptAnalysis.Enable.HasValue ? this.currentSettings.ScriptAnalysis.Enable.Value : false; |
575 | 577 | string oldScriptAnalysisSettingsPath =
|
576 | 578 | this.currentSettings.ScriptAnalysis.SettingsPath;
|
577 | 579 |
|
@@ -1074,6 +1076,50 @@ protected async Task HandleGetPSHostProcessesRequest(
|
1074 | 1076 | await requestContext.SendResult(psHostProcesses.ToArray());
|
1075 | 1077 | }
|
1076 | 1078 |
|
| 1079 | + protected async Task HandleCommentHelpRequest( |
| 1080 | + CommentHelpRequestParams requestParams, |
| 1081 | + RequestContext<CommentHelpRequestResult> requestContext) |
| 1082 | + { |
| 1083 | + var scriptFile = EditorSession.Workspace.GetFile(requestParams.DocumentUri); |
| 1084 | + var expectedFunctionLine = requestParams.TriggerPosition.Line + 2; |
| 1085 | + var functionDefinitionAst = EditorSession.LanguageService.GetFunctionDefinitionAtLine( |
| 1086 | + scriptFile, |
| 1087 | + expectedFunctionLine); |
| 1088 | + var result = new CommentHelpRequestResult() |
| 1089 | + { |
| 1090 | + Content = new string[] { "" } |
| 1091 | + }; |
| 1092 | + |
| 1093 | + if (functionDefinitionAst != null) |
| 1094 | + { |
| 1095 | + var settings = new Dictionary<string, Hashtable>(); |
| 1096 | + var ruleSettings = new Hashtable(); |
| 1097 | + ruleSettings.Add("ExportedOnly", false); |
| 1098 | + ruleSettings.Add("Enable", true); |
| 1099 | + settings.Add("PSProvideCommentHelp", ruleSettings); |
| 1100 | + var pssaSettings = EditorSession.AnalysisService.GetPSSASettingsHashtable(settings); |
| 1101 | + |
| 1102 | + // todo create a semantic marker api that take only string |
| 1103 | + var analysisResults = await EditorSession.AnalysisService.GetSemanticMarkersAsync( |
| 1104 | + scriptFile, |
| 1105 | + pssaSettings); |
| 1106 | + |
| 1107 | + var analysisResult = analysisResults?.FirstOrDefault(x => |
| 1108 | + { |
| 1109 | + return x.Correction != null |
| 1110 | + && x.Correction.Edits[0].StartLineNumber == expectedFunctionLine; |
| 1111 | + }); |
| 1112 | + |
| 1113 | + if (analysisResult != null) |
| 1114 | + { |
| 1115 | + // find the analysis result whose correction starts on |
| 1116 | + result.Content = analysisResult.Correction.Edits[0].Text.Split('\n').Select(x => x.Trim('\r')).ToArray(); |
| 1117 | + } |
| 1118 | + } |
| 1119 | + |
| 1120 | + await requestContext.SendResult(result); |
| 1121 | + } |
| 1122 | + |
1077 | 1123 | private bool IsQueryMatch(string query, string symbolName)
|
1078 | 1124 | {
|
1079 | 1125 | return symbolName.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0;
|
@@ -1136,12 +1182,12 @@ protected Task HandleEvaluateRequest(
|
1136 | 1182 | // Return an empty result since the result value is irrelevant
|
1137 | 1183 | // for this request in the LanguageServer
|
1138 | 1184 | return
|
1139 |
| - requestContext.SendResult( |
1140 |
| - new DebugAdapterMessages.EvaluateResponseBody |
1141 |
| - { |
1142 |
| - Result = "", |
1143 |
| - VariablesReference = 0 |
1144 |
| - }); |
| 1185 | + requestContext.SendResult( |
| 1186 | + new DebugAdapterMessages.EvaluateResponseBody |
| 1187 | + { |
| 1188 | + Result = "", |
| 1189 | + VariablesReference = 0 |
| 1190 | + }); |
1145 | 1191 | });
|
1146 | 1192 |
|
1147 | 1193 | return Task.FromResult(true);
|
|
0 commit comments