File tree Expand file tree Collapse file tree 2 files changed +31
-7
lines changed
PowerShellEditorServices.Protocol/Server
PowerShellEditorServices/Session Expand file tree Collapse file tree 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(
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 (
Original file line number Diff line number Diff line change 44//
55
66using Microsoft . PowerShell . EditorServices . Console ;
7+ using Microsoft . PowerShell . EditorServices . Utility ;
8+ using System . IO ;
79using System . Management . Automation ;
810using System . Management . Automation . Runspaces ;
911using 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
You can’t perform that action at this time.
0 commit comments