 	 (str (get-string-from-file filePath)))
     (json-read-from-string str)))
 
-
+;; Global variable holding the annotations
 (defvar liquid-annot-table)
-(setq liquid-annot-table (get-json-from-file "/Users/rjhala/tmp/.liquid/flycheck_Foo.hs.json"))
-
-(defun liquid-annot (table row col)
-  "Get annotation from table from identifier at row, col"
-  (let* ((r    (format "%d" row))
-	 (c    (format "%d" col))
-	 (tys  (assoc "types" table))
-	 (ro   (assoc r tys)))
-    (cdr (assoc "ann" (assoc c ro)))))
+
+;; -----------------------------------------------------------------------------------------------
+;; API for getting annots -- alist
+;; -----------------------------------------------------------------------------------------------
+;; (setq liquid-annot-table (get-json-from-file "/Users/rjhala/tmp/.liquid/flycheck_Foo.hs.json"))
+;; 
+;; (defun liquid-annot (table row col)
+;;   "Get annotation from table from identifier at row, col"
+;;   (let* ((r    (format "%d" row))
+;; 	 (c    (format "%d" col))
+;; 	 (tys  (assoc "types" table))
+;; 	 (ro   (assoc r tys)))
+;;     (cdr (assoc "ann" (assoc c ro)))))
+;; -----------------------------------------------------------------------------------------------
+
+;; -----------------------------------------------------------------------------------------------
+;; API for getting annots -- hash-table 
+;; -----------------------------------------------------------------------------------------------
+
+(setq liquid-annot-table 
+      (let ((json-object-type 'hash-table))
+	(get-json-from-file "/Users/rjhala/tmp/.liquid/flycheck_Foo.hs.json")))
+
+(defun gethash-nil (key table) 
+  (if table 
+      (gethash key table nil)
+      nil))
+
+(defun liquid-annot-get (file row col)
+  "Get annotation for identifier at row, col in file"
+  (let* ((table (gethash-nil file liquid-annot-table))
+	 (r     (format "%d" row))
+	 (c     (format "%d" col))
+	 (tys   (gethash-nil "types" table))
+	 (ro    (gethash-nil r tys)))
+    (gethash-nil "ann" (gethash-nil c ro))))
+
+;; -- Display --------------------------------------------------------------
 
 ;; If you want the separate balloon-popup
-(defun liquid-popup-tip (text)
+(defun liquid-tip-popup (text)
+  "Display text in a window popup"
   (if (and (functionp 'ac-quick-help-use-pos-tip-p)
            (ac-quick-help-use-pos-tip-p))
       (pos-tip-show text 'popup-tip-face nil nil 300 popup-tip-max-width)
     (popup-tip text)))
 
 ;; If you just want the ascii-popup
-;; (defun liquid-popup-tip (text)
+;; (defun liquid-tip-popup (text)
+;;  "Display text in ascii popup"
 ;;   (popup-tip text))
 
+
+;; -- Compute range ---------------------------------------------------------
+
+(defvar liquid-id-regexp 
+  (rx (one-or-more (not (in " \n\t()[]{}")))))
 
 (defun liquid-splitters () 
   '( ?\s  ?\t ?\n ?\( ?\) ?\[ ?\] ))

	  (position-col pos)
	  (position-file pos)))

(defun liquid-annot-at-pos-0 (pos)
  "Info to display: just the file/line/constant string"
  (let* ((info  (format "hello!")))
    (format "the information at %s is %s" 
	    (position-string pos)
	    info)))

(defun liquid-ident-at-pos (pos)
  "Return the identifier at a given position"
  (thing-at-point 'word))

(defun liquid-annot-at-pos-1 (pos)
  "Info to display: the identifier at the position or NONE" 
  (let* ((ident (liquid-ident-at-pos pos)))
    (format "the identifier at %s is %s" 
	    (position-string pos) 
	    ident)))

(defun liquid-annot-at-pos-2 (pos)
  "Info to display: the identifier at the position or NONE" 
  (let* ((row (position-row pos))
	 (col (position-col pos)))
    (liquid-annot liquid-annot-table row col)))

(defun liquid-annot-at-pos (pos)
  "Determine info to display"
  (liquid-annot-at-pos-2 pos))

;;;###autoload
(defun liquid-annot-popup ()
  "Popup help about anything at point."
  (interactive)
  (let* ((pos    (liquid-get-position))
	 (ident  (liquid-ident-at-pos pos))
         (annot  (liquid-annot-at-pos pos)))
    (if annot 
	(liquid-popup-tip annot)
        (liquid-popup-tip (format "No annotation for: %s" ident)))))

;;; cloned from  tss-popup-help

(provide 'liquid-tip)


(require 'json)
(require 'ring)
(require 'etags)
;; (require 'flymake)
;; (require 'eldoc)
(require 'pos-tip nil t)
;; (require 'log4e)
;; (require 'yaxception)
(require 'thingatpt)
(require 'button-lock)



(cl-defstruct position file row col)

