Skip to content

Commit

Permalink
fix existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Apr 5, 2021
1 parent 299ecd3 commit c9da5d2
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 34 deletions.
69 changes: 36 additions & 33 deletions cli/lsp/registries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,35 +491,38 @@ impl ModuleRegistry {
}
}
if !current_specifier.is_empty() {
Some(
self
.origins
.keys()
.filter_map(|k| {
let mut origin = k.as_str().to_string();
if origin.ends_with('/') {
origin.pop();
}
if origin.starts_with(current_specifier) {
let text_edit =
Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit {
range: *range,
new_text: origin.clone(),
}));
Some(lsp::CompletionItem {
label: origin,
kind: Some(lsp::CompletionItemKind::Folder),
detail: Some("(registry)".to_string()),
sort_text: Some("1".to_string()),
text_edit,
..Default::default()
})
} else {
None
}
})
.collect(),
)
let items = self
.origins
.keys()
.filter_map(|k| {
let mut origin = k.as_str().to_string();
if origin.ends_with('/') {
origin.pop();
}
if origin.starts_with(current_specifier) {
let text_edit =
Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit {
range: *range,
new_text: origin.clone(),
}));
Some(lsp::CompletionItem {
label: origin,
kind: Some(lsp::CompletionItemKind::Folder),
detail: Some("(registry)".to_string()),
sort_text: Some("1".to_string()),
text_edit,
..Default::default()
})
} else {
None
}
})
.collect::<Vec<lsp::CompletionItem>>();
if !items.is_empty() {
Some(items)
} else {
None
}
} else {
None
}
Expand Down Expand Up @@ -624,12 +627,12 @@ mod tests {
assert!(completions.is_some());
let completions = completions.unwrap();
assert_eq!(completions.len(), 1);
assert_eq!(completions[0].label, "https://localhost:4545/");
assert_eq!(completions[0].label, "https://localhost:4545");
assert_eq!(
completions[0].text_edit,
Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit {
range,
new_text: "https://localhost:4545/".to_string()
new_text: "https://localhost:4545".to_string()
}))
);
let range = lsp::Range {
Expand All @@ -648,12 +651,12 @@ mod tests {
assert!(completions.is_some());
let completions = completions.unwrap();
assert_eq!(completions.len(), 1);
assert_eq!(completions[0].label, "https://localhost:4545/");
assert_eq!(completions[0].label, "https://localhost:4545");
assert_eq!(
completions[0].text_edit,
Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit {
range,
new_text: "https://localhost:4545/".to_string()
new_text: "https://localhost:4545".to_string()
}))
);
}
Expand Down
11 changes: 10 additions & 1 deletion cli/tests/lsp/initialize_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@
"implementations": true,
"references": true
},
"lint": true,
"importMap": null,
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {}
}
},
"unstable": false
},
"capabilities": {
Expand Down
63 changes: 63 additions & 0 deletions cli/tests/lsp/initialize_request_registry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"processId": 0,
"clientInfo": {
"name": "test-harness",
"version": "1.0.0"
},
"rootUri": null,
"initializationOptions": {
"enable": true,
"codeLens": {
"implementations": true,
"references": true
},
"importMap": null,
"lint": true,
"suggest": {
"autoImports": true,
"completeFunctionCalls": false,
"names": true,
"paths": true,
"imports": {
"hosts": {
"https://localhost:4545/": true
}
}
},
"unstable": false
},
"capabilities": {
"textDocument": {
"codeAction": {
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"quickfix"
]
}
},
"isPreferredSupport": true,
"dataSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
}
},
"foldingRange": {
"lineFoldingOnly": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
}
}
}
}
}

0 comments on commit c9da5d2

Please sign in to comment.