Skip to content

Commit 451dcec

Browse files
committed
Merge pull request #167 from PowerShell/daviwil/handle-no-script-analyzer
Fix #166: Handle lack of Script Analyzer binaries
2 parents 5eb8ede + ded73de commit 451dcec

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

Diff for: src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

+16-6
Original file line numberDiff line numberDiff line change
@@ -891,11 +891,23 @@ private static async Task DelayThenInvokeDiagnostics(
891891
// Get the requested files
892892
foreach (ScriptFile scriptFile in filesToAnalyze)
893893
{
894-
Logger.Write(LogLevel.Verbose, "Analyzing script file: " + scriptFile.FilePath);
894+
ScriptFileMarker[] semanticMarkers = null;
895+
if (editorSession.AnalysisService != null)
896+
{
897+
Logger.Write(LogLevel.Verbose, "Analyzing script file: " + scriptFile.FilePath);
895898

896-
var semanticMarkers =
897-
editorSession.AnalysisService.GetSemanticMarkers(
898-
scriptFile);
899+
semanticMarkers =
900+
editorSession.AnalysisService.GetSemanticMarkers(
901+
scriptFile);
902+
903+
Logger.Write(LogLevel.Verbose, "Analysis complete.");
904+
}
905+
else
906+
{
907+
// Semantic markers aren't available if the AnalysisService
908+
// isn't available
909+
semanticMarkers = new ScriptFileMarker[0];
910+
}
899911

900912
var allMarkers = scriptFile.SyntaxMarkers.Concat(semanticMarkers);
901913

@@ -904,8 +916,6 @@ await PublishScriptDiagnostics(
904916
semanticMarkers,
905917
eventContext);
906918
}
907-
908-
Logger.Write(LogLevel.Verbose, "Analysis complete.");
909919
}
910920

911921
private static async Task PublishScriptDiagnostics(

Diff for: src/PowerShellEditorServices/Session/EditorSession.cs

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//
55

66
using Microsoft.PowerShell.EditorServices.Console;
7+
using Microsoft.PowerShell.EditorServices.Utility;
8+
using System.IO;
79
using System.Management.Automation;
810
using System.Management.Automation.Runspaces;
911
using System.Threading;
@@ -64,9 +66,21 @@ public void StartSession()
6466
// Initialize all services
6567
this.PowerShellContext = new PowerShellContext();
6668
this.LanguageService = new LanguageService(this.PowerShellContext);
67-
this.AnalysisService = new AnalysisService();
6869
this.DebugService = new DebugService(this.PowerShellContext);
6970
this.ConsoleService = new ConsoleService(this.PowerShellContext);
71+
72+
// AnalysisService will throw FileNotFoundException if
73+
// Script Analyzer binaries are not included.
74+
try
75+
{
76+
this.AnalysisService = new AnalysisService();
77+
}
78+
catch (FileNotFoundException)
79+
{
80+
Logger.Write(
81+
LogLevel.Warning,
82+
"Script Analyzer binaries not found, AnalysisService will be disabled.");
83+
}
7084
}
7185

7286
#endregion

0 commit comments

Comments
 (0)