All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: Dan Loman <https://github.com/namolnad>
2 " Description: Functions for integrating with Swift tools
4 " Find the nearest dir containing a Package.swift file and assume it is the root of the Swift project.
5 function! ale#swift#FindProjectRoot(buffer) abort
6 let l:swift_config = ale#path#FindNearestFile(a:buffer, 'Package.swift')
8 if !empty(l:swift_config)
9 return fnamemodify(l:swift_config, ':h')
15 " Support Apple Swift Format {{{1
17 call ale#Set('swift_appleswiftformat_executable', 'swift-format')
18 call ale#Set('swift_appleswiftformat_use_swiftpm', 0)
20 " Return the executable depending on whether or not to use Swift Package Manager.
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 ...`.
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')
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.
41 " Return the command depending on whether or not to use Swift Package Manager.
43 " If asked to use Swift Package Manager (use_swiftpm = 1), the command
44 " arguments are prefixed with 'swift run'.
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 = ''
51 if ale#Var(a:buffer, 'swift_appleswiftformat_use_swiftpm')
52 let l:command_args = ' ' . 'run swift-format'
55 return ale#Escape(l:executable) . l:command_args
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')
63 if l:config_filepath isnot# ''
64 return '--configuration' . ' ' . l:config_filepath