mirror of
https://github.com/mirego/accent.git
synced 2024-10-05 14:38:05 +03:00
Fix exile process read new line out of order spellcheck
This commit is contained in:
parent
dacb89ba4d
commit
ae92a1cb87
@ -47,10 +47,11 @@ COPY config config
|
||||
RUN mix deps.get --only prod
|
||||
RUN mix deps.compile --only prod
|
||||
|
||||
COPY vendor vendor
|
||||
COPY vendor/language_tool/priv/ vendor/language_tool/priv/
|
||||
RUN cd ./vendor/language_tool/priv/native/languagetool && ./gradlew shadowJar
|
||||
RUN cp ./vendor/language_tool/priv/native/languagetool/app/build/libs/language-tool.jar priv/native/language-tool.jar
|
||||
|
||||
COPY vendor vendor
|
||||
COPY lib lib
|
||||
|
||||
RUN mix compile --only prod
|
||||
|
@ -82,17 +82,29 @@ defmodule LanguageTool.Backend do
|
||||
end
|
||||
|
||||
defp process_check(process, lang, text) do
|
||||
lang = sanitize_lang(lang)
|
||||
Exile.Process.write(process, IO.iodata_to_binary([String.pad_trailing(lang, 7), text, "\n"]))
|
||||
write_process(process, lang, text)
|
||||
|
||||
with {:ok, data} <- Exile.Process.read(process),
|
||||
with {:ok, data} <- read_process_until_result(process),
|
||||
{:ok, data} <- Jason.decode(data) do
|
||||
data
|
||||
else
|
||||
_ -> nil
|
||||
_ ->
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
defp read_process_until_result(process) do
|
||||
case Exile.Process.read(process) do
|
||||
{:ok, "\n"} -> read_process_until_result(process)
|
||||
result -> result
|
||||
end
|
||||
end
|
||||
|
||||
defp write_process(process, lang, text) do
|
||||
lang = sanitize_lang(lang)
|
||||
Exile.Process.write(process, IO.iodata_to_binary([String.pad_trailing(lang, 7), text, "\n"]))
|
||||
end
|
||||
|
||||
defp sanitize_lang(lang) do
|
||||
if lang === "en" do
|
||||
"en-US"
|
||||
|
Loading…
Reference in New Issue
Block a user