/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
adev/src/app/editor/code-editor/extensions/diagnostics.ts
55 строк
2 KB
Matthieu Riegler
docs(docs-infra): lift circular imports (#63186)
19 авг 2025, 10:58
19 авг 2025, 10:58
9b539a1
Код
Авторство
О чём код?
/*! * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {Diagnostic, linter} from '@codemirror/lint'; import {TsVfsWorkerActions} from '../workers/enums/actions'; import {Signal} from '@angular/core'; import type {EditorFile} from '../code-mirror-editor.service'; import {ActionMessage} from '../workers/interfaces/message'; import {DiagnosticsRequest} from '../workers/interfaces/diagnostics-request'; import {Subject, filter, take} from 'rxjs'; import {DiagnosticWithLocation, DiagnosticsState} from '../services/diagnostics-state.service'; // Factory method for diagnostics extension. export const getDiagnosticsExtension = ( eventManager: Subject<ActionMessage>, currentFile: Signal<EditorFile>, sendRequestToTsVfs: (request: ActionMessage<DiagnosticsRequest>) => void, diagnosticsState: DiagnosticsState, ) => { return linter( async (view): Promise<Diagnostic[]> => { sendRequestToTsVfs({ action: TsVfsWorkerActions.DIAGNOSTICS_REQUEST, data: { file: currentFile().filename, }, }); const diagnostics = await new Promise((resolve) => { eventManager .pipe( filter((event) => event.action === TsVfsWorkerActions.DIAGNOSTICS_RESPONSE), take(1), ) .subscribe((response: ActionMessage<Diagnostic[]>) => { resolve(response.data); }); }); const result = !!diagnostics ? (diagnostics as DiagnosticWithLocation[]) : []; diagnosticsState.setDiagnostics(result); return result; }, { delay: 400, }, ); };