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

Commit 0de5bcd

Browse files
authored
Merge pull request #12 from gdkrmr/dev
Dev
2 parents 3aa2c26 + d1eb097 commit 0de5bcd

File tree

4 files changed

+171
-38
lines changed

4 files changed

+171
-38
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: julia
22
julia:
33
- 0.5.2
4+
- 0.6
45
# there is no Lint.jl for 0.6 and nightly yet
56

67
# TODO: only test master!
@@ -44,3 +45,8 @@ script:
4445
- make compile
4546
- make test
4647

48+
notifications:
49+
email:
50+
on_success: change
51+
on_failure: always
52+
on_start: never

README.md

Lines changed: 101 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,111 @@ flycheck-julia — Flycheck for Julia
66
[![MELPA Stable](https://stable.melpa.org/packages/flycheck-julia-badge.svg)](https://stable.melpa.org/#/flycheck-julia)
77
[![Build master](https://api.travis-ci.org/gdkrmr/flycheck-julia.svg?branch=master)](https://travis-ci.org/gdkrmr/flycheck-julia)
88

9-
- Add a `julia` syntax checker using [Lint.jl][]
9+
- Add a [Julia][] syntax checker for [Emacs][] and [Flycheck][] using [Lint.jl][]
1010

1111
Installation
12-
------------
12+
=====
1313

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

17-
```elisp
18-
(flycheck-julia-setup)
19-
```
17+
- Install [Lint.jl][] in [Julia][]
2018

21-
Usage
19+
Open julia and run the following commands:
20+
```julia
21+
Pkg.update()
22+
Pkg.add("Lint")
23+
```
24+
25+
- From [MELPA][] or [MELPA Stable][] install the following packages:
26+
27+
- [ess][] or [julia-mode][].
28+
29+
- [flycheck][], detailed instructions can be
30+
found [here](http://www.flycheck.org/en/latest/user/installation.html).
31+
32+
- [flycheck-julia][].
33+
34+
- Add the following to your configuration:
35+
```elisp
36+
(flycheck-julia-setup)
37+
```
38+
39+
Installing from a fresh emacs install
2240
-----
2341

24-
Simply start linting by enabling `flycheck-mode`. If you use
25-
`flycheck-global-mode` and want `flycheck-julia` enabled automatically, then add
26-
the following to your `init.del`:
42+
- Setup your package manager
43+
44+
Add the following to
45+
your
46+
[init file](http://www.flycheck.org/en/latest/glossary.html#term-init-file):
47+
48+
```elisp
49+
(require 'package)
50+
(add-to-list 'package-archives '("MELPA Stable" . "https://stable.melpa.org/packages/"))
51+
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))
52+
(package-initialize)
53+
```
54+
55+
- Install the required packages
56+
57+
Restart emacs and run `M-x list-packages` or choose `Options -> Manage
58+
Packages` from the menu and install `flycheck`, `ess`, and `flycheck-julia`.
2759

60+
In the `*Packages*` buffer you can select packages by pressing `i` and install
61+
all selected packages by pressing `x` or simply use the mouse for interaction.
62+
63+
- Configure emacs for the use with `julia`, `flycheck`, and `flycheck-julia`
64+
65+
Add the following lines at the end of your init file:
66+
67+
```elisp
68+
;; loads ess, which contains ess-julia-mode
69+
(require 'ess-site)
70+
;; enable flycheck globally
71+
(add-hook 'after-init-hook #'global-flycheck-mode)
72+
;; tell flycheck about the julia linter
73+
(flycheck-julia-setup)
74+
```
75+
76+
Installing when using [Spacemacs][]
77+
-----
78+
79+
- Add the following to your `.spacemacs`:
80+
- the [syntax-checking][] and [ess][] layers.
81+
- to `dotspacemacs-additional-packages` add `flycheck-julia`
82+
- to the `dotspacemacs/user-config` function add the following lines:
83+
```elisp
84+
(flycheck-julia-setup)
85+
(add-to-list 'flycheck-global-modes 'julia-mode)
86+
(add-to-list 'flycheck-global-modes 'ess-julia-mode)
87+
```
88+
- Restart Emacs, this should automatically install `ess`, `flycheck`, and `flycheck-julia`
89+
90+
Manual Installing
91+
------
92+
93+
Copy `flycheck-julia.el` somewhere and add the following to your init file:
2894
```elisp
95+
(add-to-list 'load-path "/path/to/directory/containing/flycheck-julia.el/file")
96+
(require 'flycheck-julia)
97+
(flycheck-julia-setup)
2998
(add-to-list 'flycheck-global-modes 'julia-mode)
3099
(add-to-list 'flycheck-global-modes 'ess-julia-mode)
31100
```
32101

102+
Usage
103+
-----
104+
105+
If you configured your Emacs with the instructions above, linting
106+
of Julia files should start automatically. If you did not enable
107+
`global-flycheck-mode`, you can enable linting of Julia files by enabling
108+
`flycheck-mode`.
109+
110+
Interaction with errors is done through `flycheck`, see
111+
the [manual](http://www.flycheck.org/en/latest/user/quickstart.html) for
112+
details.
113+
33114
License
34115
-------
35116

@@ -45,11 +126,19 @@ PARTICULAR PURPOSE. See the GNU General Public License for more details.
45126
You should have received a copy of the GNU General Public License along with
46127
this program. If not, see http://www.gnu.org/licenses/.
47128

48-
See [`LICENSE`][license] for details.
129+
See [LICENSE][] for details.
49130

131+
[Spacemacs]: https://spacemacs.org
132+
[Emacs]: https://www.gnu.org/software/emacs/
133+
[flycheck-julia]: https://github.com/gdkrmr/flycheck-julia
134+
[Julia]: https://julialang.org
50135
[badge-license]: https://img.shields.io/badge/license-GPL_3-green.svg?dummy
51136
[LICENSE]: https://github.com/gdkrmr/flycheck-julia/blob/master/LICENSE
52137
[Flycheck]: http://www.flycheck.org
53138
[Lint.jl]: https://github.com/tonyhffong/Lint.jl
54139
[MELPA]: https://melpa.org
55140
[MELPA Stable]: https://stable.melpa.org
141+
[ess]: http://ess.r-project.org/Manual/ess.html#Installation
142+
[julia-mode]: https://github.com/JuliaEditorSupport/julia-emacs/blob/master/julia-mode.el
143+
[syntax-checking]: http://spacemacs.org/layers/+checkers/syntax-checking/README.html
144+
[ess]: http://spacemacs.org/layers/+lang/ess/README.html

flycheck-julia.el

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
;; URL: https://github.com/gdkrmr/flycheck-julia
77
;; Keywords: convenience, tools, languages
88
;; Version: 0.0.3
9-
;; Package-Requires: ((emacs "25") (flycheck "0.22"))
9+
;; Package-Requires: ((emacs "24") (flycheck "0.22"))
1010

1111
;; This file is not part of GNU Emacs.
1212

@@ -36,8 +36,6 @@
3636
;; ;; Enable Flycheck checker
3737
;; (flycheck-julia-setup)
3838
;;
39-
;; (add-hook 'julia-mode-hook #'flycheck-mode)
40-
;;
4139
;; # Usage
4240
;;
4341
;; Just use Flycheck as usual in julia-mode buffers. Flycheck will
@@ -96,14 +94,6 @@ CHECKER and CALLBACK are flycheck requirements."
9694

9795
(defun flycheck-julia-server-start ()
9896
"Start the julia server for linting."
99-
;; make-process is emacs 25 only:
100-
;; this one does not work anywayse:
101-
;; (make-process
102-
;; :name "flycheck-julia-server"
103-
;; :buffer nil
104-
;; :command '("julia" "-e 'using Lint; lintserver(9999, \"standard-linter-v2\")'")
105-
;; :noquery t
106-
;; :stop nil)
10797
(start-process-shell-command
10898
"flycheck-julia-server" "*julia-linter*"
10999
;; TODO: use pipes or something different than an open port
@@ -125,8 +115,8 @@ CHECKER and CALLBACK are flycheck requirements."
125115
(defun flycheck-julia-server-query (checker)
126116
"Query a lint.
127117
128-
Query a lint for the current buffer and return the errors in a
129-
flycheck compatible format.
118+
Query a lint for the current buffer and return the errors as
119+
flycheck objects.
130120
131121
CHECKER is 'julia-linter, this is a flycheck internal."
132122

@@ -136,37 +126,35 @@ CHECKER is 'julia-linter, this is a flycheck internal."
136126
:name "julia-lint-client"
137127
:host 'local
138128
:service flycheck-julia-port))
139-
(query-list `(("file" . ,buffer-file-name)
129+
(query-list `(("file" . ,(if buffer-file-name (buffer-file-name) ""))
140130
("code_str" . ,(buffer-substring-no-properties
141131
(point-min) (point-max)))
142132
("ignore_info" . ,json-false)
143133
("ignore_warnings" . ,json-false)
144134
("show_code" . t)))
145-
(proc-output ""))
135+
(proc-output nil))
146136

147137
;; Network processes may be return results in different orders, then we are
148138
;; screwed, not sure what to do about this? use named pipes? use sockets?
149139
;; use priority queues?
150140
;; I actually never observed this, so ignoring it for now.
151-
;; TODO: this gives a warning, try to make the warning disappear!
141+
;; TODO: this gives a compiler warning, try to make the warning disappear!
152142
(defun flycheck-julia-keep-output (process output)
153143
(setq proc-output (concat proc-output output)))
154144
(set-process-filter proc 'flycheck-julia-keep-output)
155145

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

158-
;; TODO: because our process is asynchronous, we need to
148+
;; Because our process is asynchronous, we need to
159149
;; 1. to wait and
160150
;; 2. the string is sent in 500 char pieces and the results may arrive in a
161-
;; different order.
151+
;; different order. -> I did not observe this behavior until now!
162152
;; TODO: figure out a way to do this completely asynchronous.
163-
;; wait a maximum of 1 second
164153
(accept-process-output proc flycheck-julia-max-wait)
165-
166154
(flycheck-julia-error-parser
167-
(json-read-from-string proc-output)
168-
checker
169-
(current-buffer))))
155+
(when proc-output (json-read-from-string proc-output))
156+
checker
157+
(current-buffer))))
170158

171159
(defun flycheck-julia-error-parser (errors checker buffer)
172160
"Parse the error returned from the Julia lint server.

test/flycheck-julia-test.el

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,19 @@
3737
:tags '(server)
3838
(flycheck-julia-server-start)
3939
(should (flycheck-julia-serverp))
40-
(flycheck-julia-server-stop))
40+
(flycheck-julia-server-stop)
41+
(sleep-for 5)
42+
(kill-buffer "*julia-linter*"))
4143

4244
(ert-deftest flycheck-julia-kill-server ()
4345
:tags '(server)
4446
(flycheck-julia-server-start)
4547
(sleep-for 5)
4648
(flycheck-julia-server-stop)
4749
(sleep-for 5)
48-
(should (not (flycheck-julia-serverp))))
50+
(should (not (flycheck-julia-serverp)))
51+
(sleep-for 5)
52+
(kill-buffer "*julia-linter*"))
4953

