Skip to content

Commit 67785a0

Browse files
maxdeviantlpil
authored andcommitted
Continue doc comments on newline
1 parent efc7e1b commit 67785a0

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/extension.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,24 @@ import {
88
} from "vscode-languageclient/node";
99

1010
let client: LanguageClient | undefined;
11+
let configureLang: vscode.Disposable | undefined;
1112

1213
export function activate(_context: vscode.ExtensionContext) {
14+
const onEnterRules = [...continueTypingCommentsOnNewline()];
15+
16+
configureLang = vscode.languages.setLanguageConfiguration("gleam", {
17+
onEnterRules,
18+
});
19+
1320
client = createLanguageClient();
1421
// Start the client. This will also launch the server
1522
client.start();
1623
}
1724

1825
// this method is called when your extension is deactivated
1926
export function deactivate(): Thenable<void> | undefined {
27+
configureLang?.dispose();
28+
2029
return client?.stop();
2130
}
2231

@@ -50,3 +59,28 @@ function createLanguageClient(): LanguageClient {
5059
clientOptions
5160
);
5261
}
62+
63+
/**
64+
* Returns the `OnEnterRule`s needed to configure typing comments on a newline.
65+
*
66+
* This makes it so when you press `Enter` while in a comment it will continue
67+
* the comment onto the next line.
68+
*/
69+
function continueTypingCommentsOnNewline(): vscode.OnEnterRule[] {
70+
const indentAction = vscode.IndentAction.None;
71+
72+
return [
73+
{
74+
// Module doc single-line comment
75+
// e.g. ////|
76+
beforeText: /^\s*\/{4}.*$/,
77+
action: { indentAction, appendText: "//// " },
78+
},
79+
{
80+
// Doc single-line comment
81+
// e.g. ///|
82+
beforeText: /^\s*\/{3}.*$/,
83+
action: { indentAction, appendText: "/// " },
84+
},
85+
];
86+
}

0 commit comments

Comments
 (0)