|
5 | 5 | using System.Collections.Generic;
|
6 | 6 | using System.IO;
|
7 | 7 | using System.Linq;
|
| 8 | +using System.Management.Automation; |
| 9 | +using System.Threading; |
8 | 10 | using System.Threading.Tasks;
|
9 | 11 | using Microsoft.Extensions.Logging.Abstractions;
|
10 | 12 | using Microsoft.PowerShell.EditorServices.Services;
|
11 | 13 | using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
|
| 14 | +using Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility; |
12 | 15 | using Microsoft.PowerShell.EditorServices.Services.Symbols;
|
13 | 16 | using Microsoft.PowerShell.EditorServices.Services.TextDocument;
|
14 | 17 | using Microsoft.PowerShell.EditorServices.Test.Shared;
|
@@ -44,6 +47,8 @@ public SymbolsServiceTests()
|
44 | 47 | public void Dispose()
|
45 | 48 | {
|
46 | 49 | psesHost.StopAsync().GetAwaiter().GetResult();
|
| 50 | + CommandHelpers.s_cmdletToAliasCache.Clear(); |
| 51 | + CommandHelpers.s_aliasToCmdletCache.Clear(); |
47 | 52 | GC.SuppressFinalize(this);
|
48 | 53 | }
|
49 | 54 |
|
@@ -126,14 +131,43 @@ public async Task FindsFunctionDefinition()
|
126 | 131 | }
|
127 | 132 |
|
128 | 133 | [Fact]
|
129 |
| - public async Task FindsReferencesOnFunction() |
| 134 | + public async Task FindsFunctionDefinitionForAlias() |
| 135 | + { |
| 136 | + // TODO: Eventually we should get the alises through the AST instead of relying on them |
| 137 | + // being defined in the runspace. |
| 138 | + await psesHost.ExecutePSCommandAsync( |
| 139 | + new PSCommand().AddScript("Set-Alias -Name My-Alias -Value My-Function"), |
| 140 | + CancellationToken.None).ConfigureAwait(true); |
| 141 | + |
| 142 | + SymbolReference definitionResult = await GetDefinition(FindsFunctionDefinitionOfAliasData.SourceDetails).ConfigureAwait(true); |
| 143 | + Assert.Equal(1, definitionResult.ScriptRegion.StartLineNumber); |
| 144 | + Assert.Equal(10, definitionResult.ScriptRegion.StartColumnNumber); |
| 145 | + Assert.Equal("My-Function", definitionResult.SymbolName); |
| 146 | + } |
| 147 | + |
| 148 | + [Fact] |
| 149 | + public async Task FindsReferencesOnFunction() |
130 | 150 | {
|
131 | 151 | List<SymbolReference> referencesResult = await GetReferences(FindsReferencesOnFunctionData.SourceDetails).ConfigureAwait(true);
|
132 | 152 | Assert.Equal(3, referencesResult.Count);
|
133 | 153 | Assert.Equal(1, referencesResult[0].ScriptRegion.StartLineNumber);
|
134 | 154 | Assert.Equal(10, referencesResult[0].ScriptRegion.StartColumnNumber);
|
135 | 155 | }
|
136 | 156 |
|
| 157 | + [Fact] |
| 158 | + public async Task FindsReferencesOnFunctionIncludingAliases() |
| 159 | + { |
| 160 | + // TODO: Same as in FindsFunctionDefinitionForAlias. |
| 161 | + await psesHost.ExecutePSCommandAsync( |
| 162 | + new PSCommand().AddScript("Set-Alias -Name My-Alias -Value My-Function"), |
| 163 | + CancellationToken.None).ConfigureAwait(true); |
| 164 | + |
| 165 | + List<SymbolReference> referencesResult = await GetReferences(FindsReferencesOnFunctionData.SourceDetails).ConfigureAwait(true); |
| 166 | + Assert.Equal(4, referencesResult.Count); |
| 167 | + Assert.Equal(1, referencesResult[0].ScriptRegion.StartLineNumber); |
| 168 | + Assert.Equal(10, referencesResult[0].ScriptRegion.StartColumnNumber); |
| 169 | + } |
| 170 | + |
137 | 171 | [Fact]
|
138 | 172 | public async Task FindsFunctionDefinitionInDotSourceReference()
|
139 | 173 | {
|
|
0 commit comments