5054
(ert-deftest flycheck-julia-restart-server ()
5155
:tags '(server)
@@ -54,7 +58,53 @@
5458
(flycheck-julia-server-restart)
5559
(sleep-for 5)
5660
(should (flycheck-julia-serverp))
57-
(flycheck-julia-server-stop))
61+
(flycheck-julia-server-stop)
62+
(sleep-for 5)
63+
(kill-buffer "*julia-linter*"))
64+
65+
;; Lint.jl does extensive testing on the correctness of errors, so we only check
66+
;; that querying the server actually works.
67+
;; (ert-deftest flycheck-julia-test-query ()
68+
;; :tags '(query)
69+
;; (flycheck-julia-server-start)
70+
;; (sleep-for 15)
71+
;; (should
72+
;; (with-temp-buffer
73+
;; (insert-string "\ny\n")
74+
;; (ignore-errors
75+
;; (flycheck-julia-server-query 'flycheck-julia)
76+
;; (sleep-for 15)
77+
;; (flycheck-julia-server-query 'flycheck-julia)
78+
;; (sleep-for 15)
79+
;; (flycheck-julia-server-query 'flycheck-julia)
80+
;; (sleep-for 15)
81+
;; (flycheck-julia-server-query 'flycheck-julia)
82+
;; (sleep-for 15)
83+
;; (flycheck-julia-server-query 'flycheck-julia)
84+
;; (sleep-for 15)
85+
;; (flycheck-julia-server-query 'flycheck-julia))
86+
87+
;; ;; some debug stuff:
88+
;; ;; Print out the contents of the julia server process buffer
89+
;; (sleep-for 15)
90+
;; (let ((oldbuf (current-buffer)))
91+
;; (set-buffer (get-buffer "*julia-linter*"))
92+
;; (message (buffer-substring-no-properties (point-min) (point-max)))
93+
;; (set-buffer oldbuf))
94+
;; (message (buffer-name))
95+
96+
;; ;; check for the error
97+
;; ;; (sleep-for 5)
98+
;; (let ((retobj (flycheck-julia-server-query 'flycheck-julia)))
99+
;; (sleep-for 5)
100+
;; (cl-search
101+
;; "undeclared symbol"
102+
;; (aref (nth 0 retobj) 6)))))
103+
;; ;; cleanup
104+
;; (sleep-for 5)
105+
;; (flycheck-julia-server-stop)
106+
;; (sleep-for 5)
107+
;; (kill-buffer "*julia-linter*"))
58108

59109
(provide 'flycheck-julia-test)
60110

0 commit comments

Comments
 (0)