forked from PowerShell/PowerShellEditorServices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPesterCodeLensProvider.cs
92 lines (81 loc) · 2.93 KB
/
PesterCodeLensProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.PowerShell.EditorServices.Commands;
using Microsoft.PowerShell.EditorServices.Symbols;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.PowerShell.EditorServices.CodeLenses
{
internal class PesterCodeLensProvider : FeatureProviderBase, ICodeLensProvider
{
private static char[] QuoteChars = new char[] { '\'', '"'};
private EditorSession editorSession;
private IDocumentSymbolProvider symbolProvider;
public PesterCodeLensProvider(EditorSession editorSession)
{
this.editorSession = editorSession;
this.symbolProvider = new PesterDocumentSymbolProvider();
}
private IEnumerable<CodeLens> GetPesterLens(
PesterSymbolReference pesterSymbol,
ScriptFile scriptFile)
{
var clientCommands = new ClientCommand[]
{
new ClientCommand(
"PowerShell.RunPesterTests",
"Run tests",
new object[]
{
scriptFile.ClientFilePath,
false, // Don't debug
pesterSymbol.TestName,
}),
new ClientCommand(
"PowerShell.RunPesterTests",
"Debug tests",
new object[]
{
scriptFile.ClientFilePath,
true, // Run in debugger
pesterSymbol.TestName,
}),
};
return
clientCommands.Select(
command =>
new CodeLens(
this,
scriptFile,
pesterSymbol.ScriptRegion,
command));
}
public CodeLens[] ProvideCodeLenses(ScriptFile scriptFile)
{
var symbols =
this.symbolProvider
.ProvideDocumentSymbols(scriptFile);
var lenses =
symbols
.OfType<PesterSymbolReference>()
.Where(s => s.Command == PesterCommandType.Describe)
.SelectMany(s => this.GetPesterLens(s, scriptFile))
.Where(codeLens => codeLens != null)
.ToArray();
return lenses;
}
public Task<CodeLens> ResolveCodeLensAsync(
CodeLens codeLens,
CancellationToken cancellationToken)
{
// This provider has no specific behavior for
// resolving CodeLenses.
return Task.FromResult(codeLens);
}
}
}