2 Object.defineProperty(exports, "__esModule", { value: true });
3 const coc_nvim_1 = require("coc.nvim");
6 * Adds the filepath to the error message
8 * @param msg The original error message
9 * @param fileName The path to the file
10 * @returns {string} enhanced message with the filename
12 function addFilePath(msg, fileName) {
13 const lines = msg.split('\n');
14 if (lines.length > 0) {
15 lines[0] = lines[0].replace(/(\d*):(\d*)/g, `${fileName}:$1:$2`);
16 return lines.join('\n');
21 * Append messages to the output channel and format it with a title
23 * @param message The message to append to the output channel
25 function addToOutput(message, type = 'Trace') {
28 const title = `${type} - ${new Date().toLocaleString()}:`;
29 // Create a sort of title, to differentiate between messages
30 outputChannel.appendLine('');
31 // Append actual output
32 outputChannel.appendLine(`[${title}] ${message}\n`);
34 exports.addToOutput = addToOutput;
36 * Execute a callback safely, if it doesn't work, return default and log messages.
38 * @param cb The function to be executed,
39 * @param defaultText The default value if execution of the cb failed
40 * @param fileName The filename of the current document
41 * @returns {string} formatted text or defaultText
43 function safeExecution(cb, defaultText, fileName) {
44 if (cb instanceof Promise) {
46 .then(returnValue => {
47 // updateStatusBar('Prettier: $(check)')
51 addToOutput(addFilePath(err.message, fileName), 'Error');
52 // updateStatusBar('Prettier: $(x)')
57 const returnValue = cb();
58 // updateStatusBar('Prettier: $(check)')
62 addToOutput(addFilePath(err.message, fileName), 'Error');
63 // updateStatusBar('Prettier: $(x)')
67 exports.safeExecution = safeExecution;
69 * Setup the output channel and the statusBarItem.
70 * Create a command to show the output channel
72 * @returns {Disposable} The command to open the output channel
74 function setupErrorHandler() {
75 // Setup the outputChannel
76 outputChannel = coc_nvim_1.workspace.createOutputChannel('prettier');
77 return coc_nvim_1.commands.registerCommand('prettier.open-output', () => {
81 exports.setupErrorHandler = setupErrorHandler;
82 //# sourceMappingURL=errorHandler.js.map