Skip to content

Commit f5006ae

Browse files
Merge pull request #1500 from PowerShell/andschwa/fixes
Prevent some exceptions
2 parents 6e3365b + f917e9b commit f5006ae

File tree

8 files changed

+21
-13
lines changed

8 files changed

+21
-13
lines changed

PowerShellEditorServices.build.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ namespace Microsoft.PowerShell.EditorServices.Hosting
216216
{
217217
public static readonly string BuildVersion = "$buildVersion";
218218
public static readonly string BuildOrigin = "$buildOrigin";
219-
public static readonly string BuildCommit= "$buildCommit";
219+
public static readonly string BuildCommit = "$buildCommit";
220220
public static readonly System.DateTime? BuildTime = System.DateTime.Parse("$buildTime", CultureInfo.InvariantCulture.DateTimeFormat);
221221
}
222222
}

src/PowerShellEditorServices.Hosting/BuildInfo.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ namespace Microsoft.PowerShell.EditorServices.Hosting
44
{
55
public static class BuildInfo
66
{
7-
// TODO: Include a Git commit hash in this.
87
public static readonly string BuildVersion = "<development-build>";
98
public static readonly string BuildOrigin = "<development>";
10-
public static readonly string BuildCommit= "<development>";
9+
public static readonly string BuildCommit = "<development>";
1110
public static readonly System.DateTime? BuildTime = System.DateTime.Parse("2019-12-06T21:43:41", CultureInfo.InvariantCulture.DateTimeFormat);
1211
}
1312
}

src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ private void LogHostInformation()
269269
== Build Details ==
270270
- Editor Services version: {BuildInfo.BuildVersion}
271271
- Build origin: {BuildInfo.BuildOrigin}
272+
- Build commit: {BuildInfo.BuildCommit}
272273
- Build time: {BuildInfo.BuildTime}
273274
");
274275

src/PowerShellEditorServices/Extensions/EditorObject.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public EditorContext GetEditorContext()
137137
internal void SetAsStaticInstance()
138138
{
139139
EditorObject.Instance = this;
140-
s_editorObjectReady.SetResult(true);
140+
s_editorObjectReady.TrySetResult(true);
141141
}
142142
}
143143
}

src/PowerShellEditorServices/Services/Analysis/AnalysisService.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ internal static string GetUniqueIdFromDiagnostic(Diagnostic diagnostic)
8686

8787
private readonly ConfigurationService _configurationService;
8888

89-
private readonly WorkspaceService _workplaceService;
89+
private readonly WorkspaceService _workspaceService;
9090

9191
private readonly int _analysisDelayMillis;
9292

@@ -115,7 +115,7 @@ public AnalysisService(
115115
_logger = loggerFactory.CreateLogger<AnalysisService>();
116116
_languageServer = languageServer;
117117
_configurationService = configurationService;
118-
_workplaceService = workspaceService;
118+
_workspaceService = workspaceService;
119119
_analysisDelayMillis = 750;
120120
_mostRecentCorrectionsByFile = new ConcurrentDictionary<ScriptFile, CorrectionTableEntry>();
121121
_analysisEngineLazy = new Lazy<PssaCmdletAnalysisEngine>(InstantiateAnalysisEngine);
@@ -223,9 +223,10 @@ public async Task<string> GetCommentHelpText(string functionText, string helpLoc
223223
/// </summary>
224224
/// <param name="documentUri">The URI string of the file to get code actions for.</param>
225225
/// <returns>A threadsafe readonly dictionary of the code actions of the particular file.</returns>
226-
public async Task<IReadOnlyDictionary<string, MarkerCorrection>> GetMostRecentCodeActionsForFileAsync(ScriptFile scriptFile)
226+
public async Task<IReadOnlyDictionary<string, MarkerCorrection>> GetMostRecentCodeActionsForFileAsync(DocumentUri uri)
227227
{
228-
if (!_mostRecentCorrectionsByFile.TryGetValue(scriptFile, out CorrectionTableEntry corrections))
228+
if (!_workspaceService.TryGetFile(uri, out ScriptFile file)
229+
|| !_mostRecentCorrectionsByFile.TryGetValue(file, out CorrectionTableEntry corrections))
229230
{
230231
return null;
231232
}
@@ -334,7 +335,7 @@ private bool TryFindSettingsFile(out string settingsFilePath)
334335
return false;
335336
}
336337

337-
settingsFilePath = _workplaceService.ResolveWorkspacePath(configuredPath);
338+
settingsFilePath = _workspaceService.ResolveWorkspacePath(configuredPath);
338339

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

350351
private void ClearOpenFileMarkers()
351352
{
352-
foreach (ScriptFile file in _workplaceService.GetOpenedFiles())
353+
foreach (ScriptFile file in _workspaceService.GetOpenedFiles())
353354
{
354355
ClearMarkers(file);
355356
}

src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeActionHandler.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ public override async Task<CommandOrCodeActionContainer> Handle(CodeActionParams
5252
{
5353
if (cancellationToken.IsCancellationRequested)
5454
{
55-
_logger.LogDebug("CodeAction request canceled at range: {0}", request.Range);
55+
_logger.LogDebug($"CodeAction request canceled at range: {request.Range}");
5656
return Array.Empty<CommandOrCodeAction>();
5757
}
5858

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

6363
if (corrections == null)
6464
{

src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs

+6
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ await _powerShellContextService.SetWorkingDirectoryAsync(
156156

157157
private void SendFeatureChangesTelemetry(LanguageServerSettingsWrapper incomingSettings)
158158
{
159+
if (incomingSettings is null)
160+
{
161+
this._logger.LogTrace("Incoming settings were null");
162+
return;
163+
}
164+
159165
var configChanges = new Dictionary<string, bool>();
160166
// Send telemetry if the user opted-out of ScriptAnalysis
161167
if (incomingSettings.Powershell.ScriptAnalysis.Enable == false &&

src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ public bool TryGetFile(DocumentUri documentUri, out ScriptFile scriptFile)
192192
{
193193
// List supported schemes here
194194
case "file":
195+
case "inmemory":
195196
case "untitled":
196197
case "vscode-notebook-cell":
197198
break;

0 commit comments

Comments
 (0)