Skip to content

Fix #166: Handle lack of Script Analyzer binaries #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,23 @@ private static async Task DelayThenInvokeDiagnostics(
// Get the requested files
foreach (ScriptFile scriptFile in filesToAnalyze)
{
Logger.Write(LogLevel.Verbose, "Analyzing script file: " + scriptFile.FilePath);
ScriptFileMarker[] semanticMarkers = null;
if (editorSession.AnalysisService != null)
{
Logger.Write(LogLevel.Verbose, "Analyzing script file: " + scriptFile.FilePath);

var semanticMarkers =
editorSession.AnalysisService.GetSemanticMarkers(
scriptFile);
semanticMarkers =
editorSession.AnalysisService.GetSemanticMarkers(
scriptFile);

Logger.Write(LogLevel.Verbose, "Analysis complete.");
}
else
{
// Semantic markers aren't available if the AnalysisService
// isn't available
semanticMarkers = new ScriptFileMarker[0];
}

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

Expand All @@ -904,8 +916,6 @@ await PublishScriptDiagnostics(
semanticMarkers,
eventContext);
}

Logger.Write(LogLevel.Verbose, "Analysis complete.");
}

private static async Task PublishScriptDiagnostics(
Expand Down
16 changes: 15 additions & 1 deletion src/PowerShellEditorServices/Session/EditorSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//

using Microsoft.PowerShell.EditorServices.Console;
using Microsoft.PowerShell.EditorServices.Utility;
using System.IO;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Threading;
Expand Down Expand Up @@ -64,9 +66,21 @@ public void StartSession()
// Initialize all services
this.PowerShellContext = new PowerShellContext();
this.LanguageService = new LanguageService(this.PowerShellContext);
this.AnalysisService = new AnalysisService();
this.DebugService = new DebugService(this.PowerShellContext);
this.ConsoleService = new ConsoleService(this.PowerShellContext);

// AnalysisService will throw FileNotFoundException if
// Script Analyzer binaries are not included.
try
{
this.AnalysisService = new AnalysisService();
}
catch (FileNotFoundException)
{
Logger.Write(
LogLevel.Warning,
"Script Analyzer binaries not found, AnalysisService will be disabled.");
}
}

#endregion
Expand Down