Skip to content

Commit

Permalink
feat(lsp): improve registry completion suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Dec 8, 2021
1 parent b51b0c8 commit 2d50f0d
Show file tree
Hide file tree
Showing 5 changed files with 427 additions and 46 deletions.
25 changes: 16 additions & 9 deletions cli/lsp/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const LOCAL_PATHS: &[&str] = &[CURRENT_PATH, PARENT_PATH];
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CompletionItemData {
#[serde(skip_serializing_if = "Option::is_none")]
pub docs: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tsc: Option<tsc::CompletionItemData>,
}
Expand Down Expand Up @@ -132,19 +134,22 @@ pub(crate) async fn get_import_completions(
} else {
0
};
let maybe_items = state_snapshot
let maybe_list = state_snapshot
.module_registries
.get_completions(&text, offset, &range, |specifier| {
state_snapshot.documents.contains_specifier(specifier)
})
.await;
let items = maybe_items.unwrap_or_else(|| {
get_workspace_completions(specifier, &text, &range, state_snapshot)
});
Some(lsp::CompletionResponse::List(lsp::CompletionList {
let list = maybe_list.unwrap_or_else(|| lsp::CompletionList {
items: get_workspace_completions(
specifier,
&text,
&range,
state_snapshot,
),
is_incomplete: false,
items,
}))
});
Some(lsp::CompletionResponse::List(list))
} else {
let mut items: Vec<lsp::CompletionItem> = LOCAL_PATHS
.iter()
Expand All @@ -157,14 +162,16 @@ pub(crate) async fn get_import_completions(
..Default::default()
})
.collect();
let mut is_incomplete = false;
if let Some(origin_items) = state_snapshot
.module_registries
.get_origin_completions(&text, &range)
{
items.extend(origin_items);
is_incomplete = origin_items.is_incomplete;
items.extend(origin_items.items);
}
Some(lsp::CompletionResponse::List(lsp::CompletionList {
is_incomplete: false,
is_incomplete,
items,
}))
// TODO(@kitsonk) add bare specifiers from import map
Expand Down
9 changes: 9 additions & 0 deletions cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1773,6 +1773,15 @@ impl Inner {
);
params
}
} else if let Some(docs_url) = data.docs {
CompletionItem {
documentation: self
.module_registries
.get_documentation(&docs_url)
.await,
data: None,
..params
}
} else {
params
}
Expand Down
Loading

0 comments on commit 2d50f0d

Please sign in to comment.