Skip to content

Commit 383bfff

Browse files
author
Nathan Turinski
committed
Clean up some of the code
1 parent a331ddc commit 383bfff

File tree

6 files changed

+110
-236
lines changed

6 files changed

+110
-236
lines changed

extension.bundle.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/commands/pickFuncProcess.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface IStartFuncProcessResult {
4141
* An async iterable stream of terminal output from the function host task.
4242
* This stream provides real-time access to the output of the `func host start` command,
4343
* allowing consumers to monitor host status, capture logs, and detect errors.
44-
*
44+
*
4545
* The stream will be undefined if the host failed to start or if output streaming is not available.
4646
* Consumers should iterate over the stream asynchronously to read output lines as they are produced.
4747
* The stream remains active for the lifetime of the function host process.
@@ -169,7 +169,6 @@ async function startFuncTask(context: IActionContext, workspaceFolder: vscode.Wo
169169
const funcPort: string = await getFuncPortFromTaskOrProject(context, funcTask, workspaceFolder);
170170
let statusRequestTimeout: number = intervalMs;
171171
const maxTime: number = Date.now() + timeoutInSeconds * 1000;
172-
173172
while (Date.now() < maxTime) {
174173
if (taskError !== undefined) {
175174
throw taskError;
@@ -200,7 +199,6 @@ async function startFuncTask(context: IActionContext, workspaceFolder: vscode.Wo
200199
}
201200
}
202201
}
203-
204202
}
205203

206204
await delay(intervalMs);

src/debug/registerFunctionHostDebugView.ts

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,20 @@
55

66
import { registerCommand, type IActionContext } from '@microsoft/vscode-azext-utils';
77
import * as vscode from 'vscode';
8+
import { getRecentLogsPlainText } from '../funcCoreTools/funcHostErrorUtils';
89
import { onRunningFuncTasksChanged, refreshFuncHostDebugContext, runningFuncTaskMap, type IRunningFuncTask } from '../funcCoreTools/funcHostTask';
910
import { localize } from '../localize';
1011
import { stripAnsiControlCharacters } from '../utils/ansiUtils';
11-
import { openCopilotChat } from '../utils/copilotChat';
1212
import { FuncHostDebugViewProvider, type IHostErrorNode, type IHostTaskNode } from './FunctionHostDebugView';
1313

1414
const viewId = 'azureFunctions.funcHostDebugView';
1515

1616
function isHostTaskNode(node: unknown): node is IHostTaskNode {
17-
if (!node || typeof node !== 'object') {
18-
return false;
19-
}
20-
21-
const n = node as Partial<IHostTaskNode>;
22-
const scope = (n as { workspaceFolder?: unknown }).workspaceFolder;
23-
const hasValidScope = typeof scope === 'object' || typeof scope === 'number';
24-
25-
return n.kind === 'hostTask'
26-
&& hasValidScope
27-
&& typeof n.portNumber === 'string'
28-
&& (n.cwd === undefined || typeof n.cwd === 'string');
17+
return !!node && typeof node === 'object' && (node as IHostTaskNode).kind === 'hostTask';
2918
}
3019

3120
function isHostErrorNode(node: unknown): node is IHostErrorNode {
32-
if (!node || typeof node !== 'object') {
33-
return false;
34-
}
35-
36-
const n = node as Partial<IHostErrorNode>;
37-
const scope = (n as { workspaceFolder?: unknown }).workspaceFolder;
38-
const hasValidScope = typeof scope === 'object' || typeof scope === 'number';
39-
40-
return n.kind === 'hostError'
41-
&& hasValidScope
42-
&& typeof n.portNumber === 'string'
43-
&& typeof n.message === 'string'
44-
&& (n.cwd === undefined || typeof n.cwd === 'string');
21+
return !!node && typeof node === 'object' && (node as IHostErrorNode).kind === 'hostError';
4522
}
4623

4724
async function tryOpenDebugViewOnFirstFuncHostError(): Promise<void> {
@@ -74,16 +51,6 @@ async function tryOpenDebugViewOnFirstFuncHostError(): Promise<void> {
7451
}
7552
}
7653

77-
function getRecentLogs(task: IRunningFuncTask | undefined, limit: number = 250): string {
78-
const logs = task?.logs ?? [];
79-
const recent = logs.slice(Math.max(0, logs.length - limit));
80-
return recent.join('');
81-
}
82-
83-
function getRecentLogsPlainText(task: IRunningFuncTask | undefined, limit: number = 250): string {
84-
return stripAnsiControlCharacters(getRecentLogs(task, limit));
85-
}
86-
8754
export function registerFunctionHostDebugView(context: vscode.ExtensionContext): void {
8855
const provider = new FuncHostDebugViewProvider();
8956

@@ -167,7 +134,7 @@ export function registerFunctionHostDebugView(context: vscode.ExtensionContext):
167134
errorContext,
168135
].filter((l): l is string => Boolean(l)).join('\n');
169136

170-
await openCopilotChat(prompt);
137+
await vscode.commands.executeCommand('workbench.action.chat.open', { mode: 'agent', query: prompt });
171138
});
172139

