atularen / ngx-monaco-editor

Monaco Editor component for Angular 2 and Above
https://www.npmjs.com/package/ngx-monaco-editor
MIT License
428 stars 155 forks source link

Setting custom markers individually for each file #247

Open Dako390 opened 2 years ago

Dako390 commented 2 years ago

Hello everybody.

I am currently looking for an option to display markers (errors) received by a custom validator only in the right file. An error looks something like this:

{ file: 'path/to/a/file', message: 'Field scope is deprecated', severity: 1, ruleName: 'deprecated-events', ruleDescription: 'Checks for deprecated events.', row: 310, column: 9 }

So it already kind of has the marker structure. My application uses tabs like vs code and the user can switch between those or close them.

My question now is: How do I display this error using ngx-monaco-editor when the corresponding file is currently opened in the tab?

I have the path stored in the tab so I can check it like if (openedTab.path === error.file). My problem is that I somehow can not use monaco.editor.setModelMarkers(). I guess the reason is because I am using ngx-monaco-editor? What would monaco.editor be in my case?

My html looks like this: <ngx-monaco-editor automaticLayout="true" style="height: 100%" [options]="editorOptions" [(ngModel)]="code" (ngModelChange)="save();" (onInit)="onInit($event); editorInit($event)"></ngx-monaco-editor>

Thanks in advance!