|
3 | 3 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
4 | 4 | //
|
5 | 5 |
|
| 6 | +using System; |
6 | 7 | using System.Collections.Generic;
|
| 8 | +using System.Linq; |
7 | 9 | using System.Management.Automation;
|
8 | 10 | using System.Management.Automation.Language;
|
9 | 11 | using System.Management.Automation.Runspaces;
|
@@ -107,33 +109,80 @@ static public SymbolReference FindCommandAtPosition(Ast scriptAst, int lineNumbe
|
107 | 109 | }
|
108 | 110 |
|
109 | 111 | /// <summary>
|
110 |
| - /// Finds all references in a script of the given symbol |
| 112 | + /// Finds all references (including aliases) in a script for the given symbol |
111 | 113 | /// </summary>
|
112 | 114 | /// <param name="scriptAst">The abstract syntax tree of the given script</param>
|
113 | 115 | /// <param name="symbolReference">The symbol that we are looking for referneces of</param>
|
114 |
| - /// <returns>A collection of SymbolReference objects that are refrences to the symbolRefrence</returns> |
115 |
| - static public IEnumerable<SymbolReference> FindReferencesOfSymbol(Ast scriptAst, SymbolReference symbolReference) |
| 116 | + /// <param name="CmdletToAliasDictionary">Dictionary maping cmdlets to aliases for finding alias references</param> |
| 117 | + /// <param name="AliasToCmdletDictionary">Dictionary maping aliases to cmdlets for finding alias references</param> |
| 118 | + /// <returns></returns> |
| 119 | + static public IEnumerable<SymbolReference> FindReferencesOfSymbol( |
| 120 | + Ast scriptAst, |
| 121 | + SymbolReference symbolReference, |
| 122 | + Dictionary<String, List<String>> CmdletToAliasDictionary, |
| 123 | + Dictionary<String, String> AliasToCmdletDictionary) |
116 | 124 | {
|
117 | 125 | // find the symbol evaluators for the node types we are handling
|
118 |
| - FindReferencesVisitor referencesVisitor = new FindReferencesVisitor(symbolReference); |
| 126 | + FindReferencesVisitor referencesVisitor = |
| 127 | + new FindReferencesVisitor( |
| 128 | + symbolReference, |
| 129 | + CmdletToAliasDictionary, |
| 130 | + AliasToCmdletDictionary); |
119 | 131 | scriptAst.Visit(referencesVisitor);
|
120 | 132 |
|
121 | 133 | return referencesVisitor.FoundReferences;
|
122 | 134 |
|
123 | 135 | }
|
| 136 | + /// <summary> |
| 137 | + /// Finds all references (not including aliases) in a script for the given symbol |
| 138 | + /// </summary> |
| 139 | + /// <param name="scriptAst">The abstract syntax tree of the given script</param> |
| 140 | + /// <param name="foundSymbol">The symbol that we are looking for referneces of</param> |
| 141 | + /// <param name="needsAliases">If this reference search needs aliases. |
| 142 | + /// This should always be false and used for occurence requests</param> |
| 143 | + /// <returns>A collection of SymbolReference objects that are refrences to the symbolRefrence |
| 144 | + /// not including aliases</returns> |
| 145 | + static public IEnumerable<SymbolReference> FindReferencesOfSymbol( |
| 146 | + ScriptBlockAst scriptAst, |
| 147 | + SymbolReference foundSymbol, |
| 148 | + bool needsAliases) |
| 149 | + { |
| 150 | + FindReferencesVisitor referencesVisitor = |
| 151 | + new FindReferencesVisitor(foundSymbol); |
| 152 | + scriptAst.Visit(referencesVisitor); |
| 153 | + |
| 154 | + return referencesVisitor.FoundReferences; |
| 155 | + } |
124 | 156 |
|
125 | 157 | /// <summary>
|
126 | 158 | /// Finds the definition of the symbol
|
127 | 159 | /// </summary>
|
128 | 160 | /// <param name="scriptAst">The abstract syntax tree of the given script</param>
|
129 | 161 | /// <param name="symbolReference">The symbol that we are looking for the definition of</param>
|
130 | 162 | /// <returns>A SymbolReference of the definition of the symbolReference</returns>
|
131 |
| - static public SymbolReference FindDefinitionOfSymbol(Ast scriptAst, SymbolReference symbolReference) |
| 163 | + static public SymbolReference FindDefinitionOfSymbol( |
| 164 | + Ast scriptAst, |
| 165 | + SymbolReference symbolReference) |
132 | 166 | {
|
133 |
| - FindDeclartionVisitor declarationVisitor = new FindDeclartionVisitor(symbolReference); |
| 167 | + FindDeclartionVisitor declarationVisitor = |
| 168 | + new FindDeclartionVisitor( |
| 169 | + symbolReference); |
134 | 170 | scriptAst.Visit(declarationVisitor);
|
135 | 171 |
|
136 | 172 | return declarationVisitor.FoundDeclartion;
|
137 | 173 | }
|
| 174 | + |
| 175 | + /// <summary> |
| 176 | + /// Finds all files dot sourced in a script |
| 177 | + /// </summary> |
| 178 | + /// <param name="scriptAst">The abstract syntax tree of the given script</param> |
| 179 | + /// <returns></returns> |
| 180 | + static public string[] FindDotSourcedIncludes(Ast scriptAst) |
| 181 | + { |
| 182 | + FindDotSourcedVisitor dotSourcedVisitor = new FindDotSourcedVisitor(); |
| 183 | + scriptAst.Visit(dotSourcedVisitor); |
| 184 | + |
| 185 | + return dotSourcedVisitor.DotSourcedFiles.ToArray(); |
| 186 | + } |
138 | 187 | }
|
139 | 188 | }
|
0 commit comments