173140
registerCommand('azureFunctions.funcHostDebug.refresh', async (actionContext: IActionContext) => {

src/funcCoreTools/funcHostErrorUtils.ts

Lines changed: 11 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { stripAnsiControlCharacters } from '../utils/ansiUtils';
7+
import { type IRunningFuncTask } from './funcHostTask';
8+
9+
export function getRecentLogs(task: IRunningFuncTask | undefined, limit: number = 250): string {
10+
const logs = task?.logs ?? [];
11+
const recent = logs.slice(Math.max(0, logs.length - limit));
12+
return recent.join('');
13+
}
14+
15+
export function getRecentLogsPlainText(task: IRunningFuncTask | undefined, limit: number = 250): string {
16+
return stripAnsiControlCharacters(getRecentLogs(task, limit));
17+
}
718

819
/**
920
* Regex that matches a Functions-host timestamp prefix, e.g. `[2026-03-11T19:57:44.622Z]`.
@@ -21,21 +32,6 @@ function normalizeWhitespace(text: string): string {
2132
return text.replace(/\s+/g, ' ').trim();
2233
}
2334

24-
export interface FuncHostErrorContextOptions {
25-
/**
26-
* Number of log lines to include before an error line
27-
*/
28-
before?: number;
29-
/**
30-
* Number of log lines to include after an error line
31-
*/
32-
after?: number;
33-
/**
34-
* Maximum number of log lines to return (keeps the most recent)
35-
*/
36-
max?: number;
37-
}
38-
3935
// Detect red/bright-red foreground in any of the common SGR forms:
4036
// Basic 4-bit: \x1b[31m (red) / \x1b[91m (bright red), with optional extra params
4137
// 256-color: \x1b[38;5;1m (red) / \x1b[38;5;9m (bright red)
@@ -95,65 +91,3 @@ export function addErrorLinesFromChunk(errorLogs: string[], rawChunk: string): b
9591

9692
return added;
9793
}
98-
99-
/**
100-
* Extracts context for only a single relevant error line (as selected in the UI).
101-
*
102-
* @param errorMessage A plain-text error line (ANSI/control chars already removed).
103-
*/
104-
export function extractFuncHostErrorContextForErrorMessage(
105-
logs: readonly string[],
106-
errorMessage: string,
107-
options?: FuncHostErrorContextOptions
108-
): string[] {
109-
const target = (errorMessage ?? '').trim();
110-
if (!target) {
111-
return [];
112-
}
113-
114-
const before = options?.before ?? 5;
115-
const after = options?.after ?? 15;
116-
const max = options?.max ?? 250;
117-
118-
let bestIndex = -1;
119-
let bestScore = 0;
120-
121-
for (let i = 0; i < logs.length; i++) {
122-
const line = logs[i];
123-
if (!isFuncHostErrorLog(line)) {
124-
continue;
125-
}
126-
127-
const plain = stripAnsiControlCharacters(line).trim();
128-
if (!plain) {
129-
continue;
130-
}
131-
132-
let score = 0;
133-
if (plain === target) {
134-
score = 2;
135-
} else if (plain.includes(target) || target.includes(plain)) {
136-
score = 1;
137-
}
138-
139-
if (score > 0 && (score > bestScore || (score === bestScore && i > bestIndex))) {
140-
bestScore = score;
141-
bestIndex = i;
142-
}
143-
}
144-
145-
if (bestIndex < 0) {
146-
return [];
147-
}
148-
149-
const start = Math.max(0, bestIndex - before);
150-
const end = Math.min(logs.length - 1, bestIndex + after);
151-
152-
const result = logs.slice(start, end + 1);
153-
154-
if (result.length > max) {
155-
return result.slice(result.length - max);
156-
}
157-
158-
return result;
159-
}

src/utils/copilotChat.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)