antonWetzel / typst-languagetool

LanguageTool Integration for Typst for spell and grammer check
MIT License
37 stars 9 forks source link

Use existing server instead off local jar file? #15

Closed feuermandel closed 7 months ago

feuermandel commented 7 months ago

Dear Anton,

is there any chance to use typst-languagetool with an existing server within my LAN (I can tunnel any port to localhost via SSH). As running the local jar file consumes a lot ram and cpu un my somehow outdated hardware.

antonWetzel commented 7 months ago

I added the option to use a languagetool server. With the feature remote-server and the options host=... and port=... a remote server is used. The request is only the text content without markup, so long documents should work. The text is not seperated so really long documents might fail.

feuermandel commented 7 months ago

Sad to say, but I am new to rust.

But I finally manged to compile the cli and the lsb on Windows via

cargo install --git=https://github.com/antonWetzel/typst-languagetool lsp --features=remote-server and cargo install --git=https://github.com/antonWetzel/typst-languagetool cli --features=remote-server

I also managed to find the compiled binaries (c:\users\<myuser>\.cargo\bin)

I am able to check a typst file and a complete directory with

typst-languagetool.exe --language "de-DE" --host http://my.server.url --port 8010 check c:\temp\typst\myfile.typ

But when trying to use the lsp in vscode with this configuration

  "generic-lsp.configuration": [        
    {
      "lsp": "C:\\Users\\myuser\\.cargo\\bin\\typst-languagetool-lsp.exe",
      "language": "typst", 
      "options": {
        "host": "http://my.server.url",
        "port": "8010",            
        }
      },
  ]      ,

requests are made, but the lsp gets an error:

starting LSP server Allow Words not supported for Remote LanguageTool unknown notification: Notification { method: "$/cancelRequest", params: Object {"id": Number(1)} } unknown notification: Notification { method: "$/cancelRequest", params: Object {"id": Number(2)} } unknown notification: Notification { method: "$/cancelRequest", params: Object {"id": Number(3)} }

I am sure, I made an error.

BTW, how to I change the language to be checked from en-US to any other language?

antonWetzel commented 7 months ago

Changing the checked language is possible with

...
"options": {
  "language": "de-DE", // code for document language
  "host": "http://my.server.url",
  "port": "8010",
  "dictionary": [
    "word_a",
    "word_b"
  ],
  "disabled_checks": [
    "WHITESPACE_RULE",
  ],
},
...

The first error happens, because there no easy way to add allowed words with a local server. https://forum.languagetool.org/t/it-is-possible-to-add-word-with-local-server-rest-api/6479 I added post-processing step to filter the results based on the allowed words, so allowed words should work for remote now.

The unkown notifications happen, because the LSP-server gets cancel request if a file is saved again before the response. I changed the lsp to ingore them without warning.

antonWetzel commented 7 months ago

An remote LanguageTool server can be used to spellcheck. If this issue still persist, please reopen the issue.

feuermandel commented 6 months ago

Dear Anton,

sometimes I encounter errors with the LSP, as it travels through our proxy.

It there any switch I can use to prevent the LSP from accessing my local LT server over the system proxy?

Best regards

antonWetzel commented 6 months ago

@feuermandel The LSP sends an http-request with the host and port. I think I can't change whatever answers the request.

feuermandel commented 6 months ago

I configured the name of my server within the LAN, so no proxy is neccessary. But - however - I got error messages from the generic lsp giving me error messages from the proxy.

Very strange.


However, today I decided to build the current version of your typst languagetool cli and lsp.

The lsp version sees to run quite well. And after changing my configuration as in your example everything is running with the lsp as well. Thank you very much!

Did I get it right: I have to configure root path and initial document in the settings? May I ask, why you decided to do it this way? I for myself am switching through multiple documents during a working day. And to get the spell check right, if have to change the generic-lsp setting every time I switch a document.