@@ -11,3 +11,60 @@ function! ale#swift#FindProjectRoot(buffer) abort
11
11
12
12
return ' '
13
13
endfunction
14
+
15
+ " Support Apple Swift Format {{{1
16
+
17
+ call ale#Set (' swift_appleswiftformat_executable' , ' swift-format' )
18
+ call ale#Set (' swift_appleswiftformat_use_swiftpm' , 0 )
19
+
20
+ " Return the executable depending on whether or not to use Swift Package Manager.
21
+ "
22
+ " If not asked to use Swift Package Manager (use_swiftpm = 0), the returned
23
+ " value is the global executable, else the returned value is 'swift' because
24
+ " the final command line will be `swift run swift-format ...`.
25
+ "
26
+ " Failure is expected if use_swiftpm is `1` but no Package.swift can be located.
27
+ function ! ale#swift#GetAppleSwiftFormatExecutable (buffer ) abort
28
+ if ! ale#Var (a: buffer , ' swift_appleswiftformat_use_swiftpm' )
29
+ return ale#Var (a: buffer , ' swift_appleswiftformat_executable' )
30
+ endif
31
+
32
+ if ale#path#FindNearestFile (a: buffer , ' Package.swift' ) is # ' '
33
+ " If there is no Package.swift file, we don't use swift-format even if it exists,
34
+ " so we return '' to indicate failure.
35
+ return ' '
36
+ endif
37
+
38
+ return ' swift'
39
+ endfunction
40
+
41
+ " Return the command depending on whether or not to use Swift Package Manager.
42
+ "
43
+ " If asked to use Swift Package Manager (use_swiftpm = 1), the command
44
+ " arguments are prefixed with 'swift run'.
45
+ "
46
+ " In either case, the configuration file is located and added to the command.
47
+ function ! ale#swift#GetAppleSwiftFormatCommand (buffer ) abort
48
+ let l: executable = ale#swift#GetAppleSwiftFormatExecutable (a: buffer )
49
+ let l: command_args = ' '
50
+
51
+ if ale#Var (a: buffer , ' swift_appleswiftformat_use_swiftpm' )
52
+ let l: command_args = ' ' . ' run swift-format'
53
+ endif
54
+
55
+ return ale#Escape (l: executable ) . l: command_args
56
+ endfunction
57
+
58
+ " Locate the nearest '.swift-format' configuration file, and return the
59
+ " arguments, else return an empty string.
60
+ function ! ale#swift#GetAppleSwiftFormatConfigArgs (buffer ) abort
61
+ let l: config_filepath = ale#path#FindNearestFile (a: buffer , ' .swift-format' )
62
+
63
+ if l: config_filepath isnot # ' '
64
+ return ' --configuration' . ' ' . l: config_filepath
65
+ endif
66
+
67
+ return ' '
68
+ endfunction
69
+
70
+ " }}}
0 commit comments