Skip to content

Commit 63b2143

Browse files
committed
Remove notion of ReferencedFiles
This has been unused and sometimes broken, it doesn't actually power any useful features.
1 parent 5776d20 commit 63b2143

File tree

7 files changed

+3
-159
lines changed

7 files changed

+3
-159
lines changed

src/PowerShellEditorServices/Services/CodeLens/ReferencesCodeLensProvider.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,14 @@ public async Task<CodeLens> ResolveCodeLens(
9797
ScriptFile scriptFile,
9898
CancellationToken cancellationToken)
9999
{
100-
ScriptFile[] references = _workspaceService.ExpandScriptReferences(scriptFile);
101-
102100
SymbolReference foundSymbol = SymbolsService.FindSymbolDefinitionAtLocation(
103101
scriptFile,
104102
codeLens.Range.Start.Line + 1,
105103
codeLens.Range.Start.Character + 1);
106104

107105
IEnumerable<SymbolReference> referencesResult =
108106
await _symbolsService.ScanForReferencesOfSymbol(
109-
foundSymbol,
110-
references,
111-
cancellationToken).ConfigureAwait(false);
107+
foundSymbol, cancellationToken).ConfigureAwait(false);
112108

113109
Location[] referenceLocations;
114110
if (referencesResult == null)

src/PowerShellEditorServices/Services/Symbols/SymbolsService.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
using System;
55
using System.Collections.Concurrent;
66
using System.Collections.Generic;
7-
using System.Collections.Specialized;
87
using System.Linq;
98
using System.Management.Automation;
109
using System.Management.Automation.Language;
11-
using System.Runtime.InteropServices;
1210
using System.Threading;
1311
using System.Threading.Tasks;
1412
using Microsoft.Extensions.Logging;
@@ -154,12 +152,10 @@ public static SymbolReference FindSymbolAtLocation(
154152
/// Finds all the references of a symbol (excluding definitions)
155153
/// </summary>
156154
/// <param name="foundSymbol">The symbol to find all references for</param>
157-
/// <param name="referencedFiles">An array of scriptFiles to search for references in</param>
158155
/// <param name="cancellationToken"></param>
159156
/// <returns>FindReferencesResult</returns>
160157
public async Task<IEnumerable<SymbolReference>> ScanForReferencesOfSymbol(
161158
SymbolReference foundSymbol,
162-
ScriptFile[] referencedFiles,
163159
CancellationToken cancellationToken = default)
164160
{
165161
if (foundSymbol == null)
@@ -182,21 +178,6 @@ public async Task<IEnumerable<SymbolReference>> ScanForReferencesOfSymbol(
182178
}
183179
}
184180

185-
// TODO: This is entirely unused, but we actually DO want to search first the file, then
186-
// its referenced files, then everything else!
187-
//
188-
// We want to look for references first in referenced files, hence we use ordered
189-
// dictionary TODO: File system case-sensitivity is based on filesystem not OS, but OS
190-
// is a much cheaper heuristic
191-
OrderedDictionary fileMap = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
192-
? new OrderedDictionary()
193-
: new OrderedDictionary(StringComparer.OrdinalIgnoreCase);
194-
195-
foreach (ScriptFile scriptFile in referencedFiles)
196-
{
197-
fileMap[scriptFile.FilePath] = scriptFile;
198-
}
199-
200181
await ScanWorkspacePSFiles(cancellationToken).ConfigureAwait(false);
201182

202183
List<SymbolReference> symbolReferences = new();
@@ -419,7 +400,6 @@ public async Task<IEnumerable<SymbolReference>> GetDefinitionOfSymbolAsync(
419400

420401
IEnumerable<SymbolReference> allSymbols = await ScanForReferencesOfSymbol(
421402
symbol,
422-
_workspaceService.ExpandScriptReferences(file),
423403
cancellationToken).ConfigureAwait(false);
424404

425405
IEnumerable<SymbolReference> possibleDeclarations = allSymbols.Where((i) => i.IsDeclaration);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ public override async Task<LocationContainer> Handle(ReferenceParams request, Ca
4343

4444
IEnumerable<SymbolReference> referencesResult =
4545
await _symbolsService.ScanForReferencesOfSymbol(
46-
foundSymbol,
47-
_workspaceService.ExpandScriptReferences(scriptFile),
48-
cancellationToken).ConfigureAwait(false);
46+
foundSymbol, cancellationToken).ConfigureAwait(false);
4947

5048
if (referencesResult is null)
5149
{

src/PowerShellEditorServices/Services/TextDocument/ScriptFile.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Linq;
88
using System.Management.Automation;
99
using System.Management.Automation.Language;
10-
using Microsoft.PowerShell.EditorServices.Services.Symbols;
1110
using Microsoft.PowerShell.EditorServices.Utility;
1211
using OmniSharp.Extensions.LanguageServer.Protocol;
1312

@@ -111,15 +110,6 @@ public Token[] ScriptTokens
111110
private set;
112111
}
113112

114-
/// <summary>
115-
/// Gets the array of filepaths dot sourced in this ScriptFile
116-
/// </summary>
117-
public string[] ReferencedFiles
118-
{
119-
get;
120-
private set;
121-
}
122-
123113
internal ReferenceTable References { get; }
124114

125115
internal bool IsOpen { get; set; }
@@ -600,21 +590,6 @@ private void ParseFileContents()
600590
parseErrors
601591
.Select(ScriptFileMarker.FromParseError)
602592
.ToList();
603-
604-
// Untitled files have no directory
605-
// Discussed in https://github.com/PowerShell/PowerShellEditorServices/pull/815.
606-
// Rather than working hard to enable things for untitled files like a phantom directory,
607-
// users should save the file.
608-
if (IsInMemory)
609-
{
610-
// Need to initialize the ReferencedFiles property to an empty array.
611-
ReferencedFiles = Array.Empty<string>();
612-
return;
613-
}
614-
615-
// Get all dot sourced referenced files and store them
616-
// TODO: We're considering removing this notion.
617-
ReferencedFiles = AstOperations.FindDotSourcedIncludes(ScriptAst, Path.GetDirectoryName(FilePath));
618593
}
619594

620595
#endregion

src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -292,35 +292,6 @@ public void CloseFile(ScriptFile scriptFile)
292292
workspaceFiles.TryRemove(keyName, out ScriptFile _);
293293
}
294294

