File tree 2 files changed +31
-7
lines changed
PowerShellEditorServices/Session
PowerShellEditorServices.Protocol/Server
2 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -891,11 +891,23 @@ private static async Task DelayThenInvokeDiagnostics(
891
891
// Get the requested files
892
892
foreach ( ScriptFile scriptFile in filesToAnalyze )
893
893
{
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 ) ;
895
898
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
+ }
899
911
900
912
var allMarkers = scriptFile . SyntaxMarkers . Concat ( semanticMarkers ) ;
901
913
@@ -904,8 +916,6 @@ await PublishScriptDiagnostics(
904
916
semanticMarkers ,
905
917
eventContext ) ;
906
918
}
907
-
908
- Logger . Write ( LogLevel . Verbose , "Analysis complete." ) ;
909
919
}
910
920
911
921
private static async Task PublishScriptDiagnostics (
Original file line number Diff line number Diff line change 4
4
//
5
5
6
6
using Microsoft . PowerShell . EditorServices . Console ;
7
+ using Microsoft . PowerShell . EditorServices . Utility ;
8
+ using System . IO ;
7
9
using System . Management . Automation ;
8
10
using System . Management . Automation . Runspaces ;
9
11
using System . Threading ;
@@ -64,9 +66,21 @@ public void StartSession()
64
66
// Initialize all services
65
67
this . PowerShellContext = new PowerShellContext ( ) ;
66
68
this . LanguageService = new LanguageService ( this . PowerShellContext ) ;
67
- this . AnalysisService = new AnalysisService ( ) ;
68
69
this . DebugService = new DebugService ( this . PowerShellContext ) ;
69
70
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
+ }
70
84
}
71
85
72
86
#endregion
You can’t perform that action at this time.
0 commit comments