Skip to content

Commit da8c579

Browse files
refactor and hook up setting to the key handler
1 parent 4b02b1c commit da8c579

File tree

3 files changed

+178
-163
lines changed

3 files changed

+178
-163
lines changed

src/PowerShellEditorServices/Language/AstOperations.cs

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -97,65 +97,69 @@ static public async Task<CommandCompletion> GetCompletionsAsync(
9797

9898
var stopwatch = new Stopwatch();
9999

100-
stopwatch.Start();
101-
102-
try
103-
{
104-
return CommandCompletion.CompleteInput(
105-
scriptAst,
106-
currentTokens,
107-
cursorPosition,
108-
options: null,
109-
powershell: pwsh);
110-
}
111-
finally
100+
if (powerShellContext.IsPSReadLineEnabled)
112101
{
113-
stopwatch.Stop();
114-
logger.Write(LogLevel.Verbose, $"IntelliSense completed in {stopwatch.ElapsedMilliseconds}ms.");
102+
stopwatch.Start();
103+
104+
try
105+
{
106+
return CommandCompletion.CompleteInput(
107+
scriptAst,
108+
currentTokens,
109+
cursorPosition,
110+
options: null,
111+
powershell: pwsh);
112+
}
113+
finally
114+
{
115+
stopwatch.Stop();
116+
logger.Write(LogLevel.Verbose, $"IntelliSense completed in {stopwatch.ElapsedMilliseconds}ms.");
117+
}
115118
}
119+
116120
// If the current runspace is out of process we can use
117121
// CommandCompletion.CompleteInput because PSReadLine won't be taking up the
118122
// main runspace.
119-
// if (powerShellContext.IsCurrentRunspaceOutOfProcess())
120-
// {
121-
// using (RunspaceHandle runspaceHandle = await powerShellContext.GetRunspaceHandleAsync(cancellationToken))
122-
// using (PowerShell powerShell = PowerShell.Create())
123-
// {
124-
// powerShell.Runspace = runspaceHandle.Runspace;
125-
// stopwatch.Start();
126-
// try
127-
// {
128-
// return CommandCompletion.CompleteInput(
129-
// scriptAst,
130-
// currentTokens,
131-
// cursorPosition,
132-
// options: null,
133-
// powershell: powerShell);
134-
// }
135-
// finally
136-
// {
137-
// stopwatch.Stop();
138-
// logger.Write(LogLevel.Verbose, $"IntelliSense completed in {stopwatch.ElapsedMilliseconds}ms.");
139-
// }
140-
// }
141-
// }
142-
143-
// CommandCompletion commandCompletion = null;
144-
// await powerShellContext.InvokeOnPipelineThreadAsync(
145-
// pwsh =>
146-
// {
147-
// stopwatch.Start();
148-
// commandCompletion = CommandCompletion.CompleteInput(
149-
// scriptAst,
150-
// currentTokens,
151-
// cursorPosition,
152-
// options: null,
153-
// powershell: pwsh);
154-
// });
155-
// stopwatch.Stop();
156-
// logger.Write(LogLevel.Verbose, $"IntelliSense completed in {stopwatch.ElapsedMilliseconds}ms.");
157-
158-
// return commandCompletion;
123+
if (powerShellContext.IsCurrentRunspaceOutOfProcess())
124+
{
125+
using (RunspaceHandle runspaceHandle = await powerShellContext.GetRunspaceHandleAsync(cancellationToken))
126+
using (PowerShell powerShell = PowerShell.Create())
127+
{
128+
powerShell.Runspace = runspaceHandle.Runspace;
129+
stopwatch.Start();
130+
try
131+
{
132+
return CommandCompletion.CompleteInput(
133+
scriptAst,
134+
currentTokens,
135+
cursorPosition,
136+
options: null,
137+
powershell: powerShell);
138+
}
139+
finally
140+
{
141+
stopwatch.Stop();
142+
logger.Write(LogLevel.Verbose, $"IntelliSense completed in {stopwatch.ElapsedMilliseconds}ms.");
143+
}
144+
}
145+
}
146+
147+
CommandCompletion commandCompletion = null;
148+
await powerShellContext.InvokeOnPipelineThreadAsync(
149+
pwsh =>
150+
{
151+
stopwatch.Start();
152+
commandCompletion = CommandCompletion.CompleteInput(
153+
scriptAst,
154+
currentTokens,
155+
cursorPosition,
156+
options: null,
157+
powershell: pwsh);
158+
});
159+
stopwatch.Stop();
160+
logger.Write(LogLevel.Verbose, $"IntelliSense completed in {stopwatch.ElapsedMilliseconds}ms.");
161+
162+
return commandCompletion;
159163
}
160164
finally
161165
{

0 commit comments

Comments
 (0)