Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/hir/src/semantics.rs2
-rw-r--r--crates/ide-db/src/search.rs11
-rw-r--r--crates/ide/src/lib.rs6
-rw-r--r--crates/rust-analyzer/src/config.rs16
-rw-r--r--crates/rust-analyzer/src/handlers/request.rs17
-rw-r--r--docs/user/generated_config.adoc16
-rw-r--r--editors/code/package.json6
7 files changed, 42 insertions, 32 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index a1a596675b..41ec7f3e7a 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -1756,7 +1756,7 @@ impl<'db> SemanticsImpl<'db> {
let file_id = self.lookup(&root_node).unwrap_or_else(|| {
panic!(
"\n\nFailed to lookup {:?} in this Semantics.\n\
- Make sure to use only query nodes, derived from this instance of Semantics.\n\
+ Make sure to only query nodes derived from this instance of Semantics.\n\
root node: {:?}\n\
known nodes: {}\n\n",
node,
diff --git a/crates/ide-db/src/search.rs b/crates/ide-db/src/search.rs
index 68199dd871..a75aba137b 100644
--- a/crates/ide-db/src/search.rs
+++ b/crates/ide-db/src/search.rs
@@ -953,14 +953,19 @@ impl<'a> FindUsages<'a> {
// Search for occurrences of the items name
for offset in Self::match_indices(&text, finder, search_range) {
- tree.token_at_offset(offset).for_each(|token| {
- let Some(str_token) = ast::String::cast(token.clone()) else { return };
+ let ret = tree.token_at_offset(offset).any(|token| {
+ let Some(str_token) = ast::String::cast(token.clone()) else { return false };
if let Some((range, Some(nameres))) =
sema.check_for_format_args_template(token, offset)
{
- if self.found_format_args_ref(file_id, range, str_token, nameres, sink) {}
+ return self
+ .found_format_args_ref(file_id, range, str_token, nameres, sink);
}
+ false
});
+ if ret {
+ return;
+ }
for name in
Self::find_nodes(sema, name, &tree, offset).filter_map(ast::NameLike::cast)
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index 043e854215..346e2862b0 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -404,17 +404,11 @@ impl Analysis {
&self,
position: FilePosition,
char_typed: char,
- chars_to_exclude: Option<String>,
) -> Cancellable<Option<SourceChange>> {
// Fast path to not even parse the file.
if !typing::TRIGGER_CHARS.contains(char_typed) {
return Ok(None);
}
- if let Some(chars_to_exclude) = chars_to_exclude {
- if chars_to_exclude.contains(char_typed) {
- return Ok(None);
- }
- }
self.with_db(|db| typing::on_char_typed(db, position, char_typed))
}
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 72d021db5a..9d8dbfc7a4 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -326,8 +326,16 @@ config_data! {
/// Show documentation.
signatureInfo_documentation_enable: bool = true,
- /// Specify the characters to exclude from triggering typing assists. The default trigger characters are `.`, `=`, `<`, `>`, `{`, and `(`.
- typing_excludeChars: Option<String> = Some("|<".to_owned()),
+ /// Specify the characters allowed to invoke special on typing triggers.
+ /// - typing `=` after `let` tries to smartly add `;` if `=` is followed by an existing expression
+ /// - typing `=` between two expressions adds `;` when in statement position
+ /// - typing `=` to turn an assignment into an equality comparison removes `;` when in expression position
+ /// - typing `.` in a chain method call auto-indents
+ /// - typing `{` or `(` in front of an expression inserts a closing `}` or `)` after the expression
+ /// - typing `{` in a use item adds a closing `}` in the right place
+ /// - typing `>` to complete a return type `->` will insert a whitespace after it
+ /// - typing `<` in a path or type position inserts a closing `>` after the path or type.
+ typing_triggerChars: Option<String> = Some("=.".to_owned()),
/// Enables automatic discovery of projects using [`DiscoverWorkspaceConfig::command`].
@@ -2251,8 +2259,8 @@ impl Config {
}
}
- pub fn typing_exclude_chars(&self) -> Option<String> {
- self.typing_excludeChars().clone()
+ pub fn typing_trigger_chars(&self) -> &str {
+ self.typing_triggerChars().as_deref().unwrap_or_default()
}
// VSCode is our reference implementation, so we allow ourselves to work around issues by
diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs
index d01dc5fba1..190015d7fa 100644
--- a/crates/rust-analyzer/src/handlers/request.rs
+++ b/crates/rust-analyzer/src/handlers/request.rs
@@ -434,29 +434,24 @@ pub(crate) fn handle_on_type_formatting(
params: lsp_types::DocumentOnTypeFormattingParams,
) -> anyhow::Result<Option<Vec<lsp_ext::SnippetTextEdit>>> {
let _p = tracing::info_span!("handle_on_type_formatting").entered();
+ let char_typed = params.ch.chars().next().unwrap_or('\0');
+ if !snap.config.typing_trigger_chars().contains(char_typed) {
+ return Ok(None);
+ }
+
let mut position = from_proto::file_position(&snap, params.text_document_position)?;
let line_index = snap.file_line_index(position.file_id)?;
// in `ide`, the `on_type` invariant is that
// `text.char_at(position) == typed_char`.
position.offset -= TextSize::of('.');
- let char_typed = params.ch.chars().next().unwrap_or('\0');
let text = snap.analysis.file_text(position.file_id)?;
if stdx::never!(!text[usize::from(position.offset)..].starts_with(char_typed)) {
return Ok(None);
}
- // We have an assist that inserts ` ` after typing `->` in `fn foo() ->{`,
- // but it requires precise cursor positioning to work, and one can't
- // position the cursor with on_type formatting. So, let's just toggle this
- // feature off here, hoping that we'll enable it one day, 😿.
- if char_typed == '>' {
- return Ok(None);
- }
- let chars_to_exclude = snap.config.typing_exclude_chars();
-
- let edit = snap.analysis.on_char_typed(position, char_typed, chars_to_exclude)?;
+ let edit = snap.analysis.on_char_typed(position, char_typed)?;
let edit = match edit {
Some(it) => it,
None => return Ok(None),
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index 45eb38cd4f..2b518e0609 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -1051,10 +1051,18 @@ Show full signature of the callable. Only shows parameters if disabled.
--
Show documentation.
--
-[[rust-analyzer.typing.excludeChars]]rust-analyzer.typing.excludeChars (default: `"|<"`)::
-+
---
-Specify the characters to exclude from triggering typing assists. The default trigger characters are `.`, `=`, `<`, `>`, `{`, and `(`.
+[[rust-analyzer.typing.triggerChars]]rust-analyzer.typing.triggerChars (default: `"=."`)::
++
+--
+Specify the characters allowed to invoke special on typing triggers.
+- typing `=` after `let` tries to smartly add `;` if `=` is followed by an existing expression
+- typing `=` between two expressions adds `;` when in statement position
+- typing `=` to turn an assignment into an equality comparison removes `;` when in expression position
+- typing `.` in a chain method call auto-indents
+- typing `{` or `(` in front of an expression inserts a closing `}` or `)` after the expression
+- typing `{` in a use item adds a closing `}` in the right place
+- typing `>` to complete a return type `->` will insert a whitespace after it
+- typing `<` in a path or type position inserts a closing `>` after the path or type.
--
[[rust-analyzer.vfs.extraIncludes]]rust-analyzer.vfs.extraIncludes (default: `[]`)::
+
diff --git a/editors/code/package.json b/editors/code/package.json
index 8da17e7a0a..48e29a7fe2 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -2745,9 +2745,9 @@
{
"title": "typing",
"properties": {
- "rust-analyzer.typing.excludeChars": {
- "markdownDescription": "Specify the characters to exclude from triggering typing assists. The default trigger characters are `.`, `=`, `<`, `>`, `{`, and `(`.",
- "default": "|<",
+ "rust-analyzer.typing.triggerChars": {
+ "markdownDescription": "Specify the characters allowed to invoke special on typing triggers.\n- typing `=` after `let` tries to smartly add `;` if `=` is followed by an existing expression\n- typing `=` between two expressions adds `;` when in statement position\n- typing `=` to turn an assignment into an equality comparison removes `;` when in expression position\n- typing `.` in a chain method call auto-indents\n- typing `{` or `(` in front of an expression inserts a closing `}` or `)` after the expression\n- typing `{` in a use item adds a closing `}` in the right place\n- typing `>` to complete a return type `->` will insert a whitespace after it\n- typing `<` in a path or type position inserts a closing `>` after the path or type.",
+ "default": "=.",
"type": [
"null",
"string"