mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
JoinLines frontend
This commit is contained in:
parent
18918769ba
commit
8ad586a44e
5 changed files with 60 additions and 1 deletions
|
@ -3,7 +3,7 @@ use std::collections::HashMap;
|
|||
use languageserver_types::{
|
||||
Diagnostic, DiagnosticSeverity, Url, DocumentSymbol,
|
||||
Command, TextDocumentIdentifier, WorkspaceEdit,
|
||||
SymbolInformation, Position, Location,
|
||||
SymbolInformation, Position, Location, TextEdit,
|
||||
};
|
||||
use libanalysis::{Query};
|
||||
use libeditor;
|
||||
|
@ -58,6 +58,18 @@ pub fn handle_find_matching_brace(
|
|||
Ok(res)
|
||||
}
|
||||
|
||||
pub fn handle_join_lines(
|
||||
world: ServerWorld,
|
||||
params: req::JoinLinesParams,
|
||||
) -> Result<Vec<TextEdit>> {
|
||||
let file_id = params.text_document.try_conv_with(&world)?;
|
||||
let file = world.analysis().file_syntax(file_id)?;
|
||||
let line_index = world.analysis().file_line_index(file_id)?;
|
||||
let range = params.range.conv_with(&line_index);
|
||||
let res = libeditor::join_lines(&file, range);
|
||||
Ok(res.edit.conv_with(&line_index))
|
||||
}
|
||||
|
||||
pub fn handle_document_symbol(
|
||||
world: ServerWorld,
|
||||
params: req::DocumentSymbolParams,
|
||||
|
|
|
@ -27,6 +27,7 @@ use {
|
|||
handle_goto_definition,
|
||||
handle_find_matching_brace,
|
||||
handle_parent_module,
|
||||
handle_join_lines,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -145,6 +146,9 @@ fn on_request(
|
|||
handle_request_on_threadpool::<req::ParentModule>(
|
||||
&mut req, pool, world, sender, handle_parent_module,
|
||||
)?;
|
||||
handle_request_on_threadpool::<req::JoinLines>(
|
||||
&mut req, pool, world, sender, handle_join_lines,
|
||||
)?;
|
||||
dispatch::handle_request::<req::ExecuteCommand, _>(&mut req, |params, resp| {
|
||||
io.send(RawMsg::Response(resp.into_response(Ok(None))?));
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ pub use languageserver_types::{
|
|||
ExecuteCommandParams,
|
||||
WorkspaceSymbolParams,
|
||||
TextDocumentPositionParams,
|
||||
TextEdit,
|
||||
};
|
||||
|
||||
|
||||
|
@ -117,3 +118,18 @@ impl Request for ParentModule {
|
|||
type Result = Vec<Location>;
|
||||
const METHOD: &'static str = "m/parentModule";
|
||||
}
|
||||
|
||||
pub enum JoinLines {}
|
||||
|
||||
impl Request for JoinLines {
|
||||
type Params = JoinLinesParams;
|
||||
type Result = Vec<TextEdit>;
|
||||
const METHOD: &'static str = "m/joinLines";
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct JoinLinesParams {
|
||||
pub text_document: TextDocumentIdentifier,
|
||||
pub range: Range,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue