Skip to content

Commit

Permalink
Fix exile process read new line out of order spellcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
simonprev committed Apr 4, 2024
1 parent dacb89b commit ae92a1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 16 additions & 4 deletions vendor/language_tool/lib/language_tool/backend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ae92a1c

Please sign in to comment.