linting.ts 848 B

12345678910111213141516171819202122232425262728
  1. import { Compartment, EditorState } from '@codemirror/state'
  2. import { setSyntaxValidationEffect } from '../../extensions/language'
  3. import { linter } from '@codemirror/lint'
  4. import { latexLinter } from './linter/latex-linter'
  5. import { lintSourceConfig } from '../../extensions/annotations'
  6. export const linting = () => {
  7. const latexLintSourceConf = new Compartment()
  8. return [
  9. latexLintSourceConf.of([]),
  10. // enable/disable the linter to match the syntaxValidation setting
  11. EditorState.transactionExtender.of(tr => {
  12. for (const effect of tr.effects) {
  13. if (effect.is(setSyntaxValidationEffect)) {
  14. return {
  15. effects: latexLintSourceConf.reconfigure(
  16. effect.value ? linter(latexLinter, lintSourceConfig) : []
  17. ),
  18. }
  19. }
  20. }
  21. return null
  22. }),
  23. ]
  24. }