295-
/// <summary>
296-
/// Gets all file references by recursively searching
297-
/// through referenced files in a scriptfile
298-
/// </summary>
299-
/// <param name="scriptFile">Contains the details and contents of an open script file</param>
300-
/// <returns>A scriptfile array where the first file
301-
/// in the array is the "root file" of the search</returns>
302-
public ScriptFile[] ExpandScriptReferences(ScriptFile scriptFile)
303-
{
304-
Dictionary<string, ScriptFile> referencedScriptFiles = new();
305-
List<ScriptFile> expandedReferences = new();
306-
307-
// add original file so it's not searched for, then find all file references
308-
referencedScriptFiles.Add(scriptFile.Id, scriptFile);
309-
RecursivelyFindReferences(scriptFile, referencedScriptFiles);
310-
311-
// remove original file from referenced file and add it as the first element of the
312-
// expanded referenced list to maintain order so the original file is always first in the list
313-
referencedScriptFiles.Remove(scriptFile.Id);
314-
expandedReferences.Add(scriptFile);
315-
316-
if (referencedScriptFiles.Count > 0)
317-
{
318-
expandedReferences.AddRange(referencedScriptFiles.Values);
319-
}
320-
321-
return expandedReferences.ToArray();
322-
}
323-
324295
/// <summary>
325296
/// Gets the workspace-relative path of the given file path.
326297
/// </summary>
@@ -401,54 +372,6 @@ bool ignoreReparsePoints
401372
#endregion
402373

