Skip to content
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

Making textLSP more lightweight #35

Merged
merged 4 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ updates:
directory: "/"
schedule:
interval: "monthly"
ignore:
# no longer supports compilation but most packages are not in pypi yet (#29)
- dependency-name: "tree_sitter"
groups:
python-packages:
patterns:
- "*"
exclude-patterns:
- "tree_sitter"
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ install:
pip install .

install-development:
pip install -e .[dev]
pip install -e .[dev,transformers]

install-test:
pip install .[dev]
pip install .[dev,transformers]

uninstall:
pip uninstall textLSP
Expand Down
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# textLSP

Language server for text spell and grammar check with various AI tools.

_This tool is in early development._

![textLSP](https://user-images.githubusercontent.com/414596/219856412-8095caa5-9ce6-49fe-9713-78d234837ac4.png)

# Features
## Features

## LSP features
### LSP features

* Diagnostics:
* spelling or grammatical errors
Expand Down Expand Up @@ -69,9 +70,6 @@ magic command (see the OpenAI analyser below).
</details>
* [hf_completion](https://huggingface.co/docs/transformers/task_summary#language-modeling): Huggingface `fill-mask` pipeline based text completion.
* [Gramformer](https://github.com/PrithivirajDamodaran/Gramformer): Neural network based system.
* Gramformer needs to be installed manually:

```pip install git+https://github.com/PrithivirajDamodaran/Gramformer.git```

### Tools using remote services

Expand All @@ -81,6 +79,9 @@ The following tools use remote text APIs.
Due to potential costs turning off automatic analysis if suggested.

* [OpenAI](https://openai.com/api): Supports text correction as well as text generation through a magic command in the text file.
* A custom URL can be set to use an OpenAI-compatible server. See the example
[configuration](#configuration) below.

<details><summary>Generation showcase</summary>
<img src="https://user-images.githubusercontent.com/414596/219856479-b85b5c2d-6158-44be-9063-12254b76e39c.gif" height=80% width=80%/>
</details>
Expand All @@ -93,9 +94,9 @@ Due to potential costs turning off automatic analysis if suggested.
* markdown
* any other file types as plain text

# Setup
## Setup

## Install
### Install
```
pip install textLSP
```
Expand All @@ -105,7 +106,20 @@ For the latest version:
pip install git+https://github.com/hangyav/textLSP
```

## Running
#### Additional dependencies
Some analyzers need additional dependencies!

* hf_checker, hf_instruction_checker and hf_completion:
```
pip install textLSP[transformers]
```

* Gramformer needs to be installed manually:
```
pip install git+https://github.com/PrithivirajDamodaran/Gramformer.git
```

### Running
Simply run:
```
textlsp
Expand All @@ -120,7 +134,7 @@ or simply over ssh (with ssh key) if the client doesn't support it:
ssh <server> textlsp
```

## Configuration
### Configuration

Using textLSP within an editor depends on the editor of choice.
For a few examples how to set up language servers in general in some of the popular editors see [here](https://github.com/openlawlibrary/pygls/tree/master/examples/hello-world#editor-configurations) or take a look at the related documentation of your editor.
Expand Down Expand Up @@ -194,6 +208,7 @@ textLSP = {
openai = {
enabled = false,
api_key = '<MY_API_KEY>',
-- url = '<CUSTOM_URL>' -- optional to use an OpenAI-compatible server
check_text = {
on_open = false,
on_save = false,
Expand Down
10 changes: 6 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ def read(fname):
'tree_sitter==0.21.3',
'gitpython==3.1.43',
'appdirs==1.4.4',
'torch==2.3.0',
'openai==1.30.5',
'transformers==4.41.2',
'sortedcontainers==2.4.0',
'bitsandbytes==0.43.1',
'langdetect==1.0.9',
'ollama==0.2.0',
],
Expand All @@ -47,6 +44,11 @@ def read(fname):
'python-lsp-jsonrpc==1.1.2',
'pytest-cov==5.0.0',
'coverage-threshold==0.4.4'
]
],
'transformers': [
'torch==2.3.0',
'transformers==4.41.2',
'bitsandbytes==0.43.1',
],
},
)
10 changes: 5 additions & 5 deletions tests/analysers/analyser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def test_diagnostics_bug2(json_converter, langtool_ls_onsave):
langtool_ls_onsave.notify_did_open(
json_converter.unstructure(open_params)
)
assert done.wait(30)
assert done.wait(60)
done.clear()

change_params = DidChangeTextDocumentParams(
Expand All @@ -351,7 +351,7 @@ def test_diagnostics_bug2(json_converter, langtool_ls_onsave):
langtool_ls_onsave.notify_did_change(
json_converter.unstructure(change_params)
)
assert done.wait(30)
assert done.wait(60)
done.clear()

save_params = DidSaveTextDocumentParams(
Expand All @@ -362,7 +362,7 @@ def test_diagnostics_bug2(json_converter, langtool_ls_onsave):
langtool_ls_onsave.notify_did_save(
json_converter.unstructure(save_params)
)
assert done.wait(30)
assert done.wait(60)
done.clear()

change_params = DidChangeTextDocumentParams(
Expand All @@ -383,7 +383,7 @@ def test_diagnostics_bug2(json_converter, langtool_ls_onsave):
langtool_ls_onsave.notify_did_change(
json_converter.unstructure(change_params)
)
assert done.wait(30)
assert done.wait(60)
done.clear()

save_params = DidSaveTextDocumentParams(
Expand All @@ -394,7 +394,7 @@ def test_diagnostics_bug2(json_converter, langtool_ls_onsave):
langtool_ls_onsave.notify_did_save(
json_converter.unstructure(save_params)
)
assert done.wait(30)
assert done.wait(60)
done.clear()

exp_lst = [
Expand Down
4 changes: 2 additions & 2 deletions textLSP/analysers/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ def update_settings(self, settings):
)
except ImportError as e:
self.language_server.show_message(
str(e),
f"Error ({name}): {str(e)}",
MessageType.Error,
)
except ConfigurationError as e:
self.language_server.show_message(
str(e),
f"Error ({name}): {str(e)}",
MessageType.Error,
)

Expand Down
Loading
Loading