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 #12 from gdkrmr/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
gdkrmr authored Jul 15, 2017
2 parents 3aa2c26 + d1eb097 commit 0de5bcd
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 38 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: julia
julia:
- 0.5.2
- 0.6
# there is no Lint.jl for 0.6 and nightly yet

# TODO: only test master!
Expand Down Expand Up @@ -44,3 +45,8 @@ script:
- make compile
- make test

notifications:
email:
on_success: change
on_failure: always
on_start: never
113 changes: 101 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,111 @@ flycheck-julia — Flycheck for Julia
[![MELPA Stable](https://stable.melpa.org/packages/flycheck-julia-badge.svg)](https://stable.melpa.org/#/flycheck-julia)
[![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][]
- Add a [Julia][] syntax checker for [Emacs][] and [Flycheck][] using [Lint.jl][]

Installation
------------
=====

Install `flycheck-julia` from [MELPA][] or [MELPA Stable][]
and add the following to your `init.el`:
General instructions
-----

```elisp
(flycheck-julia-setup)
```
- Install [Lint.jl][] in [Julia][]

Usage
Open julia and run the following commands:
```julia
Pkg.update()
Pkg.add("Lint")
```

- From [MELPA][] or [MELPA Stable][] install the following packages:

- [ess][] or [julia-mode][].

- [flycheck][], detailed instructions can be
found [here](http://www.flycheck.org/en/latest/user/installation.html).

- [flycheck-julia][].

- Add the following to your configuration:
```elisp
(flycheck-julia-setup)
```

Installing from a fresh emacs install
-----

Simply start linting by enabling `flycheck-mode`. If you use
`flycheck-global-mode` and want `flycheck-julia` enabled automatically, then add
the following to your `init.del`:
- Setup your package manager

Add the following to
your
[init file](http://www.flycheck.org/en/latest/glossary.html#term-init-file):

```elisp
(require 'package)
(add-to-list 'package-archives '("MELPA Stable" . "https://stable.melpa.org/packages/"))
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))
(package-initialize)
```

- Install the required packages

Restart emacs and run `M-x list-packages` or choose `Options -> Manage
Packages` from the menu and install `flycheck`, `ess`, and `flycheck-julia`.

In the `*Packages*` buffer you can select packages by pressing `i` and install
all selected packages by pressing `x` or simply use the mouse for interaction.

- Configure emacs for the use with `julia`, `flycheck`, and `flycheck-julia`

Add the following lines at the end of your init file:

```elisp
;; loads ess, which contains ess-julia-mode
(require 'ess-site)
;; enable flycheck globally
(add-hook 'after-init-hook #'global-flycheck-mode)
;; tell flycheck about the julia linter
(flycheck-julia-setup)
```

Installing when using [Spacemacs][]
-----

- Add the following to your `.spacemacs`:
- the [syntax-checking][] and [ess][] layers.
- to `dotspacemacs-additional-packages` add `flycheck-julia`
- to the `dotspacemacs/user-config` function add the following lines:
```elisp
(flycheck-julia-setup)
(add-to-list 'flycheck-global-modes 'julia-mode)
(add-to-list 'flycheck-global-modes 'ess-julia-mode)
```
- Restart Emacs, this should automatically install `ess`, `flycheck`, and `flycheck-julia`
Manual Installing
------
Copy `flycheck-julia.el` somewhere and add the following to your init file:
```elisp
(add-to-list 'load-path "/path/to/directory/containing/flycheck-julia.el/file")
(require 'flycheck-julia)
(flycheck-julia-setup)
(add-to-list 'flycheck-global-modes 'julia-mode)
(add-to-list 'flycheck-global-modes 'ess-julia-mode)
```

Usage
-----

If you configured your Emacs with the instructions above, linting
of Julia files should start automatically. If you did not enable
`global-flycheck-mode`, you can enable linting of Julia files by enabling
`flycheck-mode`.

Interaction with errors is done through `flycheck`, see
the [manual](http://www.flycheck.org/en/latest/user/quickstart.html) for
details.

License
-------

Expand All @@ -45,11 +126,19 @@ 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/.

See [`LICENSE`][license] for details.
See [LICENSE][] for details.

[Spacemacs]: https://spacemacs.org
[Emacs]: https://www.gnu.org/software/emacs/
[flycheck-julia]: https://github.com/gdkrmr/flycheck-julia
[Julia]: https://julialang.org
[badge-license]: https://img.shields.io/badge/license-GPL_3-green.svg?dummy
[LICENSE]: https://github.com/gdkrmr/flycheck-julia/blob/master/LICENSE
[Flycheck]: http://www.flycheck.org
[Lint.jl]: https://github.com/tonyhffong/Lint.jl
[MELPA]: https://melpa.org
[MELPA Stable]: https://stable.melpa.org
[ess]: http://ess.r-project.org/Manual/ess.html#Installation
[julia-mode]: https://github.com/JuliaEditorSupport/julia-emacs/blob/master/julia-mode.el
[syntax-checking]: http://spacemacs.org/layers/+checkers/syntax-checking/README.html
[ess]: http://spacemacs.org/layers/+lang/ess/README.html
34 changes: 11 additions & 23 deletions flycheck-julia.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;; URL: https://github.com/gdkrmr/flycheck-julia
;; Keywords: convenience, tools, languages
;; Version: 0.0.3
;; Package-Requires: ((emacs "25") (flycheck "0.22"))
;; Package-Requires: ((emacs "24") (flycheck "0.22"))

;; This file is not part of GNU Emacs.

Expand Down Expand Up @@ -36,8 +36,6 @@
;; ;; Enable Flycheck checker
;; (flycheck-julia-setup)
;;
;; (add-hook 'julia-mode-hook #'flycheck-mode)
;;
;; # Usage
;;
;; Just use Flycheck as usual in julia-mode buffers. Flycheck will
Expand Down Expand Up @@ -96,14 +94,6 @@ CHECKER and CALLBACK are flycheck requirements."

(defun flycheck-julia-server-start ()
"Start the julia server for linting."
;; make-process is emacs 25 only:
;; this one does not work anywayse:
;; (make-process
;; :name "flycheck-julia-server"
;; :buffer nil
;; :command '("julia" "-e 'using Lint; lintserver(9999, \"standard-linter-v2\")'")
;; :noquery t
;; :stop nil)
(start-process-shell-command
"flycheck-julia-server" "*julia-linter*"
;; TODO: use pipes or something different than an open port
Expand All @@ -125,8 +115,8 @@ CHECKER and CALLBACK are flycheck requirements."
(defun flycheck-julia-server-query (checker)
"Query a lint.
Query a lint for the current buffer and return the errors in a
flycheck compatible format.
Query a lint for the current buffer and return the errors as
flycheck objects.
CHECKER is 'julia-linter, this is a flycheck internal."

Expand All @@ -136,37 +126,35 @@ CHECKER is 'julia-linter, this is a flycheck internal."
:name "julia-lint-client"
:host 'local
:service flycheck-julia-port))
(query-list `(("file" . ,buffer-file-name)
(query-list `(("file" . ,(if buffer-file-name (buffer-file-name) ""))
("code_str" . ,(buffer-substring-no-properties
(point-min) (point-max)))
("ignore_info" . ,json-false)
("ignore_warnings" . ,json-false)
("show_code" . t)))
(proc-output ""))
(proc-output nil))

;; 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!
;; TODO: this gives a compiler warning, try to make the warning disappear!
(defun flycheck-julia-keep-output (process output)
(setq proc-output (concat proc-output output)))
(set-process-filter proc 'flycheck-julia-keep-output)

(process-send-string proc (json-encode query-list))

;; TODO: because our process is asynchronous, we need to
;; Because our process is asynchronous, we need to
;; 1. to wait and
;; 2. the string is sent in 500 char pieces and the results may arrive in a
;; different order.
;; different order. -> I did not observe this behavior until now!
;; TODO: figure out a way to do this completely asynchronous.
;; wait a maximum of 1 second
(accept-process-output proc flycheck-julia-max-wait)

(flycheck-julia-error-parser
(json-read-from-string proc-output)
checker
(current-buffer))))
(when proc-output (json-read-from-string proc-output))
checker
(current-buffer))))

(defun flycheck-julia-error-parser (errors checker buffer)
"Parse the error returned from the Julia lint server.
Expand Down
56 changes: 53 additions & 3 deletions test/flycheck-julia-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@
:tags '(server)
(flycheck-julia-server-start)
(should (flycheck-julia-serverp))
(flycheck-julia-server-stop))
(flycheck-julia-server-stop)
(sleep-for 5)
(kill-buffer "*julia-linter*"))

