Less rust-analyzer specific onEnter
This commit is contained in:
@@ -85,6 +85,7 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti
|
||||
experimental: Some(json!({
|
||||
"joinLines": true,
|
||||
"ssr": true,
|
||||
"onEnter": true,
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user