 ;;; ----------------------------------------------------------------------------
 ;;; File Parsing and loading
 
+(defun fsharp-ac--buffer-truename (&optional buf)
+  "Get the truename of BUF, or the current buffer by default.
+For indirect buffers return the truename of the base buffer."
+  (if (buffer-base-buffer buf)
+      (file-truename (buffer-file-name (buffer-base-buffer buf)))
+    (file-truename (buffer-file-name buf))))
+
 (defun fsharp-ac/load-project (file)
   "Load the specified fsproj FILE as a project."
   (interactive
   ;; Prompt user for an fsproj, searching for a default.
    (let* ((proj (fsharp-mode/find-fsproj buffer-file-name))
-          (relproj (file-relative-name proj (file-name-directory buffer-file-name)))
-          (prompt (if proj (format "Path to project (default %s): " relproj)
+          (relproj (when proj (file-relative-name proj (file-name-directory buffer-file-name))))
+          (prompt (if relproj (format "Path to project (default %s): " relproj)
                     "Path to project: ")))
      (list (read-file-name prompt nil (fsharp-mode/find-fsproj buffer-file-name) t))))
 

  (when (fsharp-ac-can-make-request)
    (fsharp-ac-parse-current-buffer)
    (fsharp-ac-send-pos-request "finddecl"
                                (file-truename (buffer-file-name))
                                (line-number-at-pos)
                                (current-column))))


(defun fsharp-ac-can-make-request (&optional quiet)
  "Test whether it is possible to make a request with the compiler binding.
The current buffer must be an F# file that exists on disk."
  (let ((file (fsharp-ac--buffer-truename)))
    (cond
     ((null file)
      (unless quiet
