mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-29 05:11:44 +03:00
Return message id in prettier_server error responses
This commit is contained in:
parent
6cac58b34c
commit
06cac18d78
@ -37,8 +37,15 @@ const prettierPath = path.join(prettierContainerPath, 'node_modules/prettier');
|
|||||||
|
|
||||||
async function handleBuffer(prettier) {
|
async function handleBuffer(prettier) {
|
||||||
for await (let messageText of readStdin()) {
|
for await (let messageText of readStdin()) {
|
||||||
handleMessage(messageText, prettier).catch(e => {
|
let message;
|
||||||
sendResponse(makeError(`error during message handling: ${e}`));
|
try {
|
||||||
|
message = JSON.parse(messageText);
|
||||||
|
} catch (e) {
|
||||||
|
sendResponse(makeError(`Failed to parse message '${messageText}': ${e}`));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
handleMessage(message, prettier).catch(e => {
|
||||||
|
sendResponse({ id: message.id, ...makeError(`error during message handling: ${e}`) });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,22 +124,21 @@ async function* readStdin() {
|
|||||||
// ?
|
// ?
|
||||||
// shutdown
|
// shutdown
|
||||||
// error
|
// error
|
||||||
async function handleMessage(messageText, prettier) {
|
async function handleMessage(message, prettier) {
|
||||||
const message = JSON.parse(messageText);
|
|
||||||
const { method, id, params } = message;
|
const { method, id, params } = message;
|
||||||
if (method === undefined) {
|
if (method === undefined) {
|
||||||
throw new Error(`Message method is undefined: ${messageText}`);
|
throw new Error(`Message method is undefined: ${JSON.stringify(message)}`);
|
||||||
}
|
}
|
||||||
if (id === undefined) {
|
if (id === undefined) {
|
||||||
throw new Error(`Message id is undefined: ${messageText}`);
|
throw new Error(`Message id is undefined: ${JSON.stringify(message)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method === 'prettier/format') {
|
if (method === 'prettier/format') {
|
||||||
if (params === undefined || params.text === undefined) {
|
if (params === undefined || params.text === undefined) {
|
||||||
throw new Error(`Message params.text is undefined: ${messageText}`);
|
throw new Error(`Message params.text is undefined: ${JSON.stringify(message)}`);
|
||||||
}
|
}
|
||||||
if (params.options === undefined) {
|
if (params.options === undefined) {
|
||||||
throw new Error(`Message params.options is undefined: ${messageText}`);
|
throw new Error(`Message params.options is undefined: ${JSON.stringify(message)}`);
|
||||||
}
|
}
|
||||||
const formattedText = await prettier.format(params.text, params.options);
|
const formattedText = await prettier.format(params.text, params.options);
|
||||||
sendResponse({ id, result: { text: formattedText } });
|
sendResponse({ id, result: { text: formattedText } });
|
||||||
|
Loading…
Reference in New Issue
Block a user