Unnamed repository; edit this file 'description' to name the repository.
Merge #10384
10384: Add vscode native onEnterRules r=matklad,lnicola a=HKalbasi This PR copy onEnterRules configurations [from vscode-rust](https://github.com/rust-lang/vscode-rust/blob/master/src/extension.ts#L287) based on discussion in #6254 I understand that the ideal way is to use parser data for this, and probably all other things that language-config do. But since it can't be enabled (or at least it isn't enabled) by default in vscode, I think this is needed (until onEnter becomes official LSP and get vscode support). People can still configure shortcut and use the parser based onEnter, so it wouldn't harm anyone. Co-authored-by: hamidreza kalbasi <[email protected]>
bors[bot] 2021-09-30
parent ee12b0f · parent 0dbaf64 · commit 9e3e98d
-rw-r--r--editors/code/src/main.ts53
1 files changed, 53 insertions, 0 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index a595814635..da04eec92b 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -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 },
+ },
+ ],
+ });
+}