mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
parent
91bfa4b154
commit
b8a6ea5ab5
6 changed files with 171 additions and 84 deletions
|
@ -12,7 +12,7 @@ use std::{ffi::OsString, iter, path::PathBuf};
|
|||
use flycheck::FlycheckConfig;
|
||||
use ide::{
|
||||
AssistConfig, CompletionConfig, DiagnosticsConfig, HoverConfig, HoverDocFormat,
|
||||
InlayHintsConfig,
|
||||
InlayHintsConfig, JoinLinesConfig,
|
||||
};
|
||||
use ide_db::helpers::{
|
||||
insert_use::{ImportGranularity, InsertUseConfig, PrefixKind},
|
||||
|
@ -186,6 +186,13 @@ config_data! {
|
|||
/// Whether to show inlay type hints for variables.
|
||||
inlayHints_typeHints: bool = "true",
|
||||
|
||||
/// Join lines inserts else between consecutive ifs.
|
||||
joinLines_joinElseIf: bool = "true",
|
||||
/// Join lines removes trailing commas.
|
||||
joinLines_removeTrailingComma: bool = "true",
|
||||
/// Join lines unwraps trivial blocks.
|
||||
joinLines_unwrapTrivialBlock: bool = "true",
|
||||
|
||||
/// Whether to show `Debug` lens. Only applies when
|
||||
/// `#rust-analyzer.lens.enable#` is set.
|
||||
lens_debug: bool = "true",
|
||||
|
@ -752,6 +759,13 @@ impl Config {
|
|||
insert_use: self.insert_use_config(),
|
||||
}
|
||||
}
|
||||
pub fn join_lines(&self) -> JoinLinesConfig {
|
||||
JoinLinesConfig {
|
||||
join_else_if: self.data.joinLines_joinElseIf,
|
||||
remove_trailing_comma: self.data.joinLines_removeTrailingComma,
|
||||
unwrap_trivial_blocks: self.data.joinLines_unwrapTrivialBlock,
|
||||
}
|
||||
}
|
||||
pub fn call_info_full(&self) -> bool {
|
||||
self.data.callInfo_full
|
||||
}
|
||||
|
|
|
@ -233,12 +233,15 @@ pub(crate) fn handle_join_lines(
|
|||
params: lsp_ext::JoinLinesParams,
|
||||
) -> Result<Vec<lsp_types::TextEdit>> {
|
||||
let _p = profile::span("handle_join_lines");
|
||||
|
||||
let config = snap.config.join_lines();
|
||||
let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?;
|
||||
let line_index = snap.file_line_index(file_id)?;
|
||||
|
||||
let mut res = TextEdit::default();
|
||||
for range in params.ranges {
|
||||
let range = from_proto::text_range(&line_index, range);
|
||||
let edit = snap.analysis.join_lines(FileRange { file_id, range })?;
|
||||
let edit = snap.analysis.join_lines(&config, FileRange { file_id, range })?;
|
||||
match res.union(edit) {
|
||||
Ok(()) => (),
|
||||
Err(_edit) => {
|
||||
|
@ -246,8 +249,8 @@ pub(crate) fn handle_join_lines(
|
|||
}
|
||||
}
|
||||
}
|
||||
let res = to_proto::text_edit_vec(&line_index, res);
|
||||
Ok(res)
|
||||
|
||||
Ok(to_proto::text_edit_vec(&line_index, res))
|
||||
}
|
||||
|
||||
pub(crate) fn handle_on_enter(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue