mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 15:32:06 +00:00
add vscode native onEnterRules
This commit is contained in:
parent
dd21ad6a5e
commit
0dbaf64b12
@ -63,6 +63,8 @@ async function tryActivate(context: vscode.ExtensionContext) {
|
||||
activateInlayHints(ctx);
|
||||
warnAboutExtensionConflicts();
|
||||
|
||||
ctx.pushCleanup(configureLanguage());
|
||||
|
||||
vscode.workspace.onDidChangeConfiguration(
|
||||
_ => ctx?.client?.sendNotification('workspace/didChangeConfiguration', { settings: "" }),
|
||||
null,
|
||||
@ -474,3 +476,54 @@ function warnAboutExtensionConflicts() {
|
||||
.then(() => { }, console.error);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up additional language configuration that's impossible to do via a
|
||||
* separate language-configuration.json file. See [1] for more information.
|
||||
*
|
||||
* [1]: https://github.com/Microsoft/vscode/issues/11514#issuecomment-244707076
|
||||
*/
|
||||
function configureLanguage(): vscode.Disposable {
|
||||
const indentAction = vscode.IndentAction.None;
|
||||
return vscode.languages.setLanguageConfiguration('rust', {
|
||||
onEnterRules: [
|
||||
{
|
||||
// Doc single-line comment
|
||||
// e.g. ///|
|
||||
beforeText: /^\s*\/{3}.*$/,
|
||||
action: { indentAction, appendText: '/// ' },
|
||||
},
|
||||
{
|
||||
// Parent doc single-line comment
|
||||
// e.g. //!|
|
||||
beforeText: /^\s*\/{2}\!.*$/,
|
||||
action: { indentAction, appendText: '//! ' },
|
||||
},
|
||||
{
|
||||
// Begins an auto-closed multi-line comment (standard or parent doc)
|
||||
// e.g. /** | */ or /*! | */
|
||||
beforeText: /^\s*\/\*(\*|\!)(?!\/)([^\*]|\*(?!\/))*$/,
|
||||
afterText: /^\s*\*\/$/,
|
||||
action: { indentAction: vscode.IndentAction.IndentOutdent, appendText: ' * ' },
|
||||
},
|
||||
{
|
||||
// Begins a multi-line comment (standard or parent doc)
|
||||
// e.g. /** ...| or /*! ...|
|
||||
beforeText: /^\s*\/\*(\*|\!)(?!\/)([^\*]|\*(?!\/))*$/,
|
||||
action: { indentAction, appendText: ' * ' },
|
||||
},
|
||||
{
|
||||
// Continues a multi-line comment
|
||||
// e.g. * ...|
|
||||
beforeText: /^(\ \ )*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
|
||||
action: { indentAction, appendText: '* ' },
|
||||
},
|
||||
{
|
||||
// Dedents after closing a multi-line comment
|
||||
// e.g. */|
|
||||
beforeText: /^(\ \ )*\ \*\/\s*$/,
|
||||
action: { indentAction, removeText: 1 },
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user