fix(lsp): handle ts debug errors better (#8914)

Fixes #8864
This commit is contained in:
Kitson Kelly 2020-12-30 12:46:58 +11:00 committed by GitHub
parent 268e47c0d8
commit e8a81724bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 109 additions and 74 deletions

View file

@ -31,10 +31,22 @@ delete Object.prototype.__proto__;
const stringifiedArgs = args.map((arg) =>
typeof arg === "string" ? arg : JSON.stringify(arg)
).join(" ");
core.print(`DEBUG ${logSource} - ${stringifiedArgs}\n`);
// adding a non-zero integer value to the end of the debug string causes
// the message to be printed to stderr instead of stdout, which is better
// aligned to the behaviour of debug messages
core.print(`DEBUG ${logSource} - ${stringifiedArgs}\n`, 1);
}
}
function error(...args) {
const stringifiedArgs = args.map((arg) =>
typeof arg === "string" || arg instanceof Error
? String(arg)
: JSON.stringify(arg)
).join(" ");
core.print(`ERROR ${logSource} = ${stringifiedArgs}\n`, 1);
}
class AssertionError extends Error {
constructor(msg) {
super(msg);
@ -497,23 +509,18 @@ delete Object.prototype.__proto__;
);
return respond(id, sourceFile && sourceFile.text);
}
case "getSemanticDiagnostics": {
const diagnostics = languageService.getSemanticDiagnostics(
request.specifier,
).filter(({ code }) => !IGNORED_DIAGNOSTICS.includes(code));
return respond(id, fromTypeScriptDiagnostic(diagnostics));
}
case "getSuggestionDiagnostics": {
const diagnostics = languageService.getSuggestionDiagnostics(
request.specifier,
).filter(({ code }) => !IGNORED_DIAGNOSTICS.includes(code));
return respond(id, fromTypeScriptDiagnostic(diagnostics));
}
case "getSyntacticDiagnostics": {
const diagnostics = languageService.getSyntacticDiagnostics(
request.specifier,
).filter(({ code }) => !IGNORED_DIAGNOSTICS.includes(code));
return respond(id, fromTypeScriptDiagnostic(diagnostics));
case "getDiagnostics": {
try {
const diagnostics = [
...languageService.getSemanticDiagnostics(request.specifier),
...languageService.getSuggestionDiagnostics(request.specifier),
...languageService.getSyntacticDiagnostics(request.specifier),
].filter(({ code }) => !IGNORED_DIAGNOSTICS.includes(code));
return respond(id, fromTypeScriptDiagnostic(diagnostics));
} catch (e) {
error(e);
return respond(id, []);
}
}
case "getQuickInfo": {
return respond(