Skip to content

Commit

Permalink
fixes url encoding for curl
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdsk committed Oct 16, 2021
1 parent 4edbe53 commit 7498ec2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
6 changes: 6 additions & 0 deletions lua/prosesitter/backend/langtool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ function M.to_meta(problem)
return issue
end

function M.query(text)
-- Disable whitespace rule (whitespace repetition checking) as comments are often formatted
-- using whitespace. Disable style checking as we use vale for that.
return "language=en-US&disabledCategories=STYLE&disabledRules=WHITESPACE_RULE&text=" .. text
end

function M.add_spans(json)
local problems = vim.fn.json_decode(json)["matches"]
for _, res in ipairs(problems) do
Expand Down
43 changes: 25 additions & 18 deletions lua/prosesitter/on_event/check/check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,42 @@ M.schedualled = false
M.lintreq = "should be set in check.setup"
local job = "should be set in check.setup"

local function langtool_query(text)
-- Disable whitespace rule (whitespace repetition checking) as comments are often formatted
-- using whitespace. Disable style checking as we use vale for that.
return "language=en-US&disabledCategories=STYLE&disabledRules=WHITESPACE_RULE&text=" .. text
end

local cfg = "should be set in check.setup"
local function do_check()
M.schedualled = false
local req = M.lintreq:build()

if shared.langtool_running then
local function post_langtool(json)
local results = langtool.add_spans(json)
marks.mark_results(results, req.areas, "langtool", langtool.to_meta)
log.info(json)
-- local results = langtool.add_spans(json)
-- marks.mark_results(results, req.areas, "langtool", langtool.to_meta)
end

local curl_args = { "--no-progress-meter", "--data", "@-", langtool.url}
async.dispatch_with_stdin(langtool_query(req.text), "curl", curl_args, post_langtool)
log.info("starting check on: ", req.text)
local curl_args = {
"--no-progress-meter",
"--data-urlencode",
"language=en-US",
"--data-urlencode",
"disabledCategories=STYLE",
"--data-urlencode",
"disabledRules=WHITESPACE_RULE",
"--data-urlencode",
"text@-",
langtool.url,
}
async.dispatch_with_stdin(langtool.query(req.text), "curl", curl_args, post_langtool)
end

if cfg.vale_bin ~= nil then
local function post_vale(json)
local results = vim.fn.json_decode(json)["stdin.md"]
marks.mark_results(results, req.areas, "vale", vale.to_meta)
end
local vale_args = { "--config", cfg.vale_cfg, "--no-exit", "--ignore-syntax", "--ext=.md", "--output=JSON" }
async.dispatch_with_stdin(req.text, cfg.vale_bin, vale_args, post_vale)
end
-- if cfg.vale_bin ~= nil then
-- local function post_vale(json)
-- local results = vim.fn.json_decode(json)["stdin.md"]
-- marks.mark_results(results, req.areas, "vale", vale.to_meta)
-- end
-- local vale_args = { "--config", cfg.vale_cfg, "--no-exit", "--ignore-syntax", "--ext=.md", "--output=JSON" }
-- async.dispatch_with_stdin(req.text, cfg.vale_bin, vale_args, post_vale)
-- end
end

function M.cancelled_schedualled()
Expand Down

0 comments on commit 7498ec2

Please sign in to comment.