403374
#region Private Methods
404-
/// <summary>
405-
/// Recursively searches through referencedFiles in scriptFiles
406-
/// and builds a Dictionary of the file references
407-
/// </summary>
408-
/// <param name="scriptFile">Details an contents of "root" script file</param>
409-
/// <param name="referencedScriptFiles">A Dictionary of referenced script files</param>
410-
private void RecursivelyFindReferences(
411-
ScriptFile scriptFile,
412-
Dictionary<string, ScriptFile> referencedScriptFiles)
413-
{
414-
// Get the base path of the current script for use in resolving relative paths
415-
string baseFilePath = scriptFile.IsInMemory
416-
? WorkspacePath
417-
: Path.GetDirectoryName(scriptFile.FilePath);
418-
419-
foreach (string referencedFileName in scriptFile.ReferencedFiles)
420-
{
421-
string resolvedScriptPath =
422-
ResolveRelativeScriptPath(
423-
baseFilePath,
424-
referencedFileName);
425-
426-
// If there was an error resolving the string, skip this reference
427-
if (resolvedScriptPath == null)
428-
{
429-
continue;
430-
}
431-
432-
logger.LogDebug(
433-
string.Format(
434-
"Resolved relative path '{0}' to '{1}'",
435-
referencedFileName,
436-
resolvedScriptPath));
437-
438-
// Get the referenced file if it's not already in referencedScriptFiles
439-
if (TryGetFile(resolvedScriptPath, out ScriptFile referencedFile))
440-
{
441-
// Normalize the resolved script path and add it to the
442-
// referenced files list if it isn't there already
443-
resolvedScriptPath = resolvedScriptPath.ToLower();
444-
if (!referencedScriptFiles.ContainsKey(resolvedScriptPath))
445-
{
446-
referencedScriptFiles.Add(resolvedScriptPath, referencedFile);
447-
RecursivelyFindReferences(referencedFile, referencedScriptFiles);
448-
}
449-
}
450-
}
451-
}
452375

453376
internal static StreamReader OpenStreamReader(DocumentUri uri)
454377
{

test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ private async Task<List<SymbolReference>> GetReferences(ScriptRegion scriptRegio
109109
Assert.NotNull(symbol);
110110

111111
IEnumerable<SymbolReference> symbols =
112-
await symbolsService.ScanForReferencesOfSymbol(
113-
symbol,
114-
workspace.ExpandScriptReferences(scriptFile)).ConfigureAwait(true);
112+
await symbolsService.ScanForReferencesOfSymbol(symbol).ConfigureAwait(true);
115113

116114
return symbols.OrderBy(i => i.ScriptRegion.ToRange().Start).ToList();
117115
}

test/PowerShellEditorServices.Test/Session/ScriptFileTests.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -174,30 +174,6 @@ public void CanAppendToEndOfFile()
174174
);
175175
}
176176

177-
[Trait("Category", "ScriptFile")]
178-
[Fact]
179-
public void FindsDotSourcedFiles()
180-
{
181-
string exampleScriptContents = TestUtilities.PlatformNormalize(
182-
". ./athing.ps1\n" +
183-
". ./somefile.ps1\n" +
184-
". ./somefile.ps1\n" +
185-
"Do-Stuff $uri\n" +
186-
". simpleps.ps1");
187-
188-
using StringReader stringReader = new(exampleScriptContents);
189-
ScriptFile scriptFile =
190-
new(
191-
// Use any absolute path. Even if it doesn't exist.
192-
DocumentUri.FromFileSystemPath(Path.Combine(Path.GetTempPath(), "TestFile.ps1")),
193-
stringReader,
194-
PowerShellVersion);
195-
196-
Assert.Equal(3, scriptFile.ReferencedFiles.Length);
197-
Console.Write("a" + scriptFile.ReferencedFiles[0]);
198-
Assert.Equal(TestUtilities.NormalizePath("./athing.ps1"), scriptFile.ReferencedFiles[0]);
199-
}
200-
201177
[Trait("Category", "ScriptFile")]
202178
[Fact]
203179
public void ThrowsExceptionWithEditOutsideOfRange()
@@ -610,7 +586,6 @@ public void PropertiesInitializedCorrectlyForFile()
610586
Assert.Equal(path, scriptFile.FilePath, ignoreCase: !VersionUtils.IsLinux);
611587
Assert.True(scriptFile.IsAnalysisEnabled);
612588
Assert.False(scriptFile.IsInMemory);
613-
Assert.Empty(scriptFile.ReferencedFiles);
614589
Assert.Empty(scriptFile.DiagnosticMarkers);
615590
Assert.Single(scriptFile.ScriptTokens);
616591
Assert.Single(scriptFile.FileLines);
@@ -635,7 +610,6 @@ public void PropertiesInitializedCorrectlyForUntitled()
635610
Assert.Equal(path, scriptFile.DocumentUri);
636611
Assert.True(scriptFile.IsAnalysisEnabled);
637612
Assert.True(scriptFile.IsInMemory);
638-
Assert.Empty(scriptFile.ReferencedFiles);
639613
Assert.Empty(scriptFile.DiagnosticMarkers);
640614
Assert.Equal(10, scriptFile.ScriptTokens.Length);
641615
Assert.Equal(3, scriptFile.FileLines.Count);

0 commit comments

Comments
 (0)