-
Notifications
You must be signed in to change notification settings - Fork 90
Open
Description
You can exclude some files from formatting with ignore = [...]
in your .JuliaFormatter.toml
. It seems like LanguageServer / VS Code's "Format on Save" will ignore this, and format the file anyway.
I suspect it's because LanguageServer calls JuliaFormatter.format_text
, which doesn't know about the file identity of the code it's formatting?
LanguageServer.jl/src/requests/features.jl
Lines 150 to 179 in ff8eb2a
function textDocument_formatting_request(params::DocumentFormattingParams, server::LanguageServerInstance, conn) | |
doc = getdocument(server, params.textDocument.uri) | |
newcontent = try | |
config = get_juliaformatter_config(doc, server) | |
format_text(get_text(doc), params, config) | |
catch err | |
return JSONRPC.JSONRPCError( | |
-32000, | |
"Failed to format document: $err.", | |
nothing | |
) | |
end | |
end_l, end_c = get_position_from_offset(doc, sizeof(get_text(doc))) # AUDIT: OK | |
lsedits = TextEdit[TextEdit(Range(0, 0, end_l, end_c), newcontent)] | |
return lsedits | |
end | |
function format_text(text::AbstractString, params, config) | |
if config === nothing | |
return JuliaFormatter.format_text(text; default_juliaformatter_config(params)...) | |
else | |
# Some valid options in config file are not valid for format_text | |
VALID_OPTIONS = (fieldnames(JuliaFormatter.Options)..., :style) | |
config = filter(p -> in(first(p), VALID_OPTIONS), JuliaFormatter.kwargs(config)) | |
return JuliaFormatter.format_text(text; config...) | |
end | |
end |
Metadata
Metadata
Assignees
Labels
No labels