Skip to content

Commit 0beff4d

Browse files
committed
Improve Pester document symbol reporting
This change improves how we report Pester document symbols, narrowing the "symbol name" to just be the 'Describe "My Tests"' line rather than the entire content of the test. This makes the contents more easily searchable and displayed correctly in VS Code.
1 parent 95a7c48 commit 0beff4d

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

src/PowerShellEditorServices/Language/SymbolReference.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,20 @@ public class SymbolReference
4848
/// Constructs and instance of a SymbolReference
4949
/// </summary>
5050
/// <param name="symbolType">The higher level type of the symbol</param>
51+
/// <param name="symbolName">The name of the symbol</param>
5152
/// <param name="scriptExtent">The script extent of the symbol</param>
5253
/// <param name="filePath">The file path of the symbol</param>
5354
/// <param name="sourceLine">The line contents of the given symbol (defaults to empty string)</param>
54-
public SymbolReference(SymbolType symbolType, IScriptExtent scriptExtent, string filePath = "", string sourceLine = "")
55+
public SymbolReference(
56+
SymbolType symbolType,
57+
string symbolName,
58+
IScriptExtent scriptExtent,
59+
string filePath = "",
60+
string sourceLine = "")
5561
{
5662
// TODO: Verify params
5763
this.SymbolType = symbolType;
58-
this.SymbolName = scriptExtent.Text;
64+
this.SymbolName = symbolName;
5965
this.ScriptRegion = ScriptRegion.Create(scriptExtent);
6066
this.FilePath = filePath;
6167
this.SourceLine = sourceLine;
@@ -67,5 +73,17 @@ public SymbolReference(SymbolType symbolType, IScriptExtent scriptExtent, string
6773
// string.Format(
6874
// "{0} {1}")
6975
}
76+
77+
/// <summary>
78+
/// Constructs and instance of a SymbolReference
79+
/// </summary>
80+
/// <param name="symbolType">The higher level type of the symbol</param>
81+
/// <param name="scriptExtent">The script extent of the symbol</param>
82+
/// <param name="filePath">The file path of the symbol</param>
83+
/// <param name="sourceLine">The line contents of the given symbol (defaults to empty string)</param>
84+
public SymbolReference(SymbolType symbolType, IScriptExtent scriptExtent, string filePath = "", string sourceLine = "")
85+
: this(symbolType, scriptExtent.Text, scriptExtent, filePath, sourceLine)
86+
{
87+
}
7088
}
7189
}

src/PowerShellEditorServices/Symbols/PesterDocumentSymbolProvider.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace Microsoft.PowerShell.EditorServices.Symbols
1616
/// </summary>
1717
public class PesterDocumentSymbolProvider : FeatureProviderBase, IDocumentSymbolProvider
1818
{
19+
private static char[] DefinitionTrimChars = new char[] { ' ', '{' };
20+
1921
IEnumerable<SymbolReference> IDocumentSymbolProvider.ProvideDocumentSymbols(
2022
ScriptFile scriptFile)
2123
{
@@ -41,11 +43,20 @@ IEnumerable<SymbolReference> IDocumentSymbolProvider.ProvideDocumentSymbols(
4143
},
4244
true);
4345

44-
return commandAsts.Select(ast => new SymbolReference(
45-
SymbolType.Function,
46-
ast.Extent,
47-
scriptFile.FilePath,
48-
scriptFile.GetLine(ast.Extent.StartLineNumber)));
46+
return commandAsts.Select(
47+
ast => {
48+
var testDefinitionLine =
49+
scriptFile.GetLine(
50+
ast.Extent.StartLineNumber);
51+
52+
return
53+
new SymbolReference(
54+
SymbolType.Function,
55+
testDefinitionLine.TrimEnd(DefinitionTrimChars),
56+
ast.Extent,
57+
scriptFile.FilePath,
58+
testDefinitionLine);
59+
});
4960
}
5061
}
5162
}

0 commit comments

Comments
 (0)