@@ -4,26 +4,28 @@ import { RangeEditProvider } from './providers/range_formatter';
4
4
import * as formatter from './format' ;
5
5
import * as inferer from './infer' ;
6
6
import * as docmirror from "./docmirror"
7
+ import * as config from './config'
7
8
8
- const ClojureLanguageConfiguration : vscode . LanguageConfiguration = {
9
- wordPattern : / [ ^ \s , # ( ) [ \] { } ; " \\ ] + / ,
10
- onEnterRules : [
11
- // This is madness, but the only way to stop vscode from indenting new lines
12
- {
13
- beforeText : / .* / ,
14
- action : {
15
- indentAction : vscode . IndentAction . Outdent ,
16
- removeText : Number . MAX_VALUE
17
- }
18
- } ,
19
- ]
9
+ function getLanguageConfiguration ( autoIndentOn : boolean ) : vscode . LanguageConfiguration {
10
+ return {
11
+ wordPattern : / [ ^ \s , # ( ) [ \] { } ; " \\ ] + / ,
12
+ onEnterRules : autoIndentOn ? [
13
+ // This is madness, but the only way to stop vscode from indenting new lines
14
+ {
15
+ beforeText : / .* / ,
16
+ action : {
17
+ indentAction : vscode . IndentAction . Outdent ,
18
+ removeText : Number . MAX_VALUE
19
+ }
20
+ } ,
21
+ ] : [ ]
22
+ }
20
23
}
21
24
22
25
23
-
24
26
export function activate ( context : vscode . ExtensionContext ) {
25
27
docmirror . activate ( ) ;
26
- vscode . languages . setLanguageConfiguration ( "clojure" , ClojureLanguageConfiguration ) ;
28
+ vscode . languages . setLanguageConfiguration ( "clojure" , getLanguageConfiguration ( config . getConfig ( ) [ "format-as-you-type" ] ) ) ;
27
29
// this doesn't actually grow anything yet, but just jumps to the start of the enclosing expression.
28
30
// context.subscriptions.push(vscode.commands.registerTextEditorCommand('calva-fmt.forwardSexp', docmirror.forwardSexp))
29
31
// context.subscriptions.push(vscode.commands.registerTextEditorCommand('calva-fmt.backwardSexp', docmirror.backwardSexp))
@@ -41,4 +43,9 @@ export function activate(context: vscode.ExtensionContext) {
41
43
context . subscriptions . push ( vscode . languages . registerOnTypeFormattingEditProvider ( "clojure" , new FormatOnTypeEditProvider , "\r" , "\n" ) ) ;
42
44
context . subscriptions . push ( vscode . languages . registerDocumentRangeFormattingEditProvider ( "clojure" , new RangeEditProvider ) ) ;
43
45
vscode . window . onDidChangeActiveTextEditor ( inferer . updateState ) ;
46
+ vscode . workspace . onDidChangeConfiguration ( e => {
47
+ if ( e . affectsConfiguration ( "calva.fmt.formatAsYouType" ) ) {
48
+ vscode . languages . setLanguageConfiguration ( "clojure" , getLanguageConfiguration ( config . getConfig ( ) [ "format-as-you-type" ] ) ) ;
49
+ }
50
+ } )
44
51
}
0 commit comments