/** @babel */

import { CompositeDisposable, Disposable } from 'atom'

export default class MarkerManager extends Disposable {
  disposables = new CompositeDisposable()

  constructor (editor) {
    super(() => this.disposables.dispose())

    this.editor = editor
    this.markers = []

    this.disposables.add(latex.log.onMessages((messages, reset) => this.addMarkers(messages, reset)))
    this.disposables.add(new Disposable(() => this.clear()))
    this.disposables.add(this.editor.onDidDestroy(() => this.dispose()))

    this.addMarkers(latex.log.getMessages())
  }

  addMarkers (messages, reset) {
    const filePath = this.editor.getPath()

    if (reset) this.clear()

    if (filePath) {
      for (const message of messages) {
        if (message.filePath && message.range && filePath.includes(message.filePath)) {
          this.addMarker(message)
        }
      }
    }
  }

  addMarker (message) {
    const marker = this.editor.markBufferRange(message.range, { invalidate: 'touch' })
    this.editor.decorateMarker(marker, { type: 'line-number', class: `latex-${message.type}` })
    this.markers.push(marker)
  }

  clear () {
    for (const marker of this.markers) {
      marker.destroy()
    }
    this.markers = []
  }
}

@@ -517,16 +517,190 @@
 ose()))%0A
+    this.disposables.add(atom.config.onDidChange('latex.loggingLevel', () =%3E this.update()))%0A%0A    this.addMarkers(latex.log.getMessages())%0A  %7D%0A%0A  update () %7B%0A    this.clear()
 %0A    thi
@@ -778,52 +778,8 @@
 t) %7B
-%0A    const filePath = this.editor.getPath()%0A
 %0A   
@@ -812,24 +812,37 @@
     if (
-file
+this.editor.get
 Path
+()
 ) %7B%0A    
@@ -889,175 +889,318 @@
     
-if (message.filePath && message.range && filePath.includes(message.filePath)) %7B%0A          this.addMarker(message)%0A        %7D%0A      %7D%0A    %7D%0A  %7D%0A%0A  addMarker (message
+this.addMarker(message.type, message.filePath, message.range)%0A        this.addMarker(message.type, message.logPath, message.logRange)%0A      %7D%0A    %7D%0A  %7D%0A%0A  addMarker (type, filePath, range) %7B%0A    const currentFilePath = this.editor.getPath()%0A    if (filePath && range && currentFilePath.includes(filePath)
 ) %7B%0A
+  
     
@@ -1242,24 +1242,16 @@
 erRange(
-message.
 range, %7B
@@ -1270,24 +1270,26 @@
  'touch' %7D)%0A
+  
     this.edi
@@ -1354,24 +1354,16 @@
 latex-$%7B
-message.
 type%7D%60 %7D
@@ -1360,24 +1360,26 @@
 $%7Btype%7D%60 %7D)%0A
+  
     this.mar
@@ -1396,16 +1396,22 @@
 marker)%0A
+    %7D%0A
   %7D%0A%0A  c

Add markers in log files