MCPcopy
hub / github.com/microsoft/vscode-js-debug / listProcesses

Function listProcesses

src/ui/processPicker.ts:135–194  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

133};
134
135async function listProcesses(): Promise<IProcessItem | undefined> {
136 const nodeProcessPattern = /^(?:node|iojs)(?:$|\b)/i;
137 let seq = 0; // default sort key
138
139 const quickPick = vscode.window.createQuickPick<IProcessItem>();
140 quickPick.placeholder = l10n.t('Pick the node.js process to attach to');
141 quickPick.matchOnDescription = true;
142 quickPick.matchOnDetail = true;
143 quickPick.busy = true;
144 quickPick.show();
145
146 let hasPicked = false;
147 const itemPromise = new Promise<IProcessItem | undefined>(resolve => {
148 quickPick.onDidAccept(() => resolve(quickPick.selectedItems[0]));
149 quickPick.onDidHide(() => resolve(undefined));
150 });
151
152 processTree
153 .lookup<IProcessItem[]>((leaf, acc) => {
154 if (hasPicked) {
155 return acc;
156 }
157
158 if (process.platform === 'win32' && leaf.command.indexOf('\\??\\') === 0) {
159 // remove leading device specifier
160 leaf.command = leaf.command.replace('\\??\\', '');
161 }
162
163 const executableName = basename(leaf.command, '.exe');
164 const { port } = analyseArguments(leaf.args);
165 if (!port && !nodeProcessPattern.test(executableName)) {
166 return acc;
167 }
168
169 const newItem = {
170 label: executableName,
171 description: leaf.args,
172 pidAndPort: encodePidAndPort(leaf.pid, port),
173 sortKey: leaf.date ? leaf.date : seq++,
174 detail: port
175 ? l10n.t('process id: {0}, debug port: {1} ({2})', leaf.pid, port, 'SIGUSR1')
176 : l10n.t('process id: {0} ({1})', leaf.pid, 'SIGUSR1'),
177 };
178
179 const index = acc.findIndex(item => item.sortKey < newItem.sortKey);
180 acc.splice(index === -1 ? acc.length : index, 0, newItem);
181 quickPick.items = acc;
182 return acc;
183 }, [])
184 .then(() => (quickPick.busy = false))
185 .catch(err => {
186 vscode.window.showErrorMessage(`Error listing processes: ${err.message}`);
187 quickPick.dispose();
188 });
189
190 const item = await itemPromise;
191 hasPicked = true;
192 quickPick.dispose();

Callers 1

pickProcessFunction · 0.85

Calls 9

analyseArgumentsFunction · 0.90
resolveFunction · 0.85
basenameFunction · 0.85
encodePidAndPortFunction · 0.85
testMethod · 0.80
showMethod · 0.65
lookupMethod · 0.65
replaceMethod · 0.65
disposeMethod · 0.65

Tested by

no test coverage detected