import type * as Monaco from 'monaco-editor' // 同Monaco.MarkerSeverity enum MarkerSeverity { Hint = 1, Info = 2, Warning = 4, Error = 8, } export class LogWorker { constructor( private readonly _ctx: Monaco.worker.IWorkerContext, private readonly _createData: ICreateData, ) { console.log({ ctx: _ctx, createData: _createData }) } private _getText(uri: string): string { const model = this._ctx.getMirrorModels().find((m) => m.uri.toString() === uri) return model?.getValue() ?? '' } // TODO 待实现,可实现告警码提示 async provideInlayHints( uri: string, start: number, end: number, ): Promise { return [] } async doValidation(uri: string): Promise { const text = this._getText(uri) const markers: Monaco.editor.IMarkerData[] = [] const lines = text.split('\n') lines.forEach((line, index) => { if (line.includes('[E]') || line.includes('[Error]') || line.includes('[ERROR]')) { markers.push({ severity: MarkerSeverity.Error, message: 'Error log detected', startLineNumber: index + 1, endLineNumber: index + 1, startColumn: 1, endColumn: line.length + 1, }) } }) return markers } } export interface ICreateData { languageId: string } export function create(ctx: Monaco.worker.IWorkerContext, createData: ICreateData): LogWorker { return new LogWorker(ctx, createData) }