|
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | 4 | using System; |
| 5 | +using System.Collections.Concurrent; |
5 | 6 | using System.Collections.Generic; |
6 | | -using System.Linq; |
7 | 7 | using System.IO; |
| 8 | +using System.Linq; |
8 | 9 | using System.Security; |
9 | 10 | using System.Text; |
10 | 11 | using Microsoft.Extensions.FileSystemGlobbing; |
11 | 12 | using Microsoft.Extensions.Logging; |
12 | | -using Microsoft.PowerShell.EditorServices.Utility; |
13 | | -using Microsoft.PowerShell.EditorServices.Services.Workspace; |
14 | 13 | using Microsoft.PowerShell.EditorServices.Services.TextDocument; |
15 | | -using System.Collections.Concurrent; |
| 14 | +using Microsoft.PowerShell.EditorServices.Services.Workspace; |
| 15 | +using Microsoft.PowerShell.EditorServices.Utility; |
16 | 16 | using OmniSharp.Extensions.LanguageServer.Protocol; |
17 | 17 |
|
18 | 18 | namespace Microsoft.PowerShell.EditorServices.Services |
@@ -154,9 +154,16 @@ public ScriptFile GetFile(DocumentUri documentUri) |
154 | 154 | /// <param name="scriptFile">The out parameter that will contain the ScriptFile object.</param> |
155 | 155 | public bool TryGetFile(string filePath, out ScriptFile scriptFile) |
156 | 156 | { |
157 | | - scriptFile = null; |
158 | | - return Uri.IsWellFormedUriString(filePath, UriKind.RelativeOrAbsolute) |
159 | | - && TryGetFile(new Uri(filePath), out scriptFile); |
| 157 | + // This might not have been given a file path, in which case the Uri constructor barfs. |
| 158 | + try |
| 159 | + { |
| 160 | + return TryGetFile(new Uri(filePath), out scriptFile); |
| 161 | + } |
| 162 | + catch (UriFormatException) |
| 163 | + { |
| 164 | + scriptFile = null; |
| 165 | + return false; |
| 166 | + } |
160 | 167 | } |
161 | 168 |
|
162 | 169 | /// <summary> |
@@ -305,7 +312,7 @@ public ScriptFile[] ExpandScriptReferences(ScriptFile scriptFile) |
305 | 312 | referencedScriptFiles.Add(scriptFile.Id, scriptFile); |
306 | 313 | RecursivelyFindReferences(scriptFile, referencedScriptFiles); |
307 | 314 |
|
308 | | - // remove original file from referened file and add it as the first element of the |
| 315 | + // remove original file from referenced file and add it as the first element of the |
309 | 316 | // expanded referenced list to maintain order so the original file is always first in the list |
310 | 317 | referencedScriptFiles.Remove(scriptFile.Id); |
311 | 318 | expandedReferences.Add(scriptFile); |
|
0 commit comments