Skip to content

Commit

Permalink
Add support for completions in rust for multilspy with unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshyAAAgrawal committed Nov 21, 2023
1 parent 90c40c3 commit fa50b39
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/monitors4codegen/multilspy/language_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,11 @@ async def request_completions(
completion_item = {}
if "detail" in item:
completion_item["detail"] = item["detail"]
if "insertText" in item:

if "label" in item:
completion_item["completionText"] = item["label"]
completion_item["kind"] = item["kind"]
elif "insertText" in item:
completion_item["completionText"] = item["insertText"]
completion_item["kind"] = item["kind"]
elif "textEdit" in item and "newText" in item["textEdit"]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@
"serverStatusNotification": true,
"colorDiagnosticOutput": true,
"openServerLogs": true,
"localDocs": true,
"commands": {
"commands": [
"rust-analyzer.runSingle",
Expand Down Expand Up @@ -740,11 +741,8 @@
"merge": {
"glob": true
},
"prefer": {
"no": {
"std": false
}
},
"preferNoStd": false,
"preferPrelude": false,
"prefix": "plain"
},
"inlayHints": {
Expand Down Expand Up @@ -850,6 +848,9 @@
"references": {
"excludeImports": false
},
"rust": {
"analyzerTargetDir": null
},
"rustc": {
"source": null
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ async def window_log_message(msg):
"triggerCharacters": [":", ".", "'", "("],
"completionItem": {"labelDetailsSupport": True},
}

self.server.notify.initialized({})
self.completions_available.set()

await self.server_ready.wait()

Expand Down
39 changes: 39 additions & 0 deletions tests/multilspy/test_multilspy_rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from monitors4codegen.multilspy import LanguageServer
from monitors4codegen.multilspy.multilspy_config import Language
from monitors4codegen.multilspy.multilspy_types import Position, CompletionItemKind
from tests.test_utils import create_test_context
from pathlib import PurePath

Expand Down Expand Up @@ -70,3 +71,41 @@ async def test_multilspy_rust_carbonyl():
},
],
)

@pytest.mark.asyncio
async def test_multilspy_rust_completions_mediaplayer() -> None:
"""
Test the working of multilspy with Rust repository - mediaplayer
"""
code_language = Language.RUST
params = {
"code_language": code_language,
"repo_url": "https://github.com/LakshyAAAgrawal/MediaPlayer_example/",
"repo_commit": "ba27bb16c7ba1d88808300364af65eb69b1d84a8",
}

with create_test_context(params) as context:
lsp = LanguageServer.create(context.config, context.logger, context.source_directory)
filepath = "src/playlist.rs"
# All the communication with the language server must be performed inside the context manager
# The server process is started when the context manager is entered and is terminated when the context manager is exited.
async with lsp.start_server():
with lsp.open_file(filepath):
deleted_text = lsp.delete_text_between_positions(
filepath, Position(line=10, character=40), Position(line=12, character=4)
)
assert (
deleted_text
== """reset();
media_player1 = media_player;
"""
)

response = await lsp.request_completions(filepath, 10, 40, allow_incomplete=True)

response = [item for item in response if item['kind'] != CompletionItemKind.Snippet]

for item in response:
item['completionText'] = item['completionText'][:item['completionText'].find('(')]

assert set([item['completionText'] for item in response]) == {'reset', 'into', 'try_into', 'prepare'}

0 comments on commit fa50b39

Please sign in to comment.