         (sending-file nil))
     (when tern-buffer-is-dirty
       (setf sending-file t)
-      (push `(files . [((type . "full") (text . ,(buffer-string)) (name . ,(tern-local-filepath)))])
+      (push `(files . [((type . "full") (text . ,(buffer-string)) (name . ,(tern-project-relative-file)))])
             doc))
     (setf callback
           (lambda (port)

    (setf runner
          (lambda (err data)
            (when (< tern-activity-since-command generation)
              (cond ((not err)
                     (when sending-file (setf tern-buffer-is-dirty nil))
                     (with-current-buffer buffer (funcall f data)))
                    ((and (eq (cadar err) 'connection-failed) (not retrying))
                     (setf retrying t)
                     (setf tern-known-port nil)
                     (tern-find-server callback t))
                    ((not silent) (message "Request failed: %s" (cdr err)))))))
    (tern-find-server callback)))

;; Completion

(defun tern-find-definition ()
  (interactive)
  (tern-run-request (lambda (data)
                      (push (cons (buffer-file-name) (point)) tern-find-definition-stack)
                      (let ((too-long (nthcdr 20 tern-find-definition-stack)))
                        (when too-long (setf (cdr too-long) nil)))
                      (tern-go-to-position (concat (tern-project-dir) (cdr (assoc 'file data)))
                                           (1+ (cdr (assoc 'start data)))))
                    `((type . "definition")
                      (file . ,(tern-project-relative-file))
                      (end . ,(1- (point))))))

(defun tern-pop-find-definition ()
