From b0ea8e1df09a46cd2bef2e77952b6d964ac5f483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Fayzrakhmanov=20=28=D0=90=D1=80=D1=82=D1=83=D1=80?= =?UTF-8?q?=20=D0=A4=D0=B0=D0=B9=D0=B7=D1=80=D0=B0=D1=85=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=29?= Date: Sun, 17 Jan 2016 19:47:02 +0500 Subject: [PATCH 1/4] Fix doc stirng (get rid of warning) --- haskell-utils.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/haskell-utils.el b/haskell-utils.el index 5139282ce..e7b4a55ff 100644 --- a/haskell-utils.el +++ b/haskell-utils.el @@ -47,7 +47,8 @@ (defun haskell-utils-read-directory-name (prompt default) "Read directory name and normalize to true absolute path. Refer to `read-directory-name' for the meaning of PROMPT and -DEFAULT. If `haskell-process-load-or-reload-prompt' is nil, accept `default'." +DEFAULT. If `haskell-process-load-or-reload-prompt' is nil, +accept `default'." (let ((filename (file-truename (read-directory-name prompt default default)))) (concat (replace-regexp-in-string "/$" "" filename) "/"))) From e3de99c30df995beb3fbd698ef088932505ee7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Fayzrakhmanov=20=28=D0=90=D1=80=D1=82=D1=83=D1=80?= =?UTF-8?q?=20=D0=A4=D0=B0=D0=B9=D0=B7=D1=80=D0=B0=D1=85=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=29?= Date: Sun, 17 Jan 2016 19:51:35 +0500 Subject: [PATCH 2/4] Refactor haskell-utils-parse-repl-response Doc-string was almost inconsistent with function logic: this function returns a symbol rather than propertized input string. Give a cleaner name, the purpose of this function is test response for errors. Refactor other depended modules to use new name. Fixed TODO in haskell-process. --- haskell-commands.el | 2 +- haskell-process.el | 9 +++++---- haskell-utils.el | 38 +++++++++++++++++++++++++------------- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/haskell-commands.el b/haskell-commands.el index 33f3c07b1..9715d988c 100644 --- a/haskell-commands.el +++ b/haskell-commands.el @@ -639,7 +639,7 @@ happened since function invocation)." (min-pos (caar pos-reg)) (max-pos (cdar pos-reg)) (sig (haskell-utils-reduce-string response)) - (res-type (haskell-utils-parse-repl-response sig))) + (res-type (haskell-utils-repl-response-error-status sig))) (cl-case res-type ;; neither popup presentation buffer diff --git a/haskell-process.el b/haskell-process.el index a68c0415b..b64aff457 100644 --- a/haskell-process.el +++ b/haskell-process.el @@ -297,10 +297,11 @@ Returns NIL when no completions found." (reqstr (concat ":complete repl" mlimit (haskell-string-literal-encode inputstr))) - (rawstr (haskell-process-queue-sync-request process reqstr))) - ;; TODO use haskell-utils-parse-repl-response - (if (string-prefix-p "unknown command " rawstr) - (error "GHCi lacks `:complete' support (try installing 7.8 or ghci-ng)") + (rawstr (haskell-process-queue-sync-request process reqstr)) + (response-status (haskell-utils-repl-response-error-status rawstr))) + (if (eq 'unknown-command response-status) + (error + "GHCi lacks `:complete' support (try installing GHC 7.8+ or ghci-ng)") (let* ((s1 (split-string rawstr "\r?\n" t)) (cs (mapcar #'haskell-string-literal-decode (cdr s1))) (h0 (car s1))) ;; " " diff --git a/haskell-utils.el b/haskell-utils.el index e7b4a55ff..e9b00acce 100644 --- a/haskell-utils.el +++ b/haskell-utils.el @@ -106,25 +106,37 @@ only a single space. Then removes all newlines." (let ((s_ (replace-regexp-in-string "^\s+" " " s))) (replace-regexp-in-string "\n" "" s_))) -(defun haskell-utils-parse-repl-response (r) - "Parse response R from REPL and return special kind of result. -The result is the response string itself with the special property -response-type added. - -This property could be one of the following: +(defun haskell-utils-repl-response-error-status (response) + "Parse response REPL's RESPONSE for errors. +Returns one of the following symbols: + unknown-command + option-missing + interactive-error -+ success" - (let ((first-line (car (split-string r "\n")))) ++ no-error + +*Warning*: this funciton covers only three kind of responses: + +* \"unknown command …\" + REPL missing requested command +* \":3:5: …\" + interactive REPL error +* \"Couldn't guess that module name. Does it exist?\" + (:type-at and maybe some other commands error) +* *all other reposnses* are treated as success reposneses and + 'no-error is returned." + (let ((first-line (car (split-string response "\n" t)))) (cond - ((string-match-p "^unknown command" first-line) 'unknown-command) - ((string-match-p "^Couldn't guess that module name. Does it exist?" - first-line) + ((null first-line) 'no-error) + ((string-match-p "^unknown command" first-line) + 'unknown-command) + ((string-match-p + "^Couldn't guess that module name. Does it exist?" + first-line) 'option-missing) - ((string-match-p "^:" first-line) 'interactive-error) - (t 'success)))) + ((string-match-p "^:" first-line) + 'interactive-error) + (t 'no-error)))) (defun haskell-utils-compose-type-at-command (pos) "Prepare :type-at command to be send to haskell process. From 37e70fcf6b6ba7dcc9dfe6edc96953aee3e4d68d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Fayzrakhmanov=20=28=D0=90=D1=80=D1=82=D1=83=D1=80?= =?UTF-8?q?=20=D0=A4=D0=B0=D0=B9=D0=B7=D1=80=D0=B0=D1=85=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=29?= Date: Sun, 17 Jan 2016 19:56:04 +0500 Subject: [PATCH 3/4] Minor tidy ups. Licencing --- haskell-utils.el | 3 ++- tests/haskell-utils-tests.el | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/haskell-utils.el b/haskell-utils.el index e9b00acce..bd919cafd 100644 --- a/haskell-utils.el +++ b/haskell-utils.el @@ -1,6 +1,7 @@ ;;; haskell-utils.el --- General utility functions used by haskell-mode modules -*- lexical-binding: t -*- -;; Copyright (C) 2013 Herbert Valerio Riedel +;; Copyright © 2013 Herbert Valerio Riedel +;; 2016 Arthur Fayzrakhmanov ;; Author: Herbert Valerio Riedel diff --git a/tests/haskell-utils-tests.el b/tests/haskell-utils-tests.el index acffda417..ce02d452f 100644 --- a/tests/haskell-utils-tests.el +++ b/tests/haskell-utils-tests.el @@ -1,6 +1,6 @@ ;;; haskell-utils-tests.el --- Tests for Haskell utilities package -;; Copyright © 2016 Athur Fayzrakhmanov. All rights reserved. +;; Copyright © 2016 Arthur Fayzrakhmanov. All rights reserved. ;; This file is part of haskell-mode package. ;; You can contact with authors using GitHub issue tracker: @@ -132,7 +132,7 @@ (haskell-utils-parse-import-statement-at-point))))) (ert-deftest type-at-command-composition () - "Test haskell-utils-compose-type-at-command. + "Test `haskell-utils-compose-type-at-command'. Test only position conversion to line and column numbers, do not test last string compontent, it is used in `:type-at` command to provide user friendly output only and could be any string, even From 5741ce7d14bb805c0751c0ef8da10bbd67918f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Fayzrakhmanov=20=28=D0=90=D1=80=D1=82=D1=83=D1=80?= =?UTF-8?q?=20=D0=A4=D0=B0=D0=B9=D0=B7=D1=80=D0=B0=D1=85=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=29?= Date: Sun, 17 Jan 2016 19:56:23 +0500 Subject: [PATCH 4/4] Add tests --- tests/haskell-utils-tests.el | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/haskell-utils-tests.el b/tests/haskell-utils-tests.el index ce02d452f..8738d84f5 100644 --- a/tests/haskell-utils-tests.el +++ b/tests/haskell-utils-tests.el @@ -176,4 +176,29 @@ strings will change in future." (haskell-utils-compose-type-at-command test-b-points)) (should (string-prefix-p ":type-at nil 4 1 4 4" test-a-result)) (should (string-prefix-p ":type-at nil 7 3 8 16" test-b-result))))) + +(ert-deftest parse-repl-response () + "Test `haskell-utils-repl-response-error-status' function." + (let* ((t1-str "unknown command ':type-at'\nuse :? for help.") + (t2-str "\n:3:5: Not in scope: ‘x’") + (t3-str "Couldn't guess that module name. Does it exist?") + (t4-str "Hello World!") + (t5-str " ") + (t6-str "") + (t7-str "\n\n\n\n") + (r1 (haskell-utils-repl-response-error-status t1-str)) + (r2 (haskell-utils-repl-response-error-status t2-str)) + (r3 (haskell-utils-repl-response-error-status t3-str)) + (r4 (haskell-utils-repl-response-error-status t4-str)) + (r5 (haskell-utils-repl-response-error-status t5-str)) + (r6 (haskell-utils-repl-response-error-status t6-str)) + (r7 (haskell-utils-repl-response-error-status t7-str))) + (should (equal r1 'unknown-command)) + (should (equal r2 'interactive-error)) + (should (equal r3 'option-missing)) + (should (equal r4 'no-error)) + (should (equal r5 'no-error)) + (should (equal r6 'no-error)) + (should (equal r7 'no-error)))) + ;;; haskell-utils-tests.el ends here