112 lines
4.0 KiB
JavaScript
112 lines
4.0 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || (function () {
|
|
var ownKeys = function(o) {
|
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
var ar = [];
|
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
return ar;
|
|
};
|
|
return ownKeys(o);
|
|
};
|
|
return function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
})();
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.convertToTsDiagnostics = convertToTsDiagnostics;
|
|
exports.convertToCodeFixes = convertToCodeFixes;
|
|
const ts = __importStar(require("typescript/lib/tsserverlibrary"));
|
|
/**
|
|
* 将自定义诊断转换为 TypeScript 诊断
|
|
*/
|
|
function convertToTsDiagnostics(customDiagnostics) {
|
|
return customDiagnostics.map((custom) => {
|
|
const diagnostic = {
|
|
file: custom.file,
|
|
start: custom.start,
|
|
length: custom.length,
|
|
messageText: custom.messageText,
|
|
category: custom.category,
|
|
code: custom.code,
|
|
};
|
|
// 添加相关信息
|
|
if (custom.relatedInfo && custom.relatedInfo.length > 0) {
|
|
diagnostic.relatedInformation = custom.relatedInfo.map((info) => ({
|
|
file: info.file,
|
|
start: info.start,
|
|
length: info.length,
|
|
messageText: info.message,
|
|
category: ts.DiagnosticCategory.Message,
|
|
code: 0,
|
|
}));
|
|
}
|
|
return diagnostic;
|
|
});
|
|
}
|
|
/**
|
|
* 将自定义诊断转换为代码修复
|
|
*/
|
|
function convertToCodeFixes(customDiagnostics, fileName) {
|
|
const fixes = [];
|
|
for (const diagnostic of customDiagnostics) {
|
|
// 为 AsyncContext 错误提供修复
|
|
if (diagnostic.code === 9100 || diagnostic.code === 9101) {
|
|
fixes.push({
|
|
fixName: 'addAwait',
|
|
description: '添加 await 关键字',
|
|
changes: [
|
|
{
|
|
fileName,
|
|
textChanges: [
|
|
{
|
|
span: { start: diagnostic.start, length: 0 },
|
|
newText: 'await ',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
fixes.push({
|
|
fixName: 'addIgnoreComment',
|
|
description: '添加 @oak-ignore 注释',
|
|
changes: [
|
|
{
|
|
fileName,
|
|
textChanges: [
|
|
{
|
|
span: { start: diagnostic.start, length: 0 },
|
|
newText: '// @oak-ignore\n',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
}
|
|
// 为 i18n 错误提供修复
|
|
if (diagnostic.code >= 9200 && diagnostic.code < 9300) {
|
|
// TODO: 提供创建 i18n key 的修复
|
|
}
|
|
}
|
|
return fixes;
|
|
}
|
|
//# sourceMappingURL=diagnosticConverter.js.map
|