MCPcopy Index your code
hub / github.com/prettier/prettier / formatWithCursor

Function formatWithCursor

src/main/core.js:322–365  ·  view source on GitHub ↗
(originalText, originalOptions)

Source from the content-addressed store, hash-verified

320}
321
322async function formatWithCursor(originalText, originalOptions) {
323 let { hasBOM, text, options } = normalizeInputAndOptions(
324 originalText,
325 await normalizeFormatOptions(originalOptions),
326 );
327
328 if (
329 (options.rangeStart >= options.rangeEnd && text !== "") ||
330 (options.requirePragma && !(await hasPragma(text, options))) ||
331 (options.checkIgnorePragma && (await hasIgnorePragma(text, options)))
332 ) {
333 return {
334 formatted: originalText,
335 cursorOffset: originalOptions.cursorOffset,
336 comments: [],
337 };
338 }
339
340 let result;
341
342 if (options.rangeStart > 0 || options.rangeEnd < text.length) {
343 result = await formatRange(text, options);
344 } else {
345 if (
346 !options.requirePragma &&
347 options.insertPragma &&
348 options.printer.insertPragma &&
349 !(await hasPragma(text, options))
350 ) {
351 text = options.printer.insertPragma(text);
352 }
353 result = await coreFormat(text, options);
354 }
355
356 if (hasBOM) {
357 result.formatted = BOM + result.formatted;
358
359 if (result.cursorOffset >= 0) {
360 result.cursorOffset++;
361 }
362 }
363
364 return result;
365}
366
367async function parse(originalText, originalOptions, devOptions) {
368 const { text, options } = normalizeInputAndOptions(

Callers 3

formatDocFunction · 0.70
formatFunction · 0.50
formatFunction · 0.50

Calls 6

normalizeInputAndOptionsFunction · 0.85
normalizeFormatOptionsFunction · 0.85
formatRangeFunction · 0.85
coreFormatFunction · 0.85
hasPragmaFunction · 0.70
hasIgnorePragmaFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…