Skip to content

Prevent some exceptions #1500

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 7 commits into from
Jun 16, 2021
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
2 changes: 1 addition & 1 deletion PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ namespace Microsoft.PowerShell.EditorServices.Hosting
{
public static readonly string BuildVersion = "$buildVersion";
public static readonly string BuildOrigin = "$buildOrigin";
public static readonly string BuildCommit= "$buildCommit";
public static readonly string BuildCommit = "$buildCommit";
public static readonly System.DateTime? BuildTime = System.DateTime.Parse("$buildTime", CultureInfo.InvariantCulture.DateTimeFormat);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/PowerShellEditorServices.Hosting/BuildInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ namespace Microsoft.PowerShell.EditorServices.Hosting
{
public static class BuildInfo
{
// TODO: Include a Git commit hash in this.
public static readonly string BuildVersion = "<development-build>";
public static readonly string BuildOrigin = "<development>";
public static readonly string BuildCommit= "<development>";
public static readonly string BuildCommit = "<development>";
public static readonly System.DateTime? BuildTime = System.DateTime.Parse("2019-12-06T21:43:41", CultureInfo.InvariantCulture.DateTimeFormat);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ private void LogHostInformation()
== Build Details ==
- Editor Services version: {BuildInfo.BuildVersion}
- Build origin: {BuildInfo.BuildOrigin}
- Build commit: {BuildInfo.BuildCommit}
- Build time: {BuildInfo.BuildTime}
");

Expand Down
2 changes: 1 addition & 1 deletion src/PowerShellEditorServices/Extensions/EditorObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public EditorContext GetEditorContext()
internal void SetAsStaticInstance()
{
EditorObject.Instance = this;
s_editorObjectReady.SetResult(true);
s_editorObjectReady.TrySetResult(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ internal static string GetUniqueIdFromDiagnostic(Diagnostic diagnostic)

private readonly ConfigurationService _configurationService;

private readonly WorkspaceService _workplaceService;
private readonly WorkspaceService _workspaceService;

private readonly int _analysisDelayMillis;

Expand Down Expand Up @@ -115,7 +115,7 @@ public AnalysisService(
_logger = loggerFactory.CreateLogger<AnalysisService>();
_languageServer = languageServer;
_configurationService = configurationService;
_workplaceService = workspaceService;
_workspaceService = workspaceService;
_analysisDelayMillis = 750;
_mostRecentCorrectionsByFile = new ConcurrentDictionary<ScriptFile, CorrectionTableEntry>();
_analysisEngineLazy = new Lazy<PssaCmdletAnalysisEngine>(InstantiateAnalysisEngine);
Expand Down Expand Up @@ -223,9 +223,10 @@ public async Task<string> GetCommentHelpText(string functionText, string helpLoc
/// </summary>
/// <param name="documentUri">The URI string of the file to get code actions for.</param>
/// <returns>A threadsafe readonly dictionary of the code actions of the particular file.</returns>
public async Task<IReadOnlyDictionary<string, MarkerCorrection>> GetMostRecentCodeActionsForFileAsync(ScriptFile scriptFile)
public async Task<IReadOnlyDictionary<string, MarkerCorrection>> GetMostRecentCodeActionsForFileAsync(DocumentUri uri)
{
if (!_mostRecentCorrectionsByFile.TryGetValue(scriptFile, out CorrectionTableEntry corrections))
if (!_workspaceService.TryGetFile(uri, out ScriptFile file)
|| !_mostRecentCorrectionsByFile.TryGetValue(file, out CorrectionTableEntry corrections))
{
return null;
}
Expand Down Expand Up @@ -334,7 +335,7 @@ private bool TryFindSettingsFile(out string settingsFilePath)
return false;
}

settingsFilePath = _workplaceService.ResolveWorkspacePath(configuredPath);
settingsFilePath = _workspaceService.ResolveWorkspacePath(configuredPath);

if (settingsFilePath == null
|| !File.Exists(settingsFilePath))
Expand All @@ -349,7 +350,7 @@ private bool TryFindSettingsFile(out string settingsFilePath)

private void ClearOpenFileMarkers()
{
foreach (ScriptFile file in _workplaceService.GetOpenedFiles())
foreach (ScriptFile file in _workspaceService.GetOpenedFiles())
{
ClearMarkers(file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public override async Task<CommandOrCodeActionContainer> Handle(CodeActionParams
{
if (cancellationToken.IsCancellationRequested)
{
_logger.LogDebug("CodeAction request canceled at range: {0}", request.Range);
_logger.LogDebug($"CodeAction request canceled at range: {request.Range}");
return Array.Empty<CommandOrCodeAction>();
}

// On Windows, VSCode still gives us file URIs like "file:///c%3a/...", so we need to escape them
IReadOnlyDictionary<string, MarkerCorrection> corrections = await _analysisService.GetMostRecentCodeActionsForFileAsync(
_workspaceService.GetFile(request.TextDocument.Uri)).ConfigureAwait(false);
request.TextDocument.Uri)
.ConfigureAwait(false);

if (corrections == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ await _powerShellContextService.SetWorkingDirectoryAsync(

private void SendFeatureChangesTelemetry(LanguageServerSettingsWrapper incomingSettings)
{
if (incomingSettings is null)
{
this._logger.LogTrace("Incoming settings were null");
return;
}

var configChanges = new Dictionary<string, bool>();
// Send telemetry if the user opted-out of ScriptAnalysis
if (incomingSettings.Powershell.ScriptAnalysis.Enable == false &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public bool TryGetFile(DocumentUri documentUri, out ScriptFile scriptFile)
{
// List supported schemes here
case "file":
case "inmemory":
case "untitled":
case "vscode-notebook-cell":
break;
Expand Down