Skip to content

Commit 3b20749

Browse files
Add multilspy
1 parent 595f40a commit 3b20749

39 files changed

+14317
-21
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,5 @@ cython_debug/
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161161
.vscode/
162+
163+
multilspy/language_servers/*/static

README.md

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@ MGD uses static analysis to guide the decoding of LMs, to generate code followin
1818

1919
![](figures/motivating_example.png)
2020

21+
## Environment Setup
22+
We use the Python packages listed in [requirements.txt](requirements.txt). Our experiments used python 3.10. It is recommended to install the same with dependencies in an isolated virtual environment. To create a virtual environment using `venv`:
23+
```setup
24+
python3 -m venv venv_monitors4codegen
25+
source venv_monitors4codegen/bin/activate
26+
```
27+
or using conda:
28+
```
29+
conda create -n monitors4codegen python=3.10
30+
conda activate monitors4codegen
31+
```
32+
Further details and instructions on creation of python virtual environments can be found in the [official documentation](https://docs.python.org/3/library/venv.html). Further, we also refer users to [Miniconda](https://docs.conda.io/en/latest/miniconda.html), as an alternative to the above steps for creation of the virtual environment.
33+
34+
To install the requirements for running evaluations as described [below](#2-evaluation-scripts):
35+
36+
```setup
37+
pip3 install -r requirements.txt
38+
```
39+
2140
## 1. Datasets
2241

2342
### Dataset Statistics
@@ -38,25 +57,6 @@ DotPrompts is a set of testcases derived from PragmaticCode, such that each test
3857
The complete description of a testcase in DotPrompts is a tuple - `(repo, classFileName, methodStartIdx, methodStopIdx, dot_idx)`. The dataset is available at [datasets/DotPrompts/dataset.csv](datasets/DotPrompts/dataset.csv).
3958

4059
## 2. Evaluation Scripts
41-
### Environment Setup
42-
We use the Python packages listed in [requirements.txt](requirements.txt). Our experiments used python 3.10. It is recommended to install the same with dependencies in an isolated virtual environment. To create a virtual environment using `venv`:
43-
```setup
44-
python3 -m venv venv_monitors4codegen
45-
source venv_monitors4codegen/bin/activate
46-
```
47-
or using conda:
48-
```
49-
conda create -n monitors4codegen python=3.10
50-
conda activate monitors4codegen
51-
```
52-
Further details and instructions on creation of python virtual environments can be found in the [official documentation](https://docs.python.org/3/library/venv.html). Further, we also refer users to [Miniconda](https://docs.conda.io/en/latest/miniconda.html), as an alternative to the above steps for creation of the virtual environment.
53-
54-
To install the requirements for running evaluation as described below:
55-
56-
```setup
57-
pip3 install -r requirements.txt
58-
```
59-
6060
### Running the evaluation script
6161
The evaluation script can be run as follows:
6262
```
@@ -101,8 +101,49 @@ python3 evaluation_scripts/eval_results.py inference_results/dotprompts_results.
101101
The above command creates a directory [results](results/) (already included in the repository), containing all the figures and tables provided in the paper along with extra details. The command also generates a report in the output directory which relates the generated figures to sections in the paper. In case of above command, the report is generated at [results/Report.md](results/Report.md).
102102

103103
## 4. `multilspy`
104+
`multilspy` is a cross-platform library to set up and interact with various language servers in a unified and easy way. [Language servers]((https://microsoft.github.io/language-server-protocol/overviews/lsp/overview/)) are tools that perform a variety of static analyses on source code and provide useful information such as type-directed code completion suggestions, symbol definition locations, symbol references, etc., over the [Language Server Protocol (LSP)](https://microsoft.github.io/language-server-protocol/overviews/lsp/overview/). `multilspy` intends to ease the process of using language servers, by abstracting the setting up of the language servers, performing language-specific configuration and handling communication with the server over the json-rpc based protocol, while exposing a simple interface to the user.
105+
106+
Since LSP is language-agnostic, `multilspy` can provide the results for static analyses of code in different languages over a common interface. `multilspy` is easily extensible to any language that has a Language Server and currently supports Java, Rust, C# and Python and we aim to support more language servers from the [list of language server implementations](https://microsoft.github.io/language-server-protocol/implementors/servers/).
107+
108+
Some of the analyses results that `multilspy` can provide are:
109+
- Finding the definition of a function or a class ([textDocument/definition](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_definition))
110+
- Finding the callers of a function or the instantiations of a class ([textDocument/references](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_references))
111+
- Providing type-based dereference completions ([textDocument/completion](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_completion))
112+
113+
Example usage:
114+
```python
115+
from multilspy import SyncLanguageServer
116+
from multilspy.multilspy_config import MultilspyConfig
117+
from multilspy.multilspy_logger import MultilspyLogger
118+
...
119+
config = MultilspyConfig.from_dict({"code_language": "java"})
120+
logger = MultilspyLogger()
121+
lsp = SyncLanguageServer.create(config, logger, "/abs/path/to/project/root/")
122+
with lsp.start_server():
123+
result = lsp.request_definition(
124+
"relative/path/to/code_file.java", # Filename of location where request is being made
125+
163, # line number of symbol for which request is being made
126+
4 # column number of symbol for which request is being made
127+
)
128+
...
129+
```
104130

105-
Coming Soon...
131+
`multilspy` also provides an asyncio based API which can be used in async contexts. Example usage (asyncio):
132+
```python
133+
from multilspy import LanguageServer
134+
...
135+
lsp = LanguageServer.create(...)
136+
async with lsp.start_server():
137+
result = await lsp.request_definition(
138+
...
139+
)
140+
...
141+
```
142+
143+
Several tests for `multilspy` present under [tests/multilspy/](tests/multilspy/) provide detailed usage examples for `multilspy`. The tests can be executed by running:
144+
```bash
145+
pytest tests/multilspy
146+
```
106147

107148
## 5. Monitor-Guided Decoding
108149

multilspy/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""
2+
This module contains the multilspy API
3+
"""
4+
5+
from . import multilspy_types as Types
6+
from .language_server import LanguageServer, SyncLanguageServer
7+
8+
__all__ = ["LanguageServer", "Types", "SyncLanguageServer"]

0 commit comments

Comments
 (0)