From 588ac75ad01487e93899f8d61163551d0fb1dc78 Mon Sep 17 00:00:00 2001 From: Artyom Shalkhakov Date: Fri, 31 Aug 2018 19:36:03 +0600 Subject: FlyCheck integration. Some issues: - since Ur/Web expects to typecheck a project, we "guess" it (which may not be the exact project that you use, maybe we need to improve our heuristics) - lightly tested, but seems to work on my machine --- src/elisp/urweb-flycheck.el | 83 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/elisp/urweb-flycheck.el diff --git a/src/elisp/urweb-flycheck.el b/src/elisp/urweb-flycheck.el new file mode 100644 index 00000000..1f10226b --- /dev/null +++ b/src/elisp/urweb-flycheck.el @@ -0,0 +1,83 @@ +;;; urweb-flycheck.el --- Flycheck: Ur/Web support -*- lexical-binding: t; -*- + +;; Copyright (C) 2018 Artyom Shalkhakov + +;; Author: +;; Artyom Shalkhakov +;; David Christiansen +;; +;; Keywords: tools, languages, convenience +;; Version: 0.1 +;; Package-Requires: ((emacs "24.1") (flycheck "0.22")) + +;; This file is not part of GNU Emacs, but it is distributed under the +;; same conditions. + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the GNU General Public License as +;; published by the Free Software Foundation; either version 2, or (at +;; your option) any later version. + +;; This program is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + +;;; Commentary: + +;; This Flycheck extension provides an 'urweb' syntax checker. +;; +;; # Setup +;; +;; Put the following into your 'init' file: +;; +;; (with-eval-after-load 'flycheck (urweb-flycheck-setup)) +;; +;; Ensure that the Ur/Web compiler is in your PATH +;; + +;;; Code: + +(require 'flycheck) + +(flycheck-define-checker urweb + "Ur/Web checker" + :command ("urweb" "-tc" + (eval (file-name-sans-extension + (car (flycheck-substitute-argument 'source-inplace + 'urweb))))) + ;; filename:1:0: (to 1:0) syntax error found at SYMBOL + ;; /home/artyom/projects/urweb-test/test.ur:1:0: (to 1:38) Some constructor unification variables are undetermined in declaration + ;; (look for them as "") + ;; Decl: + ;; val rec + ;; help : + ;; {} -> Type> (xml ([])) = + ;; fn $x : {} => + ;; case $x of + ;; {} => + ;; return [ Type>] + ;; [xml ([])] _ + ;; (Basis.cdata [] [] "Hello!") + + :error-patterns + ((error line-start (file-name) ":" line ":" column ":" + " (to " (1+ num) ?: (1+ num) ")" + ;; AS: indebted to David Christiansen for this rx expression! + (message (and (* nonl) (* "\n" (not (any "/" "~")) (* nonl)))))) + :modes (urweb-mode)) + +;;;###autoload +(defun urweb-flycheck-setup () + "Setup Flycheck Ur/Web. + +Add `urweb' to `flycheck-checkers'." + (interactive) + (add-to-list 'flycheck-checkers 'urweb)) + +(provide 'urweb-flycheck) +;;; urweb-flycheck.el ends here -- cgit v1.2.3 From 8c2ce9489b3164534532bddd87ba952ee9b66048 Mon Sep 17 00:00:00 2001 From: Artyom Shalkhakov Date: Fri, 31 Aug 2018 19:53:33 +0600 Subject: Flycheck: improving multi-file support --- src/elisp/urweb-flycheck.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/elisp/urweb-flycheck.el b/src/elisp/urweb-flycheck.el index 1f10226b..96b7cc9b 100644 --- a/src/elisp/urweb-flycheck.el +++ b/src/elisp/urweb-flycheck.el @@ -48,7 +48,7 @@ "Ur/Web checker" :command ("urweb" "-tc" (eval (file-name-sans-extension - (car (flycheck-substitute-argument 'source-inplace + (car (flycheck-substitute-argument 'source-original 'urweb))))) ;; filename:1:0: (to 1:0) syntax error found at SYMBOL ;; /home/artyom/projects/urweb-test/test.ur:1:0: (to 1:38) Some constructor unification variables are undetermined in declaration -- cgit v1.2.3 From d1dcdbad6fa310c83aac551e952d752e7d2921ce Mon Sep 17 00:00:00 2001 From: Artyom Shalkhakov Date: Sat, 1 Sep 2018 14:34:03 +0600 Subject: Multi-file projects should work. --- src/elisp/urweb-flycheck.el | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/elisp/urweb-flycheck.el b/src/elisp/urweb-flycheck.el index 96b7cc9b..31433fbc 100644 --- a/src/elisp/urweb-flycheck.el +++ b/src/elisp/urweb-flycheck.el @@ -7,7 +7,7 @@ ;; David Christiansen ;; ;; Keywords: tools, languages, convenience -;; Version: 0.1 +;; Version: 0.2 ;; Package-Requires: ((emacs "24.1") (flycheck "0.22")) ;; This file is not part of GNU Emacs, but it is distributed under the @@ -44,14 +44,28 @@ (require 'flycheck) +(defun urweb-get-flycheck-project-file () + "Guess the location of the nearest urp file." + (let ((bn (buffer-file-name))) + (if bn + (let + ((x (file-name-sans-extension bn)) + (y (file-name-directory bn))) + (cond + ;; file with .urp extension exists? take it + ((file-exists-p (concat x ".urp")) x) + ;; lib.urp exists in this directory? take it + ((file-exists-p (concat y "/lib.urp")) (concat y "/lib")) + ;; fall back to the first .urp file in this directory + ;; or if that fails, use the current file name + (t (or (car (directory-files y nil "\\.urp$")) x))))))) + (flycheck-define-checker urweb "Ur/Web checker" :command ("urweb" "-tc" - (eval (file-name-sans-extension - (car (flycheck-substitute-argument 'source-original - 'urweb))))) + (eval (urweb-get-flycheck-project-file))) ;; filename:1:0: (to 1:0) syntax error found at SYMBOL - ;; /home/artyom/projects/urweb-test/test.ur:1:0: (to 1:38) Some constructor unification variables are undetermined in declaration + ;; filename:1:0: (to 1:38) Some constructor unification variables are undetermined in declaration ;; (look for them as "") ;; Decl: ;; val rec @@ -69,6 +83,9 @@ " (to " (1+ num) ?: (1+ num) ")" ;; AS: indebted to David Christiansen for this rx expression! (message (and (* nonl) (* "\n" (not (any "/" "~")) (* nonl)))))) + :predicate + (lambda () + (buffer-file-name)) :modes (urweb-mode)) ;;;###autoload -- cgit v1.2.3