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 (limited to 'src/elisp') 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(-) (limited to 'src/elisp') 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(-) (limited to 'src/elisp') 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 From 85287c07fff6682c6d3a935efc30aad623e69179 Mon Sep 17 00:00:00 2001 From: FrigoEU Date: Sat, 3 Aug 2019 10:46:18 +0200 Subject: Added emacs functions for getInfo --- src/elisp/urweb-mode.el | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/elisp') diff --git a/src/elisp/urweb-mode.el b/src/elisp/urweb-mode.el index 69b0e23c..1eb9a1eb 100644 --- a/src/elisp/urweb-mode.el +++ b/src/elisp/urweb-mode.el @@ -925,6 +925,32 @@ Optional argument STYLE is currently ignored." (urweb-skip-siblings)) fullname))) +(defun urweb-get-proj-dir (bfn) + (locate-dominating-file + bfn + (lambda (dir) + (some (lambda (f) (s-suffix? ".urp" f)) + (if (f-dir? dir) + (directory-files dir) + (list '(dir))))))) + +(defun urweb-get-info () + (interactive) + (let* + ((row (line-number-at-pos)) + (col (evil-column)) + (bfn (or (buffer-file-name) + "/Users/Simon/ur-proj/testje/a.ur")) + (proj-dir (urweb-get-proj-dir bfn)) + (filename (file-relative-name bfn proj-dir)) + (loc (concat filename ":" (number-to-string row) ":" (number-to-string col))) + ) + (require 'popup) + (message (let + ((default-directory proj-dir)) + (shell-command-to-string (concat "urweb -getInfo " loc))))) + ) + (provide 'urweb-mode) ;;; urweb-mode.el ends here -- cgit v1.2.3 From 870ce334b835614bab3f114b2aa57617f699c6be Mon Sep 17 00:00:00 2001 From: FrigoEU Date: Sat, 3 Aug 2019 11:01:42 +0200 Subject: Cleaned up elisp and added dependencies --- src/elisp/urweb-mode.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/elisp') diff --git a/src/elisp/urweb-mode.el b/src/elisp/urweb-mode.el index 1eb9a1eb..057761ac 100644 --- a/src/elisp/urweb-mode.el +++ b/src/elisp/urweb-mode.el @@ -939,13 +939,14 @@ Optional argument STYLE is currently ignored." (let* ((row (line-number-at-pos)) (col (evil-column)) - (bfn (or (buffer-file-name) - "/Users/Simon/ur-proj/testje/a.ur")) + (bfn (buffer-file-name)) (proj-dir (urweb-get-proj-dir bfn)) (filename (file-relative-name bfn proj-dir)) (loc (concat filename ":" (number-to-string row) ":" (number-to-string col))) ) - (require 'popup) + (require 's) + (require 'f) + (require 'simple) (message (let ((default-directory proj-dir)) (shell-command-to-string (concat "urweb -getInfo " loc))))) -- cgit v1.2.3