emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/haskell-tng-mode bc93c3d 224/385: very alpha hsinspect sup


From: ELPA Syncer
Subject: [nongnu] elpa/haskell-tng-mode bc93c3d 224/385: very alpha hsinspect support
Date: Tue, 5 Oct 2021 23:59:35 -0400 (EDT)

branch: elpa/haskell-tng-mode
commit bc93c3d1282d4ff00fa04b572148a315475e9da6
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>

    very alpha hsinspect support
---
 Cask                               |  1 +
 README.md                          | 34 +++++++++++++++++-
 haskell-tng-contrib-company.el     | 25 ++++++++++++++
 haskell-tng-contrib-smartparens.el |  1 +
 haskell-tng-font-lock.el           |  1 +
 haskell-tng-hsinspect.el           | 70 ++++++++++++++++++++++++++++++++++++++
 haskell-tng-mode.el                |  1 +
 7 files changed, 132 insertions(+), 1 deletion(-)

diff --git a/Cask b/Cask
index f6e916e..eb2614c 100644
--- a/Cask
+++ b/Cask
@@ -27,6 +27,7 @@
 (package-file "haskell-tng-mode.el")
 
 (development
+ (depends-on "company")
  (depends-on "faceup")
  (depends-on "ert-runner")
  ;;(depends-on "undercover")
diff --git a/README.md b/README.md
index aa394c0..d0ee04b 100644
--- a/README.md
+++ b/README.md
@@ -58,13 +58,43 @@ Giving the following commands
 
 Built-in navigation commands such as `forward-symbol`, `forward-sexp` and 
`imenu` work as expected (although 
[`popup-imenu`](https://github.com/ancane/popup-imenu) is recommended).
 
+## `hsinspect`
+
+The optional command line tool `hsinspect` provides semantic information by 
using the `ghc` api.
+
+`hsinspect` must be installed separately for each version of `ghc` that you 
are using.
+
+At the moment only one version of `ghc` is supported at a time (change 
`ghc-8.4.4` to your current `ghc` version):
+
+```
+git clone https://gitlab.com/tseenshe/hsinspect.git
+cd hsinspect
+cabal v2-install -O2 hsinspect --overwrite-policy=always -w ghc-8.4.4
+```
+
+<!-- TODO these installation instructions don't work 
https://github.com/haskell/cabal/issues/6179 -->
+<!-- ```bash -->
+<!-- for v in ghc-8.4.4 ghc-8.6.5 ; do -->
+<!--   cabal v2-install hsinspect --program-suffix=-$v -w $v -->
+<!-- done -->
+<!-- ``` -->
+
+with recommended binding
+
+```lisp
+  :bind
+   (:map haskell-tng-mode-map
+    ("C-c C-i s" . haskell-tng-fqn-at-point))
+```
+
 ## Contrib
 
-Integrations are provided for common libraries (installed separately), enable 
them from `use-package` with
+Integrations are provided for common libraries and external applications 
(installed separately), enable them from `use-package` with
 
 ```lisp
   :config
   (require 'haskell-tng-contrib)
+  (require 'haskell-tng-contrib-company)
   (require 'haskell-tng-contrib-projectile)
   (require 'haskell-tng-contrib-smartparens)
   (require 'haskell-tng-contrib-yasnippet)
@@ -131,6 +161,8 @@ Semantic tooling will likely take the form of a standalone 
cli tool that is call
   - expand import list into explicit list (perhaps via `:browse` but better as 
standalone tool) for symbol-at-point (assuming no shadowing).
   - convert wildcard import to explicit list
   - remove unused imports
+- Exports
+  - visual indicator of what has been exported (hsinspect could do this for 
compilable code)
 - Hoogle integration
   - build local hoogle database for a project
   - local cli jump-to-source of symbol-at-point / type-at-point (i.e. explicit 
fully qualified name)
diff --git a/haskell-tng-contrib-company.el b/haskell-tng-contrib-company.el
new file mode 100644
index 0000000..b98c099
--- /dev/null
+++ b/haskell-tng-contrib-company.el
@@ -0,0 +1,25 @@
+;;; haskell-tng-contrib-company.el --- company mode integration -*- 
lexical-binding: t -*-
+
+;; Copyright (C) 2019 Tseen She
+;; License: GPL 3 or any later version
+
+;;; Commentary:
+;;
+;;  Integration with `company-mode' completions for
+;;
+;;  1. keywords
+;;  2. `hsinspect' contextual completions
+;;
+;;; Code:
+
+(require 'company)
+
+(require 'haskell-tng-hsinspect)
+
+;; TODO keywords
+;; TODO completions for imports (needs to know project wide module list)
+;; TODO completions for symbols (can this be made more contextual)
+;; TODO add-hook and a TNG specific list of default backends
+
+(provide 'haskell-tng-contrib-company)
+;;; haskell-tng-contrib-company.el ends here
diff --git a/haskell-tng-contrib-smartparens.el 
b/haskell-tng-contrib-smartparens.el
index 23d4e29..a8ffc11 100644
--- a/haskell-tng-contrib-smartparens.el
+++ b/haskell-tng-contrib-smartparens.el
@@ -17,6 +17,7 @@
   (sp-local-pair 'haskell-tng-mode (car pair) (cdr pair)
                  :post-handlers '(("| " "SPC"))))
 
+;; TODO use advise instead of redefining the function
 ;; WORKAROUND smartparens indenting all the time
 (defun sp--indent-region (start end &optional column)
   (unless (or
diff --git a/haskell-tng-font-lock.el b/haskell-tng-font-lock.el
index d7830d5..84f415a 100644
--- a/haskell-tng-font-lock.el
+++ b/haskell-tng-font-lock.el
@@ -124,6 +124,7 @@
         (1 'haskell-tng-keyword-face)
         (2 'haskell-tng-module-face)
         (3 'haskell-tng-keyword-face))
+       ;; TODO combinations of as and hiding
        (,(rx-to-string `(: word-start (group "as") word-end (+ space)
                            word-start (group ,conid) word-end))
         (haskell-tng--font-lock-multiline-anchor-rewind) nil
diff --git a/haskell-tng-hsinspect.el b/haskell-tng-hsinspect.el
new file mode 100644
index 0000000..75a4c64
--- /dev/null
+++ b/haskell-tng-hsinspect.el
@@ -0,0 +1,70 @@
+;;; haskell-tng-hsinspect.el --- hsinspect integration -*- lexical-binding: t 
-*-
+
+;; Copyright (C) 2019 Tseen She
+;; License: GPL 3 or any later version
+
+;;; Commentary:
+;;
+;;  `hsinspect' is a companion tool to `haskell-tng' that uses the `ghc' api to
+;;  extract semantic information. This file provides an integration layer and
+;;  some features.
+;;
+;;; Code:
+
+(require 'haskell-tng-compile)
+
+;; TODO automatically installing hsinspect under hsinspect-ghc-X
+
+(defcustom haskell-tng-hsinspect
+  '("cabal" "v2-exec" "-v0" "--")
+  "Launch command for the `hsinspect' external tool."
+  :type 'listp
+  :group 'haskell-tng)
+
+(defun haskell-tng-fqn-at-point ()
+  "Consult the imports in scope and display the fully qualified
+name of the symbol at point in the minibuffer."
+  (interactive)
+  (if-let* ((sym (symbol-name (symbol-at-point)))
+            (found (seq-find
+                    (lambda (names) (member sym names))
+                    (haskell-tng--hsinspect-imports))))
+      ;; TODO multiple hits
+      (message "%s" (car (last found)))
+    (message "<not imported>")))
+
+;; TODO invalidate cache when imports section has changed
+;; TODO is there a way to tell Emacs not to render this in `C-h v'?
+;;      (suggestion is to advise around describe-key)
+(defvar-local haskell-tng--hsinspect-imports nil
+  "Cache for the last `imports' call for this buffer.
+t means the process failed.")
+(defun haskell-tng--hsinspect-imports ()
+  (if haskell-tng--hsinspect-imports
+      (or (eq t haskell-tng--hsinspect-imports)
+          haskell-tng--hsinspect-imports)
+    (setq haskell-tng--hsinspect-imports t) ;; avoid races
+    (ignore-errors (kill-buffer "*hsinspect*"))
+    (let ((default-directory
+            (or
+             (haskell-tng--util-locate-dominating-file
+              haskell-tng--compile-dominating-file)
+             default-directory)))
+      (if (/= 0 (apply
+                 #'call-process
+                 ;; TODO launching the correct hsinspect-ghc-X version
+                 ;; TODO is there a way to pipe into a string not a buffer?
+                 ;; TODO async
+                 (car haskell-tng-hsinspect) nil "*hsinspect*" nil
+                 (append (cdr haskell-tng-hsinspect)
+                         `("hsinspect" "imports" ,buffer-file-name))))
+          (message "hsinspect failed, semantic support disabled")
+        (setq haskell-tng--hsinspect-imports
+              (with-current-buffer "*hsinspect*"
+                (goto-char (point-min))
+                (re-search-forward (rx "(") nil t) ;; sometimes there is junk 
from the launcher
+                (goto-char (match-beginning 0))
+                (read (current-buffer))))))))
+
+(provide 'haskell-tng-hsinspect)
+;;; haskell-tng-hsinspect.el ends here
diff --git a/haskell-tng-mode.el b/haskell-tng-mode.el
index 2c33e6c..470f2d6 100644
--- a/haskell-tng-mode.el
+++ b/haskell-tng-mode.el
@@ -20,6 +20,7 @@
 
 (require 'haskell-tng-compile)
 (require 'haskell-tng-font-lock)
+(require 'haskell-tng-hsinspect)
 (require 'haskell-tng-imenu)
 (require 'haskell-tng-smie)
 (require 'haskell-tng-syntax)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]