Skip to content

Commit 05ce4c3

Browse files
authored
Merge pull request #735 from JunoLab/avi/fmtconfigfile
support .JuliaFormatter.toml config file
2 parents aea5bcd + 257d91a commit 05ce4c3

File tree

2 files changed

+18
-129
lines changed

2 files changed

+18
-129
lines changed

lib/package/config.coffee

Lines changed: 11 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -120,119 +120,21 @@ config =
120120
order: 13
121121
formattingOptions:
122122
title: 'Formatting Options'
123-
description: 'Specifies [formatting options for `JuliaFormatter.format_text`](https://domluna.github.io/JuliaFormatter.jl/stable/#Formatting-Options-1).'
123+
description:
124+
'''
125+
This config is deprecated. In order to specify [Formatting Options](https://domluna.github.io/JuliaFormatter.jl/dev/#Formatting-Options-1),
126+
use `.JuliaFormatter.toml` configuration file instead.
127+
See the ["Configuration File" section in JuliaFormatter.jl's documentation](https://domluna.github.io/JuliaFormatter.jl/dev/config/)
128+
for more details.
129+
'''
124130
type: 'object'
125131
order: 14
126132
collapsed: true
127133
properties:
128-
indent:
129-
title: 'indent'
130-
description:
131-
'''
132-
Specifies the number of spaces used for an indentation.
133-
With the default value (`-1`), `indent` will be automatically set to the current editor's [tab length](https://flight-manual.atom.io/using-atom/sections/basic-customization/#configuration-key-reference).
134-
'''
135-
type: 'integer'
136-
default: -1
137-
order: 1
138-
margin:
139-
title: 'margin'
140-
description:
141-
'''
142-
Specifies the maximum length of a line. Code exceeding this margin will be formatted
143-
across multiple lines.
144-
With the default value (`-1`), `indent` will be automatically set to the current editor's [preferred line length](https://flight-manual.atom.io/using-atom/sections/basic-customization/#configuration-key-reference).
145-
'''
146-
type: 'integer'
147-
default: -1
148-
order: 2
149-
always_for_in:
150-
title: 'always_for_in'
151-
description:
152-
'''
153-
If `always_for_in` is true `=` is always replaced with `in` if part of a
154-
`for` loop condition. For example, `for i = 1:10` will be transformed
155-
to `for i in 1:10`.
156-
'''
157-
type: 'boolean'
158-
default: false
159-
order: 3
160-
whitespace_typedefs:
161-
title: 'whitespace_typedefs'
162-
description:
163-
'''
164-
If `whitespace_typedefs` is true, whitespace is added for type definitions.
165-
Make this `true` if you prefer `Union{A <: B, C}` to `Union{A<:B,C}`.
166-
'''
167-
type: 'boolean'
168-
default: false
169-
order: 4
170-
whitespace_ops_in_indices:
171-
title: 'whitespace_ops_in_indices'
172-
description:
173-
'''
174-
If `whitespace_ops_in_indices` is true, whitespace is added for binary operations
175-
in indices. Make this `true` if you prefer `arr[a + b]` to `arr[a+b]`. Additionally, if there's a colon `:` involved, parenthesis will be added to the LHS and RHS.
176-
'''
177-
type: 'boolean'
178-
default: false
179-
order: 5
180-
remove_extra_newlines:
181-
title: 'remove_extra_newlines'
182-
description:
183-
'''
184-
If `remove_extra_newlines` is true superflous newlines will be removed.
185-
'''
186-
type: 'boolean'
187-
default: false
188-
order: 6
189-
import_to_using:
190-
title: 'import_to_using'
191-
description:
192-
'''
193-
If true import expressions are rewritten to using expressions in cases like:
194-
`import A` is rewritten to `using A: A`
195-
'''
196-
type: 'boolean'
197-
default: false
198-
order: 7
199-
pipe_to_function_call:
200-
title: 'pipe_to_function_call'
201-
description:
202-
'''
203-
If true `x |> f` is rewritten to `f(x)`.
204-
'''
205-
type: 'boolean'
206-
default: false
207-
order: 8
208-
short_to_long_function_def:
209-
title: 'short_to_long_function_def'
210-
description:
211-
'''
212-
Transforms a _short_ function definition to a _long_ function definition
213-
'''
214-
type: 'boolean'
215-
default: false
216-
order: 9
217-
always_use_return:
218-
title: 'always_use_return'
219-
description:
220-
'''
221-
If true `return` will be prepended to the last expression where applicable in function definitions, macro definitions, and do blocks.
222-
'''
223-
type: 'boolean'
224-
default: false
225-
order: 10
226-
use_YAS_style:
227-
title: 'YAS style'
228-
description:
229-
'''
230-
If true use formatting style based on [YASGuide](https://github.com/jrevels/YASGuide).
231-
See [JuliaFormatter's documentation](https://domluna.github.io/JuliaFormatter.jl/dev/yas_style/#) for more details.
232-
'''
233-
type: 'boolean'
234-
default: false
235-
order: 11
134+
mock:
135+
title: 'mock (not appear in the settings view)'
136+
type: 'object'
137+
default: {}
236138

