-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Json format return message for lintserver() #194
Conversation
@TeroFrondelius Can you ping me again when this is ready to be reviewed? I don't have much time these days, so would prefer to look at a final version. |
@davidanthoff sure I will ping you again. Now there is only a fundamental question: should I keep as it is, or should I change that all messages are sent as one json. Now: |
I think we would want to go with one JSON that has an array of messages, right? |
@davidanthoff yes this is my second option. Thus you think it's better? I think it should be relatively easy to implement, I just need second opinion, because I haven't decided which one is better. |
Yes, I think that is better, otherwise we need another "protocol" that defines how different JSON messages are combined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good contribution! Just a few comments.
src/Lint.jl
Outdated
@@ -350,7 +356,54 @@ function lintdir{T<:AbstractString}(dir::T, ctx::LintContext=LintContext()) | |||
ctx.messages | |||
end | |||
|
|||
function readandwritethestream(conn) | |||
function convertmsgtojson(msgs, style) | |||
if style == "LintMessage" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This style is in CamelCase and the others in snake-case; should be made consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the next commit.
src/Lint.jl
Outdated
txt = msg.message | ||
file = msg.file | ||
linenumber = msg.line | ||
errorrange = Array[[linenumber, 0], [linenumber, 80]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't support 0.4 any more so this should be [[linenumber, 0], [linenumber, 80]]
, i.e. leave out the Array
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See issue #195
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, we can leave this until that is fixed.
src/Lint.jl
Outdated
end | ||
|
||
function lintserver(port) | ||
function lintserver(port,style) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use default argument; i.e. style="original behavior"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the next commit.
src/Lint.jl
Outdated
@@ -391,6 +449,10 @@ function lintserver(port) | |||
end | |||
end | |||
|
|||
function lintserver(port) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above, use default argument instead of this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the next commit.
CI is failing on 0.5 |
test/server.jl
Outdated
socket = connect(pipe) | ||
write(socket, json_input * "\n") | ||
json_output = readline(socket) | ||
results_array = JSON.parse(strip(json_output)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need to strip json, here and elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I forgot this one.
src/Lint.jl
Outdated
write(conn, "\n") | ||
else | ||
json_data = readline(conn) | ||
dict_data = JSON.parse(json_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you can parse the connection directly; i.e. JSON.parse(conn)
instead of JSON.parse(readline(conn))
. I recommend that over readline
so the client can send newlines in their JSON if they prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I really appreciate your effort to review and improve my code.
I guess CI is failing, because I haven't updated the REQUIRE file to demand JSON dependency. I will add it to next commit. |
@davidanthoff and @TotalVerb this is ready for the final review. Few questions:
git remote add upstream https://github.com/tonyhffong/Lint.jl.git
git checkout master
git fetch upstream
git merge upstream/master
git push |
FYI: here is the linter-julia code version that uses this version: https://github.com/TeroFrondelius/linter-julia/blob/JSON/lib/linter-julia.coffee |
1 similar comment
I now have a problem with linter-julia json parsing. I need to study what changed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code LGTM now. I just have a few remaining comments about the documentation, which is overall great.
docs/features.md
Outdated
The new protocol for the server is JSON in both input and output: | ||
```json | ||
"{ | ||
\"file\":\"path_to_the_file\", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a Julia string that happens to contain JSON, not JSON. We should not have the \"
and the surrounding ""
in the README.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fixed.
docs/features.md
Outdated
\"show_code\":true | ||
}" | ||
``` | ||
Only the two first `'file'` and `'code_str'` are mandatory fields. For the output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be "file"
and "code_str"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fixed.
docs/features.md
Outdated
``` | ||
Only the two first `'file'` and `'code_str'` are mandatory fields. For the output | ||
there are four different protocols from which the `"lint-message"` is preferred, | ||
because it is the direct match of `LintMessage` and this way will be always up |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't say it is preferred, because the LintMessage
format, while up to date, is subject to change.
docs/features.md
Outdated
julia> conn = connect(pipe_lm) | ||
Base.PipeEndpoint(open, 0 bytes waiting) | ||
|
||
julia> write(conn, json_input1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using JSON.print(conn, Dict(...))
in this example would be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason this didn't work:
julia> conn = connect(pipe_lm)
Base.PipeEndpoint(open, 0 bytes waiting)
julia> JSON.print(conn, json_input1)
connection ended with error MethodError(getindex,("{\"file\":\"none\",\"code_str\":\"something\"}","file"))
julia> conn = connect(pipe_lm)
Base.PipeEndpoint(open, 0 bytes waiting)
julia> write(conn, json_input1)
38
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the noise. I found my mistake. I will push another commit.
@TotalVerb thanks, once again, your valuable comments. I will make the changes. If you wouldn't mind taking another look (or even testing) where is my bug. I had this already working with linter-julia, but then I introduced a bug somewhere, which I haven't been able to find. It can be trivial because there are not so many changes between the working commits and non working. This is the comparison to working version and current, changes in Lint.jl: and in linter-julia: AtomLinter/linter-julia@db8daf9...JSON |
I think I found my bug: TeroFrondelius/Lint.jl@a81d069...TeroFrondelius:ddefddb if haskey(dict_data,"show_code")
if !dict_data["show_code"]
msgtext = "$evar: $txt"
end
else
msgtext = "$code $evar: $txt"
end The bug is the case when |
@tonyhffong or @Michael-Klassen, I think this is ready for merge. @TotalVerb thanks for your help, please comment if there is still something to do. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. @tonyhffong @Michael-Klassen This LGTM.
@TeroFrondelius The merging of #179 has resulted in some merge conflicts; could you resolve those? |
Yes, I will try. |
BTW I changed in REQUIRE: julia 0.5 |
For some reason, Travis did not run. Could you try closing and reopening this PR to restart the CI? |
This pull request is ready.
TODO:
See issue #131
Maybe it's ok to list the old issue here to get it closed: #70
@TotalVerb and @davidanthoff your comments / improvement ideas would be appreciated.
Ps. I still haven't learned the git. Now it shows all the commits also for the previous pull request.