MCPcopy Index your code
hub / github.com/nodejs/node / showCompletionPreview

Function showCompletionPreview

lib/internal/repl/utils.js:229–288  ·  view source on GitHub ↗
(line, insertPreview)

Source from the content-addressed store, hash-verified

227 };
228
229 function showCompletionPreview(line, insertPreview) {
230 previewCompletionCounter++;
231
232 const count = previewCompletionCounter;
233
234 repl.completer(line, (error, data) => {
235 // Tab completion might be async and the result might already be outdated.
236 if (count !== previewCompletionCounter) {
237 return;
238 }
239
240 if (error) {
241 debug('Error while generating completion preview', error);
242 return;
243 }
244
245 // Result and the text that was completed.
246 const { 0: rawCompletions, 1: completeOn } = data;
247
248 if (!rawCompletions || rawCompletions.length === 0) {
249 return;
250 }
251
252 hasCompletions = true;
253
254 // If there is a common prefix to all matches, then apply that portion.
255 const completions = ArrayPrototypeFilter(rawCompletions, Boolean);
256 const prefix = commonPrefix(completions);
257
258 // No common prefix found.
259 if (prefix.length <= completeOn.length) {
260 return;
261 }
262
263 const suffix = StringPrototypeSlice(prefix, completeOn.length);
264
265 if (insertPreview) {
266 repl._insertString(suffix);
267 return;
268 }
269
270 completionPreview = suffix;
271
272 const result = repl.useColors ?
273 `\u001b[90m${suffix}\u001b[39m` :
274 ` // ${suffix}`;
275
276 const { cursorPos, displayPos } = getPreviewPos();
277 if (repl.line.length !== repl.cursor) {
278 cursorTo(repl.output, displayPos.cols);
279 moveCursor(repl.output, 0, displayPos.rows - cursorPos.rows);
280 }
281 repl.output.write(result);
282 cursorTo(repl.output, cursorPos.cols);
283 const totalLine = `${repl.getPrompt()}${repl.line}${suffix}`;
284 const newPos = repl._getDisplayPos(totalLine);
285 const rows = newPos.rows - cursorPos.rows - (newPos.cols === 0 ? 1 : 0);
286 moveCursor(repl.output, 0, -rows);

Callers 2

showPreviewFunction · 0.85
setupPreviewFunction · 0.85

Calls 8

commonPrefixFunction · 0.85
getPreviewPosFunction · 0.85
cursorToFunction · 0.85
moveCursorFunction · 0.85
completerMethod · 0.80
getPromptMethod · 0.80
debugFunction · 0.50
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…