MCPcopy
hub / github.com/graphql/graphiql / DiagnosticsAdapter

Class DiagnosticsAdapter

packages/monaco-graphql/src/languageFeatures.ts:22–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20// --- completion ------
21
22export class DiagnosticsAdapter {
23 private _disposables: monaco.IDisposable[] = [];
24 private _listener: { [uri: string]: monaco.IDisposable } =
25 Object.create(null);
26
27 constructor(
28 private defaults: MonacoGraphQLAPI,
29 private _worker: WorkerAccessor,
30 ) {
31 this._worker = _worker;
32 let onChangeTimeout: ReturnType<typeof setTimeout>;
33 const onModelAdd = (model: editor.IModel): void => {
34 const modeId = getModelLanguageId(model);
35 if (modeId !== this.defaults.languageId) {
36 // it is tempting to load json models we cared about here
37 // into the webworker, however setDiagnosticOptions() needs
38 // to be called here from main process anyway, and the worker
39 // is already generating json schema itself!
40 return;
41 }
42 const modelUri = model.uri.toString();
43 // if the config changes, this adapter will be re-instantiated, so we only need to check this once
44 const jsonValidationForModel =
45 defaults.diagnosticSettings?.validateVariablesJSON?.[modelUri];
46 // once on adding a model, this is also fired when schema or other config changes
47 onChangeTimeout = setTimeout(() => {
48 void this._doValidate(model.uri, modeId, jsonValidationForModel);
49 }, 400);
50
51 this._listener[modelUri] = model.onDidChangeContent(() => {
52 clearTimeout(onChangeTimeout);
53 onChangeTimeout = setTimeout(() => {
54 void this._doValidate(model.uri, modeId, jsonValidationForModel);
55 }, 400);
56 });
57 };
58
59 const onModelRemoved = (model: editor.IModel): void => {
60 editor.setModelMarkers(model, this.defaults.languageId, []);
61 const uriStr = model.uri.toString();
62 const listener = this._listener[uriStr];
63
64 if (listener) {
65 listener.dispose();
66 delete this._listener[uriStr];
67 }
68 };
69
70 this._disposables.push(
71 editor.onDidCreateModel(onModelAdd),
72 {
73 dispose() {
74 clearTimeout(onChangeTimeout);
75 },
76 },
77 editor.onWillDisposeModel(model => {
78 onModelRemoved(model);
79 }),

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected