Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Cthulhu"
uuid = "f68482b8-f384-11e8-15f7-abe071a5a75f"
version = "3.0.0"
version = "3.0.1"
authors = ["Valentin Churavy <[email protected]> and contributors"]

[deps]
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ julia> Cthulhu.CONFIG.enable_highlighter = true # Change default
true

julia> Cthulhu.save_config!(Cthulhu.CONFIG) # Will be automatically read next time you `using Cthulhu`

julia> Cthulhu.save_config!(Cthulhu.CONFIG; force = true) # to overwrite any existing preferences
```

## Development
Expand Down
11 changes: 7 additions & 4 deletions src/preferences.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""
```julia
save_config!(config::CthulhuConfig=CONFIG)
save_config!(config::CthulhuConfig=CONFIG; kwargs...)
```
Save a Cthulhu.jl configuration `config` (by default, `Cthulhu.CONFIG`) to your
`LocalPreferences.toml` file using Preferences.jl.
`LocalPreferences.toml` file using Preferences.jl. For more information about
`kwargs`, refer to the documentation of `Preferences.set_preferences!`.

The saved preferences will be automatically loaded next time you `using Cthulhu`.

Expand All @@ -20,9 +21,11 @@ julia> Cthulhu.CONFIG.debuginfo = :none # Customize some defaults
:none

julia> Cthulhu.save_config!(Cthulhu.CONFIG) # Will be automatically read next time you `using Cthulhu`

julia> Cthulhu.save_config!(Cthulhu.CONFIG; force = true) # to overwrite any existing preferences
```
"""
function save_config!(config::CthulhuConfig=CONFIG)
function save_config!(config::CthulhuConfig=CONFIG; kwargs...)
set_preferences!(Cthulhu,
"enable_highlighter" => config.enable_highlighter,
"highlighter" => config.highlighter.exec,
Expand All @@ -38,7 +41,7 @@ function save_config!(config::CthulhuConfig=CONFIG)
"view" => String(config.view),
"inlay_types_vscode" => config.inlay_types_vscode,
"diagnostics_vscode" => config.diagnostics_vscode,
"jump_always" => config.jump_always)
"jump_always" => config.jump_always; kwargs...)
end

function read_config!()
Expand Down
6 changes: 5 additions & 1 deletion test/test_Cthulhu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -863,14 +863,18 @@ end
@testset "preferences" begin
# Test that load and save are able to set state
set_config!(; enable_highlighter = true, debuginfo = :none)
Cthulhu.save_config!()
Cthulhu.save_config!(; force = true)
set_config!(; enable_highlighter = false, debuginfo = :compact)
@test Cthulhu.CONFIG.enable_highlighter === false
@test Cthulhu.CONFIG.debuginfo === :compact

Cthulhu.read_config!()
@test Cthulhu.CONFIG.enable_highlighter === true
@test Cthulhu.CONFIG.debuginfo === :none

set_config!(; debuginfo = :source)
@test_throws "Cannot set preference" Cthulhu.save_config!()
Cthulhu.save_config!(; force = true)
end

Base.@constprop :none sin_noconstprop(x) = sin(x)
Expand Down
Loading