scubalspy 0.0.16__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. scubalspy-0.0.16/LICENSE +21 -0
  2. scubalspy-0.0.16/PKG-INFO +187 -0
  3. scubalspy-0.0.16/README.md +159 -0
  4. scubalspy-0.0.16/pyproject.toml +46 -0
  5. scubalspy-0.0.16/src/scubalspy/__init__.py +8 -0
  6. scubalspy-0.0.16/src/scubalspy/language_server.py +876 -0
  7. scubalspy-0.0.16/src/scubalspy/language_servers/clangd_language_server/clangd_language_server.py +187 -0
  8. scubalspy-0.0.16/src/scubalspy/language_servers/clangd_language_server/initialize_params.json +36 -0
  9. scubalspy-0.0.16/src/scubalspy/language_servers/clangd_language_server/runtime_dependencies.json +29 -0
  10. scubalspy-0.0.16/src/scubalspy/language_servers/dart_language_server/dart_language_server.py +147 -0
  11. scubalspy-0.0.16/src/scubalspy/language_servers/dart_language_server/initialize_params.json +23 -0
  12. scubalspy-0.0.16/src/scubalspy/language_servers/dart_language_server/runtime_dependencies.json +13 -0
  13. scubalspy-0.0.16/src/scubalspy/language_servers/eclipse_jdtls/eclipse_jdtls.py +404 -0
  14. scubalspy-0.0.16/src/scubalspy/language_servers/eclipse_jdtls/initialize_params.json +849 -0
  15. scubalspy-0.0.16/src/scubalspy/language_servers/eclipse_jdtls/runtime_dependencies.json +72 -0
  16. scubalspy-0.0.16/src/scubalspy/language_servers/gopls/gopls.py +151 -0
  17. scubalspy-0.0.16/src/scubalspy/language_servers/gopls/initialize_params.json +36 -0
  18. scubalspy-0.0.16/src/scubalspy/language_servers/jedi_language_server/initialize_params.json +909 -0
  19. scubalspy-0.0.16/src/scubalspy/language_servers/jedi_language_server/jedi_server.py +120 -0
  20. scubalspy-0.0.16/src/scubalspy/language_servers/kotlin_language_server/initialize_params.json +521 -0
  21. scubalspy-0.0.16/src/scubalspy/language_servers/kotlin_language_server/kotlin_language_server.py +233 -0
  22. scubalspy-0.0.16/src/scubalspy/language_servers/kotlin_language_server/runtime_dependencies.json +41 -0
  23. scubalspy-0.0.16/src/scubalspy/language_servers/omnisharp/initialize_params.json +631 -0
  24. scubalspy-0.0.16/src/scubalspy/language_servers/omnisharp/omnisharp.py +408 -0
  25. scubalspy-0.0.16/src/scubalspy/language_servers/omnisharp/runtime_dependencies.json +441 -0
  26. scubalspy-0.0.16/src/scubalspy/language_servers/omnisharp/workspace_did_change_configuration.json +111 -0
  27. scubalspy-0.0.16/src/scubalspy/language_servers/rust_analyzer/initialize_params.json +917 -0
  28. scubalspy-0.0.16/src/scubalspy/language_servers/rust_analyzer/runtime_dependencies.json +29 -0
  29. scubalspy-0.0.16/src/scubalspy/language_servers/rust_analyzer/rust_analyzer.py +181 -0
  30. scubalspy-0.0.16/src/scubalspy/language_servers/solargraph/initialize_params.json +15 -0
  31. scubalspy-0.0.16/src/scubalspy/language_servers/solargraph/runtime_dependencies.json +11 -0
  32. scubalspy-0.0.16/src/scubalspy/language_servers/solargraph/solargraph.py +187 -0
  33. scubalspy-0.0.16/src/scubalspy/language_servers/typescript_language_server/initialize_params.json +906 -0
  34. scubalspy-0.0.16/src/scubalspy/language_servers/typescript_language_server/runtime_dependencies.json +16 -0
  35. scubalspy-0.0.16/src/scubalspy/language_servers/typescript_language_server/typescript_language_server.py +201 -0
  36. scubalspy-0.0.16/src/scubalspy/lsp_protocol_handler/lsp_constants.py +62 -0
  37. scubalspy-0.0.16/src/scubalspy/lsp_protocol_handler/lsp_requests.py +617 -0
  38. scubalspy-0.0.16/src/scubalspy/lsp_protocol_handler/lsp_types.py +5905 -0
  39. scubalspy-0.0.16/src/scubalspy/lsp_protocol_handler/server.py +573 -0
  40. scubalspy-0.0.16/src/scubalspy/multilspy_config.py +47 -0
  41. scubalspy-0.0.16/src/scubalspy/multilspy_exceptions.py +14 -0
  42. scubalspy-0.0.16/src/scubalspy/multilspy_logger.py +61 -0
  43. scubalspy-0.0.16/src/scubalspy/multilspy_settings.py +27 -0
  44. scubalspy-0.0.16/src/scubalspy/multilspy_types.py +284 -0
  45. scubalspy-0.0.16/src/scubalspy/multilspy_utils.py +259 -0
  46. scubalspy-0.0.16/src/scubalspy/type_helpers.py +24 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