237139
uiOptions:
238140
title: 'UI Options'

lib/runtime/formatter.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** @babel */
22

3+
import path from 'path'
34
import { client } from '../connection'
45
import { CompositeDisposable } from 'atom'
56

@@ -30,42 +31,28 @@ function formatEditorWithSelection (editor, selection) {
3031
}
3132

3233
function formatEditorTextInRange (editor, range, text) {
34+
const dir = path.dirname(client.editorPath(editor))
3335
const marker = markRange(editor, range)
3436
// NOTE: Branch on `getSoftTabs` if supported by formatter.
35-
let indent = atom.config.get('julia-client.juliaOptions.formattingOptions.indent')
36-
if (indent === -1) indent = editor.getTabLength()
37-
let margin = atom.config.get('julia-client.juliaOptions.formattingOptions.margin')
38-
if (margin === -1) margin = editor.getPreferredLineLength()
37+
const indent = editor.getTabLength()
38+
const margin = editor.getPreferredLineLength()
3939
format({
4040
text,
41+
dir,
4142
indent,
4243
margin,
43-
44-
// TODO:
45-
// maintaining those lists are not so fun;
46-
// do https://github.com/domluna/JuliaFormatter.jl/issues/184 and switch to respect a project configuration,
47-
// then we will be able to leave each user to set those configurations
48-
always_for_in: atom.config.get('julia-client.juliaOptions.formattingOptions.always_for_in'),
49-
whitespace_typedefs: atom.config.get('julia-client.juliaOptions.formattingOptions.whitespace_typedefs'),
50-
whitespace_ops_in_indices: atom.config.get('julia-client.juliaOptions.formattingOptions.whitespace_ops_in_indices'),
51-
remove_extra_newlines: atom.config.get('julia-client.juliaOptions.formattingOptions.remove_extra_newlines'),
52-
import_to_using: atom.config.get('julia-client.juliaOptions.formattingOptions.import_to_using'),
53-
pipe_to_function_call: atom.config.get('julia-client.juliaOptions.formattingOptions.pipe_to_function_call'),
54-
short_to_long_function_def: atom.config.get('julia-client.juliaOptions.formattingOptions.short_to_long_function_def'),
55-
always_use_return: atom.config.get('julia-client.juliaOptions.formattingOptions.always_use_return'),
56-
use_YAS_style: atom.config.get('julia-client.juliaOptions.formattingOptions.use_YAS_style'),
5744
}).then(({ error, formattedtext }) => {
5845
if (error) {
5946
atom.notifications.addError('Julia-Client: Format-Code', {
60-
detail: error,
47+
description: error,
6148
dismissable: true
6249
})
6350
} else {
6451
if (marker.isValid()) {
6552
editor.setTextInBufferRange(marker.getBufferRange(), formattedtext)
6653
} else {
6754
atom.notifications.addError('Julia-Client: Format-Code', {
68-
detail: 'Cancelled the formatting task because the selected code has been manually modified.',
55+
description: 'Cancelled the formatting task because the selected code has been manually modified.',
6956
dismissable: true
7057
})
7158
}

0 commit comments

Comments
 (0)