mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
automate braceless return substitution for long lines
Per [bjorn3][https://github.com/bjorn3] suggestion resolves cases where an early return is moved to a separate line due to line width formatting. This setting changes ``` if (a very long condition) return; ``` to ``` if (a very long condition) { return; } ``` while keeping ``` if (short) return; ``` as is. In pathological cases this may cause `npm run fix` not to fix formatting in one go and may require running it twice.
This commit is contained in:
parent
e0df2c9bee
commit
00a97272f2
@ -14,6 +14,7 @@ module.exports = {
|
|||||||
rules: {
|
rules: {
|
||||||
camelcase: ["error"],
|
camelcase: ["error"],
|
||||||
eqeqeq: ["error", "always", { null: "ignore" }],
|
eqeqeq: ["error", "always", { null: "ignore" }],
|
||||||
|
curly: ["error", "multi-line"],
|
||||||
"no-console": ["error", { allow: ["warn", "error"] }],
|
"no-console": ["error", { allow: ["warn", "error"] }],
|
||||||
"prefer-const": "error",
|
"prefer-const": "error",
|
||||||
"@typescript-eslint/member-delimiter-style": [
|
"@typescript-eslint/member-delimiter-style": [
|
||||||
|
@ -101,8 +101,9 @@ export class AstInspector implements vscode.HoverProvider, vscode.DefinitionProv
|
|||||||
doc: vscode.TextDocument,
|
doc: vscode.TextDocument,
|
||||||
pos: vscode.Position
|
pos: vscode.Position
|
||||||
): vscode.ProviderResult<vscode.DefinitionLink[]> {
|
): vscode.ProviderResult<vscode.DefinitionLink[]> {
|
||||||
if (!this.rustEditor || doc.uri.toString() !== this.rustEditor.document.uri.toString())
|
if (!this.rustEditor || doc.uri.toString() !== this.rustEditor.document.uri.toString()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const astEditor = this.findAstTextEditor();
|
const astEditor = this.findAstTextEditor();
|
||||||
if (!astEditor) return;
|
if (!astEditor) return;
|
||||||
|
@ -11,7 +11,7 @@ export async function applySnippetWorkspaceEdit(edit: vscode.WorkspaceEdit) {
|
|||||||
}
|
}
|
||||||
for (const [uri, edits] of edit.entries()) {
|
for (const [uri, edits] of edit.entries()) {
|
||||||
const editor = await editorFromUri(uri);
|
const editor = await editorFromUri(uri);
|
||||||
if (editor)
|
if (editor) {
|
||||||
await editor.edit((builder) => {
|
await editor.edit((builder) => {
|
||||||
for (const indel of edits) {
|
for (const indel of edits) {
|
||||||
assert(
|
assert(
|
||||||
@ -21,6 +21,7 @@ export async function applySnippetWorkspaceEdit(edit: vscode.WorkspaceEdit) {
|
|||||||
builder.replace(indel.range, indel.newText);
|
builder.replace(indel.range, indel.newText);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user