Skip to content

Commit 9706571

Browse files
committed
Fix crash and hang issues with Pester CodeLens feature
This change fixes a couple of issues with the new Pester CodeLens feature. One is that the "Describe" function is not recognized when it is not cased exactly like that and the other is that the language server has an internal error that causes it to hang when typing Describe blocks into a script. Resolves PowerShell/vscode-powershell#850 Resolves PowerShell/vscode-powershell#851
1 parent 7159276 commit 9706571

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/PowerShellEditorServices.Host/CodeLens/PesterCodeLensProvider.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ private IEnumerable<CodeLens> GetPesterLens(
3434
int startQuoteIndex = symbol.SourceLine.IndexOfAny(QuoteChars) + 1;
3535
int endQuoteIndex = symbol.SourceLine.LastIndexOfAny(QuoteChars);
3636

37+
// Is this a valid describe block with a string?
38+
if (startQuoteIndex == -1 ||
39+
startQuoteIndex >= endQuoteIndex)
40+
{
41+
return Enumerable.Empty<CodeLens>();
42+
}
43+
3744
string describeBlockName =
3845
symbol.SourceLine.Substring(
3946
startQuoteIndex,
@@ -80,8 +87,9 @@ public CodeLens[] ProvideCodeLenses(ScriptFile scriptFile)
8087

8188
var lenses =
8289
symbols
83-
.Where(s => s.SymbolName.StartsWith("Describe"))
90+
.Where(s => s.SymbolName.StartsWith("Describe", StringComparison.OrdinalIgnoreCase))
8491
.SelectMany(s => this.GetPesterLens(s, scriptFile))
92+
.Where(codeLens => codeLens != null)
8593
.ToArray();
8694

8795
return lenses;

0 commit comments

Comments
 (0)