Less rust-analyzer specific onEnter

This commit is contained in:
Aleksey Kladov
2020-05-25 14:12:53 +02:00
parent e4f91bfa57
commit 76e170c3d0
11 changed files with 105 additions and 55 deletions

View File

@@ -85,6 +85,7 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti
experimental: Some(json!({
"joinLines": true,
"ssr": true,
"onEnter": true,
})),
}
}

View File

@@ -102,8 +102,8 @@ pub enum OnEnter {}
impl Request for OnEnter {
type Params = lsp_types::TextDocumentPositionParams;
type Result = Option<SnippetWorkspaceEdit>;
const METHOD: &'static str = "rust-analyzer/onEnter";
type Result = Option<Vec<SnippetTextEdit>>;
const METHOD: &'static str = "experimental/onEnter";
}
pub enum Runnables {}

View File

@@ -174,13 +174,17 @@ pub fn handle_join_lines(
pub fn handle_on_enter(
world: WorldSnapshot,
params: lsp_types::TextDocumentPositionParams,
) -> Result<Option<lsp_ext::SnippetWorkspaceEdit>> {
) -> Result<Option<Vec<lsp_ext::SnippetTextEdit>>> {
let _p = profile("handle_on_enter");
let position = from_proto::file_position(&world, params)?;
match world.analysis().on_enter(position)? {
None => Ok(None),
Some(source_change) => to_proto::snippet_workspace_edit(&world, source_change).map(Some),
}
let edit = match world.analysis().on_enter(position)? {
None => return Ok(None),
Some(it) => it,
};
let line_index = world.analysis().file_line_index(position.file_id)?;
let line_endings = world.file_line_endings(position.file_id);
let edit = to_proto::snippet_text_edit_vec(&line_index, line_endings, true, edit);
Ok(Some(edit))
}
// Don't forget to add new trigger characters to `ServerCapabilities` in `caps.rs`.

View File

@@ -135,6 +135,18 @@ pub(crate) fn text_edit_vec(
text_edit.into_iter().map(|indel| self::text_edit(line_index, line_endings, indel)).collect()
}
pub(crate) fn snippet_text_edit_vec(
line_index: &LineIndex,
line_endings: LineEndings,
is_snippet: bool,
text_edit: TextEdit,
) -> Vec<lsp_ext::SnippetTextEdit> {
text_edit
.into_iter()
.map(|indel| self::snippet_text_edit(line_index, line_endings, is_snippet, indel))
.collect()
}
pub(crate) fn completion_item(
line_index: &LineIndex,
line_endings: LineEndings,