diff --git a/.gitignore b/.gitignore index d822feb..3018f41 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *.elc \#*\# +.cask* +dist/* diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b508563 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,46 @@ +language: julia +julia: + - 0.5.2 + # there is no Lint.jl for 0.6 and nightly yet + +# TODO: only test master! + +sudo: false + +cache: + - directories: + - "$HOME/emacs/" + - ".cask/" + - "$HOME/.emacs.d/.cask" + - "$HOME/.julia" + +env: + matrix: + - EMACS_VERSION=24.5 + - EMACS_VERSION=25.2 + - EMACS_VERSION=snapshot + +matrix: + fast_finish: true + allow_failures: + - env: EMACS_VERSION=snapshot + +before_install: + # Install a proper Emacs for testing + - export PATH="$HOME/bin:$PATH" + - wget 'https://raw.githubusercontent.com/flycheck/emacs-travis/master/emacs-travis.mk' + - if [[ -n $EMACS_VERSION ]]; then make -f emacs-travis.mk install_emacs; fi + - if [[ -n $EMACS_VERSION ]]; then make -f emacs-travis.mk install_cask; fi + - if [[ -n $EMACS_VERSION ]]; then emacs --version; fi + # Set up julia + - julia -e "Pkg.update()" + - julia -e 'Pkg.add("Lint")' + - julia -e 'Pkg.build("Lint")' + +install: + - cask install + +script: + - make compile + - make test + diff --git a/Cask b/Cask new file mode 100644 index 0000000..c107764 --- /dev/null +++ b/Cask @@ -0,0 +1,8 @@ +(source gnu) +(source melpa) + +(package-file "flycheck-julia.el") + +(development + (depends-on "ess") + (depends-on "julia-mode")) \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..17ab4df --- /dev/null +++ b/Makefile @@ -0,0 +1,52 @@ +# modified from flycheck-ocaml + +EMACS=emacs +EMACSFLAGS= +CASK=cask +VERSION:=$(shell EMACS=$(EMACS) $(CASK) version) +PKGDIR:=$(shell EMACS=$(EMACS) $(CASK) package-directory) + +export EMACS + + +SRCS=flycheck-julia.el +OBJECTS=$(SRCS:.el=.elc) + +EMACSBATCH=$(EMACS) -Q --batch $(EMACSFLAGS) + +.PHONY: compile dist test \ + clean clean-elc clean-dist clean-deps + +compile : $(OBJECTS) + +dist : + $(CASK) package + +deps : $(PKGDIR) + +# Testing +test : + $(CASK) exec $(EMACSBATCH) \ + -l flycheck-julia.el -l test/flycheck-julia-test.el \ + -f ert-run-tests-batch-and-exit + +# Cleanup targets +clean : clean-elc clean-dist clean-deps + +clean-elc : + rm -rf $(OBJECTS) + +clean-dist : + rm -rf $(DISTDIR) + +clean-deps : + rm -rf .cask/ + +$(PKGDIR) : Cask + $(CASK) install + touch $(PKGDIR) + +%.elc : %.el $(PKGDIR) + $(CASK) exec $(EMACSBATCH) \ + -f batch-byte-compile $< + diff --git a/README.md b/README.md index d28e483..13a6c96 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,7 @@ flycheck-julia — Flycheck for Julia [![License GPL 3][badge-license]][license] [![MELPA](https://melpa.org/packages/flycheck-julia-badge.svg)](https://melpa.org/#/flycheck-julia) [![MELPA Stable](https://stable.melpa.org/packages/flycheck-julia-badge.svg)](https://stable.melpa.org/#/flycheck-julia) - -Add Julia support to [Flycheck][]: +[![Build master](https://api.travis-ci.org/gdkrmr/flycheck-julia.svg?branch=master)](https://travis-ci.org/gdkrmr/flycheck-julia) - Add a `julia` syntax checker using [Lint.jl][] diff --git a/flycheck-julia.el b/flycheck-julia.el index c5e806b..9563f56 100644 --- a/flycheck-julia.el +++ b/flycheck-julia.el @@ -34,7 +34,7 @@ ;; Add the following to your init file: ;; ;; ;; Enable Flycheck checker -;; (flycheck-julia-setup)) +;; (flycheck-julia-setup) ;; ;; (add-hook 'julia-mode-hook #'flycheck-mode) ;; @@ -52,7 +52,10 @@ (defgroup flycheck-julia nil - "flycheck-julia options") + "flycheck-julia options" + :prefix "flycheck-julia" + :group 'flycheck + :link '(url-link :tag "Github" "https://github.com/gdkrmr/flycheck-julia")) (defcustom flycheck-julia-executable "julia" "The executable used for the julia process." @@ -64,13 +67,18 @@ :type 'integer :group 'flycheck-julia) +(defcustom flycheck-julia-max-wait 1 + "The maximum time to wait for an answer from the server." + :type 'number + :group 'flycheck-julia) + (defun flycheck-julia-start-or-query-server (checker callback) "Start a Julia syntax check, init the server if necessary. CHECKER and CALLBACK are flycheck requirements." ;; TODO: use (when ...) here and do the query - (if (not (get-process "flycheck-julia-server")) + (if (not (flycheck-julia-serverp)) (progn (message "no server --- starting") (flycheck-julia-server-start) @@ -78,6 +86,14 @@ CHECKER and CALLBACK are flycheck requirements." (message "server running --- querying") (funcall callback 'finished (flycheck-julia-server-query checker)))) +;; TODO: make these functions interactive +;; needs checking, if the server is already running, closing of the linter +;; buffer, etc... + +(defun flycheck-julia-serverp () + "Check if the lint server is up" + (get-process "flycheck-julia-server")) + (defun flycheck-julia-server-start () "Start the julia server for linting." ;; make-process is emacs 25 only: @@ -100,9 +116,10 @@ CHECKER and CALLBACK are flycheck requirements." "Kill the julia lint server." (kill-process (get-process "flycheck-julia-server"))) -(defun flycheck-julia-sever-restart () +(defun flycheck-julia-server-restart () "Kill the julia lint server and restart it." (flycheck-julia-server-stop) + (sleep-for 5) (flycheck-julia-server-start)) (defun flycheck-julia-server-query (checker) @@ -124,20 +141,16 @@ CHECKER is 'julia-linter, this is a flycheck internal." (point-min) (point-max))) ("ignore_info" . ,json-false) ("ignore_warnings" . ,json-false) - ("show_code" . t)))) - ;; capture the process output - ;; TODO: find a nicer way to do this (i.e. without - ;; global variables), this is taken from the following page: - ;; http://www.math.utah.edu/docs/info/elisp_34.html + ("show_code" . t))) + (proc-output "")) ;; Network processes may be return results in different orders, then we are ;; screwed, not sure what to do about this? use named pipes? use sockets? ;; use priority queues? + ;; I actually never observed this, so ignoring it for now. + ;; TODO: this gives a warning, try to make the warning disappear! (defun flycheck-julia-keep-output (process output) - (setq flycheck-julia-proc-output - (concat flycheck-julia-proc-output output))) - ;; TODO: make this local don't know how. - (setq flycheck-julia-proc-output "") + (setq proc-output (concat proc-output output))) (set-process-filter proc 'flycheck-julia-keep-output) (process-send-string proc (json-encode query-list)) @@ -148,10 +161,10 @@ CHECKER is 'julia-linter, this is a flycheck internal." ;; different order. ;; TODO: figure out a way to do this completely asynchronous. ;; wait a maximum of 1 second - (accept-process-output proc 1) + (accept-process-output proc flycheck-julia-max-wait) (flycheck-julia-error-parser - (json-read-from-string flycheck-julia-proc-output) + (json-read-from-string proc-output) checker (current-buffer)))) diff --git a/test/flycheck-julia-test.el b/test/flycheck-julia-test.el new file mode 100644 index 0000000..386ed9a --- /dev/null +++ b/test/flycheck-julia-test.el @@ -0,0 +1,61 @@ +;;; flycheck-julia-test.el --- Flycheck Julia: Test cases -*- lexical-binding: t; -*- + +;; Copyright (C) 2017 Guido Kraemer + +;; Author: Guido Kraemer +;; URL: https://github.com/gdkrmr/flycheck-julia + +;; This file is not part of GNU Emacs. + +;; 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 3 of the License, 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 this program. If not, see . + +;;; Commentary: + +;; Test cases Flycheck OCaml. + +;;; Code: + + +(require 'flycheck-julia) +(require 'flycheck-ert) + +(load "ess-autoloads.el") +(require 'ess-site) + +(ert-deftest flycheck-julia-start-server () + :tags '(server) + (flycheck-julia-server-start) + (should (flycheck-julia-serverp)) + (flycheck-julia-server-stop)) + +(ert-deftest flycheck-julia-kill-server () + :tags '(server) + (flycheck-julia-server-start) + (sleep-for 5) + (flycheck-julia-server-stop) + (sleep-for 5) + (should (not (flycheck-julia-serverp)))) + +(ert-deftest flycheck-julia-restart-server () + :tags '(server) + (flycheck-julia-server-start) + (sleep-for 5) + (flycheck-julia-server-restart) + (sleep-for 5) + (should (flycheck-julia-serverp)) + (flycheck-julia-server-stop)) + +(provide 'flycheck-julia-test) + +;;; flycheck-julia-test.el ends here