Skip to content

Add option "useFormatterConfigDefaults" to make it search upwards for .JuliaFormatter.toml and also in home dir #1349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ if there is no parent project.
## Development of the VSCode extension

See https://github.com/julia-vscode/julia-vscode/wiki for information on how to test this package with the VSCode extension

## LanguageServer.jl does not normally search upwards for .JuliaFormatter.toml
You can turn this on by setting the initialization option "useFormatterConfigDefaults" to true
2 changes: 2 additions & 0 deletions src/LanguageServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import Dates

export LanguageServerInstance, runserver

const INIT_OPT_USE_FORMATTER_CONFIG_DEFAULTS = "useFormatterConfigDefaults"

const g_operationId = Ref{String}("")

JSON.lower(uri::URI) = string(uri)
Expand Down
17 changes: 14 additions & 3 deletions src/requests/features.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,20 @@

# search through workspace for a `.JuliaFormatter.toml`
workspace_dirs = sort(filter(f -> startswith(path, f), collect(server.workspaceFolders)), by = length, rev = true)
config_path = length(workspace_dirs) > 0 ?
search_file(JuliaFormatter.CONFIG_FILE_NAME, path, workspace_dirs[1]) :
nothing
if ismissing(server.initialization_options) || !get(server.initialization_options, INIT_OPT_USE_FORMATTER_CONFIG_DEFAULTS, false)
config_path = length(workspace_dirs) > 0 ?
search_file(JuliaFormatter.CONFIG_FILE_NAME, path, workspace_dirs[1]) :
nothing
else
@debug "using standard formatter config file locations"
config_path = length(workspace_dirs) > 0 ?

Check warning on line 139 in src/requests/features.jl

View check run for this annotation

Codecov / codecov/patch

src/requests/features.jl#L138-L139

Added lines #L138 - L139 were not covered by tests
search_file(JuliaFormatter.CONFIG_FILE_NAME, path, "/") :
nothing
if isnothing(config_path) && haskey(ENV, "HOME")
local home = ENV["HOME"]
config_path = search_file(JuliaFormatter.CONFIG_FILE_NAME, home, home)

Check warning on line 144 in src/requests/features.jl

View check run for this annotation

Codecov / codecov/patch

src/requests/features.jl#L142-L144

Added lines #L142 - L144 were not covered by tests
end
end

config_path === nothing && return nothing

Expand Down
Loading