       (let ((tree (with-current-buffer type-buf
                     (widen)
                     (goto-char (point-min))
-                    (caml-types-build-tree))))
+                    (caml-types-build-tree target-file))))
         (setq caml-types-annotation-tree tree
               caml-types-annotation-date type-date)
         (message "")))))

       (>= r-cnum (elt (elt node 1) 3))))

(defun caml-types-find-location (targ-pos curr node)
  (let ((i 3))
    (if (not (caml-types-pos-inside targ-pos node))
        curr
      (while (and (< i (length node))
                  (not (caml-types-pos-inside targ-pos (elt node i))))
        (setq i (1+ i)))
      (if (elt node 2)
          (setq curr node))
      (if (< i (length node))
          (caml-types-find-location targ-pos curr (elt node i))
        curr))))

(defun caml-types-pos-inside (pos node)
  (let ((left-pos (elt node 0))

            (r-line (string-to-int (match-string 8)))
            (r-bol (string-to-int (match-string 9)))
            (r-cnum (string-to-int (match-string 10))))
        (unless (not (and (string= l-file target-file)
                          (string= r-file target-file)))
          (while (and (re-search-forward "^" () t)
                      (not (looking-at "type"))
                      (not (looking-at "\\\"")))
            (forward-char 1))
          (setq type-info
                (if (looking-at
                            "^type(\n\\(  \\([^\n)]\\|.)\\|\n[^)]\\)*\n\\))")
                    (cons (match-beginning 1) (match-end 1))))
          (setq accu ())
          (while (and stack
                      (caml-types-pos-contains l-cnum r-cnum (car stack)))
            (setq accu (cons (car stack) accu))
            (setq stack (cdr stack)))
          (let* ((left-pos (vector l-file l-line l-bol l-cnum))
                 (right-pos (vector r-file r-line r-bol r-cnum))
                 (node (caml-types-make-node left-pos right-pos type-info
                                             accu)))
            (setq stack (cons node stack))))))
    (if (null stack)
        (let ((dummy-pos (vector "" 0 0 0)))
          (vector dummy-pos dummy-pos ()))
      (let* ((left-pos (elt (car (last stack)) 0))
             (right-pos (elt (car stack) 1)))
        (if (null (cdr stack))
