mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Suppress extra indent after the end of dot chains
This commit is contained in:
parent
492b3deba7
commit
1c454736a4
1 changed files with 70 additions and 48 deletions
|
@ -86,11 +86,34 @@ export class Config {
|
|||
* [1]: https://github.com/Microsoft/vscode/issues/11514#issuecomment-244707076
|
||||
*/
|
||||
private configureLanguage() {
|
||||
if (this.typingContinueCommentsOnNewline && !this.configureLang) {
|
||||
if (this.configureLang) return;
|
||||
|
||||
let onEnterRules: vscode.OnEnterRule[] = [
|
||||
{
|
||||
// Carry indentation from the previous line
|
||||
beforeText: /^\s*$/,
|
||||
action: { indentAction: vscode.IndentAction.None },
|
||||
},
|
||||
{
|
||||
// After the end of a function/field chain,
|
||||
// with the semicolon on the same line
|
||||
beforeText: /^\s+\..*;/,
|
||||
action: { indentAction: vscode.IndentAction.Outdent },
|
||||
},
|
||||
{
|
||||
// After the end of a function/field chain,
|
||||
// with semicolon detached from the rest
|
||||
beforeText: /^\s+;/,
|
||||
previousLineText: /^\s+\..*/,
|
||||
action: { indentAction: vscode.IndentAction.Outdent },
|
||||
},
|
||||
];
|
||||
|
||||
if (this.typingContinueCommentsOnNewline) {
|
||||
const indentAction = vscode.IndentAction.None;
|
||||
|
||||
this.configureLang = vscode.languages.setLanguageConfiguration("rust", {
|
||||
onEnterRules: [
|
||||
onEnterRules = [
|
||||
...onEnterRules,
|
||||
{
|
||||
// Doc single-line comment
|
||||
// e.g. ///|
|
||||
|
@ -131,14 +154,13 @@ export class Config {
|
|||
beforeText: /^(\ \ )*\ \*\/\s*$/,
|
||||
action: { indentAction, removeText: 1 },
|
||||
},
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
this.configureLang = vscode.languages.setLanguageConfiguration("rust", {
|
||||
onEnterRules,
|
||||
});
|
||||
}
|
||||
if (!this.typingContinueCommentsOnNewline && this.configureLang) {
|
||||
this.configureLang.dispose();
|
||||
this.configureLang = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// We don't do runtime config validation here for simplicity. More on stackoverflow:
|
||||
// https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue