linting.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. // TODO: enable this once https://github.com/overleaf/internal/issues/10055 is fixed
  24. // ViewPlugin.define(view => {
  25. // return {
  26. // update(update) {
  27. // // force the linter to run if the selection has changed
  28. // if (update.selectionSet) {
  29. // // note: no timeout needed as this is already asynchronous
  30. // forceLinting(view, true) // TODO: true to force run even if doc hasn't changed
  31. // }
  32. // },
  33. // }
  34. // }),
  35. ]
  36. }