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

feat(lsp): Implement textDocument/foldingRange #9900

Merged
merged 8 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add unit test
  • Loading branch information
jeanp413 committed Mar 26, 2021
commit 454bbb4694b82a2a763bb8383e6fd3e0045def69
48 changes: 48 additions & 0 deletions cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2487,6 +2487,54 @@ mod tests {
);
}

#[tokio::test]
async fn test_folding_range() {
let mut harness = LspTestHarness::new(vec![
("initialize_request.json", LspResponse::RequestAny),
("initialized_notification.json", LspResponse::None),
(
"folding_range_did_open_notification.json",
LspResponse::None,
),
(
"folding_range_request.json",
LspResponse::Request(
2,
json!([
{
"startLine": 0,
"endLine": 12,
"kind": "region"
},
{
"startLine": 1,
"endLine": 3,
"kind": "comment"
},
{
"startLine": 4,
"endLine": 10
},
{
"startLine": 5,
"endLine": 9
},
{
"startLine": 6,
"endLine": 7
}
]),
),
),
(
"shutdown_request.json",
LspResponse::Request(3, json!(null)),
),
("exit_notification.json", LspResponse::None),
]);
harness.run().await;
}

#[tokio::test]
async fn test_rename() {
let mut harness = LspTestHarness::new(vec![
Expand Down
12 changes: 12 additions & 0 deletions cli/tests/lsp/folding_range_did_open_notification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"jsonrpc": "2.0",
"method": "textDocument/didOpen",
"params": {
"textDocument": {
"uri": "file:https:///a/file.ts",
"languageId": "typescript",
"version": 1,
"text": "// #region 1\n/*\n * Some comment\n */\nclass Foo {\n bar(a, b) {\n if (a === b) {\n return true;\n }\n return false;\n }\n}\n// #endregion"
}
}
}
10 changes: 10 additions & 0 deletions cli/tests/lsp/folding_range_request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"jsonrpc": "2.0",
"id": 2,
"method": "textDocument/foldingRange",
"params": {
"textDocument": {
"uri": "file:https:///a/file.ts"
}
}
}
3 changes: 3 additions & 0 deletions cli/tests/lsp/initialize_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
]
}
},
"foldingRange": {
"lineFoldingOnly": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
Expand Down