Salve is an IPC library that can be used by code editors to easily get autocompletions, replacements, editorconfig suggestions, definitions, and syntax highlighting.
Project description
Salve v0.5.2
Installation
In the Command Line, paste the following: pip install salve_ipc
Description
Salve is an IPC library that can be used by code editors to easily get autocompletions, replacements, editorconfig suggestions, definitions, and syntax highlighting.
Note The first time that the system is loaded or a new server needs to be started it will take a fair bit longer
Documentation
COMMANDS
The COMMANDS
list contains all valid commands to request server output from. If multiple requests of different commands are made they will be kept and held seperately and can be retrieved seperately. Current commands are as follows:
- "autocomplete"
- "replacements"
- "highlight"
- "editorconfig"
- "definition"
These can be imported as string constants (AUTOCOMPLETE
, REPLACEMENTS
, HIGHLIGHT
, EDITORCONFIG
, DEFINITION
) for usage in calling requests and requesting output from the server while getting "spelling checks" from your code editor so to speak (E.G. not very hard to misspell "autocomplete" as "autocopmlete").
Token
type alias
The Token
type alias helps your type checker when you work with Token
's from salve.
generic_tokens
The generic_tokens
list is a list of strings that define all of the generic token types returned by the server which can be mapped to colors for syntax highlighting.
hidden_chars
The hidden_chars
(dict[str, str]
) dictionary holds a bunch of hidden (zero width) characters as keys and then names for them as values. Token
's of type "Hidden_Char" give the index to hidden characters and allow the user to display hidden characters to them that they may not see. These characters appear in code posted on forums or blogs by those hoping to prevent others from simply copy-pasting their code along with many other places.
Response
TypedDict class
The Response
TypedDict classs allows for type checking when handling output from salve_ipc.
is_unicode_letter(char: str) -> bool
The is_unicode_letter()
function returns a boolean if a given word is a unicode letter (includes "_" as special case) which can be useful when trying to find the current word being typed to hand to the IPC for autocompletion.
IPC
Class
Method | Description | Arguments |
---|---|---|
.get_response() |
Gets a response of the requested command | command : str |
.request() |
(Autocomplete) Makes an autocomplete request to the server | command : str, file : str, expected_keywords : list[str], current_word : str |
.request() |
(Replacements) Makes a replacement request to the server | command : str, file : str, expected_keywords : list[str], current_word : str |
.request() |
(highlight) Makes a highlight request to the server | command : str, file : str, language : str , text_range : tuple[int, int] |
.request() |
(Editorconfig) Makes an editorconfig request to the server | command : str, file_path : pathlib.Path | str, definition_starters : list[tuple[str, str]] |
.request() |
(Definition) Makes a definition request to the server | command : str, current_word : str |
.cancel_request() |
Cancels request of command type and removes reponse if it was recieved. Must be called before .get_response() to work |
command : str |
.update_file() |
Updates files stored on the server that are used to get responses | file : str, current_state : str (just the text of the file) |
.remove_file() |
Removes a file of the name given if any exists. Files should only be removed after all requests using the file are completed. | file : str |
.kill_IPC() |
This kills the IPC process and acts as a precaution against wasted CPU when the main thread no longer needs the IPC | None |
Basic Usage:
from time import sleep
from salve_ipc import IPC, Response
def main():
context = IPC()
context.update_file(
"test",
open(__file__, "r+").read() * 20,
)
context.request(
"highlight", file="test", language="python", text_range=(1, 30)
)
sleep(1)
output: Response | None = context.get_response("highlight")
print(output["result"]) # type: ignore
context.kill_IPC()
if __name__ == "__main__":
main()
How to run and contribute
Running
To run the example, move examples/example_usage.py
to the root directory and run with python.
To test newer features or test code in a Pull Review, do the same but move it back after if you plan to make a PR.
Contributing
To contribute, fork the repository, make your changes, and then make a pull request. If you want to add a feature, please open an issue first so it can be discussed. Note that whenever and wherever possible you should try to use stdlib modules rather than external ones.
License
This project is licensed under the MIT License - see the LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for salve_ipc-0.5.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 660a90c3d5972d38ac4bc05d2d8dadc58929bc59a7d3d160a355ffb04aef1e50 |
|
MD5 | 1855774f64c8af5786c8e13d8210ef8f |
|
BLAKE2b-256 | 187eaf4336e4b2a3308a1da5913e9258ec6f21a016e58579eca33a8380caf3cb |