Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #10 from gdkrmr/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
gdkrmr authored Jun 27, 2017
2 parents 792ce3a + c17ea33 commit 3aa2c26
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.elc
\#*\#
.cask*
dist/*
46 changes: 46 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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

8 changes: 8 additions & 0 deletions Cask
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(source gnu)
(source melpa)

(package-file "flycheck-julia.el")

(development
(depends-on "ess")
(depends-on "julia-mode"))
52 changes: 52 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 $<

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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][]

Expand Down
43 changes: 28 additions & 15 deletions flycheck-julia.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;;
Expand All @@ -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."
Expand All @@ -64,20 +67,33 @@
: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)
(funcall callback 'finished nil))
(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:
Expand All @@ -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)
Expand All @@ -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))
Expand All @@ -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))))

Expand Down
61 changes: 61 additions & 0 deletions test/flycheck-julia-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
;;; flycheck-julia-test.el --- Flycheck Julia: Test cases -*- lexical-binding: t; -*-

;; Copyright (C) 2017 Guido Kraemer <guido.kraemer@gmx.de>

;; Author: Guido Kraemer <guido.kraemer@gmx.de>
;; 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 <http://www.gnu.org/licenses/>.

;;; 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

0 comments on commit 3aa2c26

Please sign in to comment.