Skip to content

Commit 9e3e98d

Browse files
bors[bot]HKalbasi
andauthored
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]>
2 parents ee12b0f + 0dbaf64 commit 9e3e98d

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

editors/code/src/main.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ async function tryActivate(context: vscode.ExtensionContext) {
6363
activateInlayHints(ctx);
6464
warnAboutExtensionConflicts();
6565

66+
ctx.pushCleanup(configureLanguage());
67+
6668
vscode.workspace.onDidChangeConfiguration(
6769
_ => ctx?.client?.sendNotification('workspace/didChangeConfiguration', { settings: "" }),
6870
null,
@@ -474,3 +476,54 @@ function warnAboutExtensionConflicts() {
474476
.then(() => { }, console.error);
475477
};
476478
}
479+
480+
/**
481+
* Sets up additional language configuration that's impossible to do via a
482+
* separate language-configuration.json file. See [1] for more information.
483+
*
484+
* [1]: https://github.com/Microsoft/vscode/issues/11514#issuecomment-244707076
485+
*/
486+
function configureLanguage(): vscode.Disposable {
487+
const indentAction = vscode.IndentAction.None;
488+
return vscode.languages.setLanguageConfiguration('rust', {
489+
onEnterRules: [
490+
{
491+
// Doc single-line comment
492+
// e.g. ///|
493+
beforeText: /^\s*\/{3}.*$/,
494+
action: { indentAction, appendText: '/// ' },
495+
},
496+
{
497+
// Parent doc single-line comment
498+
// e.g. //!|
499+
beforeText: /^\s*\/{2}\!.*$/,
500+
action: { indentAction, appendText: '//! ' },
501+
},
502+
{
503+
// Begins an auto-closed multi-line comment (standard or parent doc)
504+
// e.g. /** | */ or /*! | */
505+
beforeText: /^\s*\/\*(\*|\!)(?!\/)([^\*]|\*(?!\/))*$/,
506+
afterText: /^\s*\*\/$/,
507+
action: { indentAction: vscode.IndentAction.IndentOutdent, appendText: ' * ' },
508+
},
509+
{
510+
// Begins a multi-line comment (standard or parent doc)
511+
// e.g. /** ...| or /*! ...|
512+
beforeText: /^\s*\/\*(\*|\!)(?!\/)([^\*]|\*(?!\/))*$/,
513+
action: { indentAction, appendText: ' * ' },
514+
},
515+
{
516+
// Continues a multi-line comment
517+
// e.g. * ...|
518+
beforeText: /^(\ \ )*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
519+
action: { indentAction, appendText: '* ' },
520+
},
521+
{
522+
// Dedents after closing a multi-line comment
523+
// e.g. */|
524+
beforeText: /^(\ \ )*\ \*\/\s*$/,
525+
action: { indentAction, removeText: 1 },
526+
},
527+
],
528+
});
529+
}

0 commit comments

Comments
 (0)