@@ -0,0 +1,187 @@
1
+ Metadata-Version: 2.4
2
+ Name: scubalspy
3
+ Version: 0.0.16
4
+ Summary: A language-agnostic LSP client in Python, with a library interface. Intended to be used to build applications around language servers. Currently scubalspy supports language servers for Python, Rust, Java, Go, JavaScript, Ruby, C# and Dart. Originally appeared as part of Monitor-Guided Decoding (https://github.com/microsoft/monitors4codegen)
5
+ Author-email: Lakshya A Agrawal <lakshya.aagrawal@gmail.com>, SunBK201 <sunbk201gm@gmail.com>
6
+ Requires-Python: >=3.8, <4.0
7
+ Description-Content-Type: text/markdown
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Development Status :: 2 - Pre-Alpha
11
+ Classifier: Topic :: Software Development
12
+ Classifier: Topic :: Text Editors :: Integrated Development Environments (IDE)
13
+ Classifier: Programming Language :: C#
14
+ Classifier: Programming Language :: Java
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Rust
17
+ Classifier: Programming Language :: JavaScript
18
+ Classifier: Programming Language :: Go
19
+ Classifier: Programming Language :: Ruby
20
+ License-File: LICENSE
21
+ Requires-Dist: jedi-language-server==0.41.3
22
+ Requires-Dist: requests==2.32.3
23
+ Requires-Dist: typing-extensions>=4.2.0
24
+ Requires-Dist: psutil (>=7.0.0,<8.0.0)
25
+ Project-URL: Bug Tracker, https://github.com/SunBK201/scubalspy-scubatrace/issues
26
+ Project-URL: Homepage, https://github.com/SunBK201/scubalspy-scubatrace
27
+
28
+ [![PyPI - Version](https://img.shields.io/pypi/v/scubalspy)](https://pypi.org/project/scubalspy/)
29
+ # Scubalspy: LSP client library in Python to build applications around language servers
30
+
31
+ ## Introduction
32
+ This repository hosts `scubalspy`, a library developed as part of research conducted for NeruIPS 2023 paper titled ["Monitor-Guided Decoding of Code LMs with Static Analysis of Repository Context"](https://neurips.cc/virtual/2023/poster/70362) (["Guiding Language Models of Code with Global Context using Monitors"](https://arxiv.org/abs/2306.10763) on Arxiv). The paper introduces Monitor-Guided Decoding (MGD) for code generation using Language Models, where a monitor uses static analysis to guide the decoding, ensuring that the generated code follows various correctness properties, like absence of hallucinated symbol names, valid order of method calls, etc. For further details about Monitor-Guided Decoding, please refer to the paper and GitHub repository [microsoft/monitors4codegen](https://github.com/microsoft/monitors4codegen).
33
+
34
+ `scubalspy` is a cross-platform library designed to simplify the process of creating language server clients to query and obtain results of various static analyses from a wide variety of language servers that communicate over the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/). It is easily extensible to support any [language that has a Language Server](https://microsoft.github.io/language-server-protocol/implementors/servers/) and we aim to continuously add support for more language servers and languages.
35
+
36
+ [Language servers]((https://microsoft.github.io/language-server-protocol/overviews/lsp/overview/)) are tools that perform a variety of static analyses on code repositories 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/). Since LSP is language-agnostic, `scubalspy` can provide the results for static analyses of code in different languages over a common interface.
37
+
38
+ `scubalspy` intends to ease the process of using language servers, by handling various steps in using a language server:
39
+ * Automatically handling the download of platform-specific server binaries, and setup/teardown of language servers
40
+ * Handling JSON-RPC based communication between the client and the server
41
+ * Maintaining and passing hand-tuned server and language specific configuration parameters
42
+ * Providing a simple API to the user, while executing all steps of server-specific protocol steps to execute the query/request.
43
+
44
+ Some of the analysis results that `scubalspy` can provide are:
45
+ - 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))
46
+ - 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))
47
+ - Providing type-based dereference completions ([textDocument/completion](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_completion))
48
+ - Getting information displayed when hovering over symbols, like method signature ([textDocument/hover](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_hover))
49
+ - Getting list/tree of all symbols defined in a given file, along with symbol type like class, method, etc. ([textDocument/documentSymbol](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_documentSymbol))
50
+ - Please create an issue/PR to add any other LSP request not listed above
51
+
52
+ ## Installation
53
+ It is ideal to create a new virtual environment with `python>=3.10`. To create a virtual environment using conda and activate it:
54
+ ```
55
+ conda create -n scubalspy_env python=3.10
56
+ conda activate scubalspy_env
57
+ ```
58
+ 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.
59
+
60
+ To install `scubalspy` using pip, execute the following command:
61
+ ```
62
+ pip install scubalspy
63
+ ```
64
+
65
+ ## Supported Languages
66
+ `scubalspy` currently supports the following languages:
67
+ | Code Language | Language Server |
68
+ | --- | --- |
69
+ | java | Eclipse JDTLS |
70
+ | python | jedi-language-server |
71
+ | rust | Rust Analyzer |
72
+ | csharp | OmniSharp / RazorSharp |
73
+ | typescript | TypeScriptLanguageServer |
74
+ | javascript | TypeScriptLanguageServer |
75
+ | go | gopls |
76
+ | dart | Dart |
77
+ | ruby | Solargraph |
78
+ | kotlin | KotlinLanguageServer |
79
+
80
+
81
+ ## Usage
82
+ Example usage:
83
+ ```python
84
+ from scubalspy import SyncLanguageServer
85
+ from scubalspy.scubalspy_config import ScubalspyConfig
86
+ from scubalspy.scubalspy_logger import ScubalspyLogger
87
+ ...
88
+ config = ScubalspyConfig.from_dict({"code_language": "java"}) # Also supports "python", "rust", "csharp", "typescript", "javascript", "go", "dart", "ruby"
89
+ logger = ScubalspyLogger()
90
+ lsp = SyncLanguageServer.create(config, logger, "/abs/path/to/project/root/")
91
+ with lsp.start_server():
92
+ result = lsp.request_definition(
93
+ "relative/path/to/code_file.java", # Filename of location where request is being made
94
+ 163, # line number of symbol for which request is being made
95
+ 4 # column number of symbol for which request is being made
96
+ )
97
+ result2 = lsp.request_completions(
98
+ ...
99
+ )
100
+ result3 = lsp.request_references(
101
+ ...
102
+ )
103
+ result4 = lsp.request_document_symbols(
104
+ ...
105
+ )
106
+ result5 = lsp.request_hover(
107
+ ...
108
+ )
109
+ ...
110
+ ```
111
+
112
+ `scubalspy` also provides an asyncio based API which can be used in async contexts. Example usage (asyncio):
113
+ ```python
114
+ from scubalspy import LanguageServer
115
+ ...
116
+ lsp = LanguageServer.create(...)
117
+ async with lsp.start_server():
118
+ result = await lsp.request_definition(
119
+ ...
120
+ )
121
+ ...
122
+ ```
123
+
124
+ The file [src/scubalspy/language_server.py](src/scubalspy/language_server.py) provides the `scubalspy` API. Several tests for `scubalspy` present under [tests/scubalspy/](tests/scubalspy/) provide detailed usage examples for `scubalspy`. The tests can be executed by running:
125
+ ```bash
126
+ pytest tests/scubalspy
127
+ ```
128
+
129
+ ## Use of `scubalspy` in AI4Code Scenarios like Monitor-Guided Decoding
130
+ `scubalspy` provides all the features that language-server-protocol provides to IDEs like VSCode. It is useful to develop toolsets that can interface with AI systems like Large Language Models (LLM).
131
+ ### [Monitor-Guided Decoding](https://github.com/microsoft/monitors4codegen)
132
+ One such usecase is Monitor-Guided Decoding, where `scubalspy` is used to find results of static analyses like type-directed completions, to guide the token-by-token generation of code using an LLM, ensuring that all generated identifier/method names are valid in the context of the repository, significantly boosting the compilability of generated code. MGD also demonstrates use of `scubalspy` to create monitors that ensure all function calls in LLM generated code receive correct number of arguments, and that functions of an object are called in the right order following a protocol (like not calling "read" before "open" on a file object).
133
+
134
+ ### Scubalspy in other usecases
135
+ * ["Fix the Tests: Augmenting LLMs to Repair Test Cases with Static Collector and Neural Reranker," in 2024 IEEE 35th International Symposium on Software Reliability Engineering (ISSRE)](https://github.com/SQUARE-RG/SynTeR)
136
+ * [Tutorial on obtaining python completions with scubalspy](https://medium.com/@techhara/python-obtain-completions-3db4d2479b82)
137
+ * Gathering and utilizing repository-wide context for repository-level coding agents
138
+
139
+ ## Frequently Asked Questions (FAQ)
140
+ ### ```asyncio``` related Runtime error when executing the tests for MGD
141
+ If you get the following error:
142
+ ```
143
+ RuntimeError: Task <Task pending name='Task-2' coro=<_AsyncGeneratorContextManager.__aenter__() running at
144
+ python3.8/contextlib.py:171> cb=[_chain_future.<locals>._call_set_state() at
145
+ python3.8/asyncio/futures.py:367]> got Future <Future pending> attached to a different loop python3.8/asyncio/locks.py:309: RuntimeError
146
+ ```
147
+
148
+ Please ensure that you create a new environment with Python ```>=3.10```. For further details, please have a look at the [StackOverflow Discussion](https://stackoverflow.com/questions/73599594/asyncio-works-in-python-3-10-but-not-in-python-3-8).
149
+
150
+ ## Citing Scubalspy
151
+ If you're using Scubalspy in your research or applications, please cite using this BibTeX:
152
+ ```
153
+ @inproceedings{NEURIPS2023_662b1774,
154
+ author = {Agrawal, Lakshya A and Kanade, Aditya and Goyal, Navin and Lahiri, Shuvendu and Rajamani, Sriram},
155
+ booktitle = {Advances in Neural Information Processing Systems},
156
+ editor = {A. Oh and T. Naumann and A. Globerson and K. Saenko and M. Hardt and S. Levine},
157
+ pages = {32270--32298},
158
+ publisher = {Curran Associates, Inc.},
159
+ title = {Monitor-Guided Decoding of Code LMs with Static Analysis of Repository Context},
160
+ url = {https://proceedings.neurips.cc/paper_files/paper/2023/file/662b1774ba8845fc1fa3d1fc0177ceeb-Paper-Conference.pdf},
161
+ volume = {36},
162
+ year = {2023}
163
+ }
164
+ ```
165
+
166
+ ## Contributing
167
+
168
+ This project welcomes contributions and suggestions. Most contributions require you to agree to a
169
+ Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
170
+ the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
171
+
172
+ When you submit a pull request, a CLA bot will automatically determine whether you need to provide
173
+ a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
174
+ provided by the bot. You will only need to do this once across all repos using our CLA.
175
+
176
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
177
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
178
+ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
179
+
180
+ ## Trademarks
181
+
182
+ This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
183
+ trademarks or logos is subject to and must follow
184
+ [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
185
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
186
+ Any use of third-party trademarks or logos are subject to those third-party's policies.
187
+
@@ -0,0 +1,159 @@
1
+ [![PyPI - Version](https://img.shields.io/pypi/v/scubalspy)](https://pypi.org/project/scubalspy/)
2
+ # Scubalspy: LSP client library in Python to build applications around language servers
3
+
4
+ ## Introduction
5
+ This repository hosts `scubalspy`, a library developed as part of research conducted for NeruIPS 2023 paper titled ["Monitor-Guided Decoding of Code LMs with Static Analysis of Repository Context"](https://neurips.cc/virtual/2023/poster/70362) (["Guiding Language Models of Code with Global Context using Monitors"](https://arxiv.org/abs/2306.10763) on Arxiv). The paper introduces Monitor-Guided Decoding (MGD) for code generation using Language Models, where a monitor uses static analysis to guide the decoding, ensuring that the generated code follows various correctness properties, like absence of hallucinated symbol names, valid order of method calls, etc. For further details about Monitor-Guided Decoding, please refer to the paper and GitHub repository [microsoft/monitors4codegen](https://github.com/microsoft/monitors4codegen).
6
+
7
+ `scubalspy` is a cross-platform library designed to simplify the process of creating language server clients to query and obtain results of various static analyses from a wide variety of language servers that communicate over the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/). It is easily extensible to support any [language that has a Language Server](https://microsoft.github.io/language-server-protocol/implementors/servers/) and we aim to continuously add support for more language servers and languages.
8
+
9
+ [Language servers]((https://microsoft.github.io/language-server-protocol/overviews/lsp/overview/)) are tools that perform a variety of static analyses on code repositories 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/). Since LSP is language-agnostic, `scubalspy` can provide the results for static analyses of code in different languages over a common interface.
10
+
11
+ `scubalspy` intends to ease the process of using language servers, by handling various steps in using a language server:
12
+ * Automatically handling the download of platform-specific server binaries, and setup/teardown of language servers
13
+ * Handling JSON-RPC based communication between the client and the server
14
+ * Maintaining and passing hand-tuned server and language specific configuration parameters
15
+ * Providing a simple API to the user, while executing all steps of server-specific protocol steps to execute the query/request.
16
+
17
+ Some of the analysis results that `scubalspy` can provide are:
18
+ - 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))
19
+ - 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))
20
+ - Providing type-based dereference completions ([textDocument/completion](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_completion))
21
+ - Getting information displayed when hovering over symbols, like method signature ([textDocument/hover](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_hover))
22
+ - Getting list/tree of all symbols defined in a given file, along with symbol type like class, method, etc. ([textDocument/documentSymbol](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_documentSymbol))
23
+ - Please create an issue/PR to add any other LSP request not listed above
24
+
25
+ ## Installation
26
+ It is ideal to create a new virtual environment with `python>=3.10`. To create a virtual environment using conda and activate it:
27
+ ```
28
+ conda create -n scubalspy_env python=3.10
29
+ conda activate scubalspy_env
30
+ ```
31
+ 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.
32
+
33
+ To install `scubalspy` using pip, execute the following command:
34
+ ```
35
+ pip install scubalspy
36
+ ```
37
+
38
+ ## Supported Languages
39
+ `scubalspy` currently supports the following languages:
40
+ | Code Language | Language Server |
41
+ | --- | --- |
42
+ | java | Eclipse JDTLS |
43
+ | python | jedi-language-server |
44
+ | rust | Rust Analyzer |
45
+ | csharp | OmniSharp / RazorSharp |
46
+ | typescript | TypeScriptLanguageServer |
47
+ | javascript | TypeScriptLanguageServer |
48
+ | go | gopls |
49
+ | dart | Dart |
50
+ | ruby | Solargraph |
51
+ | kotlin | KotlinLanguageServer |
52
+
53
+
54
+ ## Usage
55
+ Example usage:
56
+ ```python
57
+ from scubalspy import SyncLanguageServer
58
+ from scubalspy.scubalspy_config import ScubalspyConfig
59
+ from scubalspy.scubalspy_logger import ScubalspyLogger
60
+ ...
61
+ config = ScubalspyConfig.from_dict({"code_language": "java"}) # Also supports "python", "rust", "csharp", "typescript", "javascript", "go", "dart", "ruby"
62
+ logger = ScubalspyLogger()
63
+ lsp = SyncLanguageServer.create(config, logger, "/abs/path/to/project/root/")
64
+ with lsp.start_server():
65
+ result = lsp.request_definition(
66
+ "relative/path/to/code_file.java", # Filename of location where request is being made
67
+ 163, # line number of symbol for which request is being made
68
+ 4 # column number of symbol for which request is being made
69
+ )
70
+ result2 = lsp.request_completions(
71
+ ...
72
+ )
73
+ result3 = lsp.request_references(
74
+ ...
75
+ )
76
+ result4 = lsp.request_document_symbols(
77
+ ...
78
+ )
79
+ result5 = lsp.request_hover(
80
+ ...
81
+ )
82
+ ...
83
+ ```
84
+
85
+ `scubalspy` also provides an asyncio based API which can be used in async contexts. Example usage (asyncio):
86
+ ```python
87
+ from scubalspy import LanguageServer
88
+ ...
89
+ lsp = LanguageServer.create(...)
90
+ async with lsp.start_server():
91
+ result = await lsp.request_definition(
92
+ ...
93
+ )
94
+ ...
95
+ ```
96
+
97
+ The file [src/scubalspy/language_server.py](src/scubalspy/language_server.py) provides the `scubalspy` API. Several tests for `scubalspy` present under [tests/scubalspy/](tests/scubalspy/) provide detailed usage examples for `scubalspy`. The tests can be executed by running:
98
+ ```bash
99
+ pytest tests/scubalspy
100
+ ```
101
+
102
+ ## Use of `scubalspy` in AI4Code Scenarios like Monitor-Guided Decoding
103
+ `scubalspy` provides all the features that language-server-protocol provides to IDEs like VSCode. It is useful to develop toolsets that can interface with AI systems like Large Language Models (LLM).
104
+ ### [Monitor-Guided Decoding](https://github.com/microsoft/monitors4codegen)
105
+ One such usecase is Monitor-Guided Decoding, where `scubalspy` is used to find results of static analyses like type-directed completions, to guide the token-by-token generation of code using an LLM, ensuring that all generated identifier/method names are valid in the context of the repository, significantly boosting the compilability of generated code. MGD also demonstrates use of `scubalspy` to create monitors that ensure all function calls in LLM generated code receive correct number of arguments, and that functions of an object are called in the right order following a protocol (like not calling "read" before "open" on a file object).
106
+
107
+ ### Scubalspy in other usecases
108
+ * ["Fix the Tests: Augmenting LLMs to Repair Test Cases with Static Collector and Neural Reranker," in 2024 IEEE 35th International Symposium on Software Reliability Engineering (ISSRE)](https://github.com/SQUARE-RG/SynTeR)
109
+ * [Tutorial on obtaining python completions with scubalspy](https://medium.com/@techhara/python-obtain-completions-3db4d2479b82)
110
+ * Gathering and utilizing repository-wide context for repository-level coding agents
111
+
112
+ ## Frequently Asked Questions (FAQ)
113
+ ### ```asyncio``` related Runtime error when executing the tests for MGD
114
+ If you get the following error:
115
+ ```
116
+ RuntimeError: Task <Task pending name='Task-2' coro=<_AsyncGeneratorContextManager.__aenter__() running at
117
+ python3.8/contextlib.py:171> cb=[_chain_future.<locals>._call_set_state() at
118
+ python3.8/asyncio/futures.py:367]> got Future <Future pending> attached to a different loop python3.8/asyncio/locks.py:309: RuntimeError
119
+ ```
120
+
121
+ Please ensure that you create a new environment with Python ```>=3.10```. For further details, please have a look at the [StackOverflow Discussion](https://stackoverflow.com/questions/73599594/asyncio-works-in-python-3-10-but-not-in-python-3-8).
122
+
123
+ ## Citing Scubalspy
124
+ If you're using Scubalspy in your research or applications, please cite using this BibTeX:
125
+ ```
126
+ @inproceedings{NEURIPS2023_662b1774,
127
+ author = {Agrawal, Lakshya A and Kanade, Aditya and Goyal, Navin and Lahiri, Shuvendu and Rajamani, Sriram},
128
+ booktitle = {Advances in Neural Information Processing Systems},
129
+ editor = {A. Oh and T. Naumann and A. Globerson and K. Saenko and M. Hardt and S. Levine},
130
+ pages = {32270--32298},
131
+ publisher = {Curran Associates, Inc.},
132
+ title = {Monitor-Guided Decoding of Code LMs with Static Analysis of Repository Context},
133
+ url = {https://proceedings.neurips.cc/paper_files/paper/2023/file/662b1774ba8845fc1fa3d1fc0177ceeb-Paper-Conference.pdf},
134
+ volume = {36},
135
+ year = {2023}
136
+ }
137
+ ```
138
+
139
+ ## Contributing
140
+
141
+ This project welcomes contributions and suggestions. Most contributions require you to agree to a
142
+ Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
143
+ the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
144
+
145
+ When you submit a pull request, a CLA bot will automatically determine whether you need to provide
146
+ a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
147
+ provided by the bot. You will only need to do this once across all repos using our CLA.
148
+
149
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
150
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
151
+ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
152
+
153
+ ## Trademarks
154
+
155
+ This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
156
+ trademarks or logos is subject to and must follow
157
+ [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
158
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
159
+ Any use of third-party trademarks or logos are subject to those third-party's policies.
@@ -0,0 +1,46 @@
1
+ # Read https://setuptools.pypa.io/en/latest/userguide/datafiles.html
2
+ [build-system]
3
+ requires = ["flit_core>=3.4"]
4
+ build-backend = "flit_core.buildapi"
5
+
6
+ [project]
7
+ name = "scubalspy"
8
+ version = "0.0.16"
9
+ authors = [
10
+ { name="Lakshya A Agrawal", email="lakshya.aagrawal@gmail.com" },
11
+ { name="SunBK201", email="sunbk201gm@gmail.com" },
12
+ ]
13
+ description = "A language-agnostic LSP client in Python, with a library interface. Intended to be used to build applications around language servers. Currently scubalspy supports language servers for Python, Rust, Java, Go, JavaScript, Ruby, C# and Dart. Originally appeared as part of Monitor-Guided Decoding (https://github.com/microsoft/monitors4codegen)"
14
+ readme = "README.md"
15
+ requires-python = ">=3.8, <4.0"
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Operating System :: OS Independent",
19
+ "Development Status :: 2 - Pre-Alpha",
20
+ "Topic :: Software Development",
21
+ "Topic :: Text Editors :: Integrated Development Environments (IDE)",
22
+ "Programming Language :: C#",
23
+ "Programming Language :: Java",
24
+ "Programming Language :: Python",
25
+ "Programming Language :: Rust",
26
+ "Programming Language :: JavaScript",
27
+ "Programming Language :: Go",
28
+ "Programming Language :: Ruby",
29
+ ]
30
+
31
+ dependencies = [
32
+ "jedi-language-server==0.41.3",
33
+ "requests==2.32.3",
34
+ "typing-extensions>=4.2.0",
35
+ "psutil (>=7.0.0,<8.0.0)"
36
+ ]
37
+
38
+ [project.urls]
39
+ "Homepage" = "https://github.com/SunBK201/scubalspy-scubatrace"
40
+ "Bug Tracker" = "https://github.com/SunBK201/scubalspy-scubatrace/issues"
41
+
42
+ [tool.setuptools]
43
+ include-package-data = true
44
+
45
+ [tool.setuptools.packages.find]
46
+ where = ["src"]
@@ -0,0 +1,8 @@
1
+ """
2
+ This module contains the scubalspy API
3
+ """
4
+
5
+ from . import scubalspy_types as Types
6
+ from .language_server import LanguageServer, SyncLanguageServer
7
+
8
+ __all__ = ["LanguageServer", "Types", "SyncLanguageServer"]