(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))))
(should (not (flycheck-julia-serverp)))
(sleep-for 5)
(kill-buffer "*julia-linter*"))

(ert-deftest flycheck-julia-restart-server ()
:tags '(server)
Expand All @@ -54,7 +58,53 @@
(flycheck-julia-server-restart)
(sleep-for 5)
(should (flycheck-julia-serverp))
(flycheck-julia-server-stop))
(flycheck-julia-server-stop)
(sleep-for 5)
(kill-buffer "*julia-linter*"))

;; Lint.jl does extensive testing on the correctness of errors, so we only check
;; that querying the server actually works.
;; (ert-deftest flycheck-julia-test-query ()
;; :tags '(query)
;; (flycheck-julia-server-start)
;; (sleep-for 15)
;; (should
;; (with-temp-buffer
;; (insert-string "\ny\n")
;; (ignore-errors
;; (flycheck-julia-server-query 'flycheck-julia)
;; (sleep-for 15)
;; (flycheck-julia-server-query 'flycheck-julia)
;; (sleep-for 15)
;; (flycheck-julia-server-query 'flycheck-julia)
;; (sleep-for 15)
;; (flycheck-julia-server-query 'flycheck-julia)
;; (sleep-for 15)
;; (flycheck-julia-server-query 'flycheck-julia)
;; (sleep-for 15)
;; (flycheck-julia-server-query 'flycheck-julia))

;; ;; some debug stuff:
;; ;; Print out the contents of the julia server process buffer
;; (sleep-for 15)
;; (let ((oldbuf (current-buffer)))
;; (set-buffer (get-buffer "*julia-linter*"))
;; (message (buffer-substring-no-properties (point-min) (point-max)))
;; (set-buffer oldbuf))
;; (message (buffer-name))

;; ;; check for the error
;; ;; (sleep-for 5)
;; (let ((retobj (flycheck-julia-server-query 'flycheck-julia)))
;; (sleep-for 5)
;; (cl-search
;; "undeclared symbol"
;; (aref (nth 0 retobj) 6)))))
;; ;; cleanup
;; (sleep-for 5)
;; (flycheck-julia-server-stop)
;; (sleep-for 5)
;; (kill-buffer "*julia-linter*"))

(provide 'flycheck-julia-test)

Expand Down

0 comments on commit 0de5bcd

Please sign in to comment.