Easier/better settings chaining
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Start by reviewing the existing SettingsDict abstraction and the ChainMap-based examples in the issue, then compare their subscription and mutation behavior across view, window, and project settings. The issue is complete only after the project settles the API design, including chain modification, subscriptions, and project-data handling.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Inspired by this forum thread.
Some packages want to allow package settings to be overridden per view, per window, and/or per project. We recommend using a ChainMap of SettingsDicts for this. However, this only works if all of the Settings objects use the same keys. In practice, packages should and often do cordon off the package-specific parts of view, window, and project settings. This is usually done in one of two ways:
- Prefixing the key (e.g.
my_settingin the global package settings,Example Package-my_settingin the view settings). - Putting all package settings under a struct (e.g.
Example Package→my_settingin the project settings).
Even with SettingsDict and ChainMap, this requires boilerplate to implement. Consider the following code sample from ESLint-Formatter:
@staticmethod
def get_pref(key):
global_settings = sublime.load_settings(SETTINGS_FILE)
value = global_settings.get(key)
# Load active project settings
project_settings = sublime.active_window().active_view().settings()
# Overwrite global config value if it's defined
if project_settings.has(PROJECT_NAME):
value = project_settings.get(PROJECT_NAME).get(key, value)
return value
This only handles two levels (package and project), is read-only, and relies on active_window(). but it's still a fair bit of code. Adding window and view settings would add yet more complication.
It would seem beneficial for sublime_lib to provide an abstraction for this pattern that is robust, full-featured, and easy to use. The simplest approach (in terms of implementation) would be to define simple dictionary decorators and rely on ChainMap:
settings = ChainMap(
PrefixedDict(SettingsDict(view.settings()), 'MySettings-'),
PrefixedDict(SettingsDict(window.settings()), 'MySettings-'),
NamedSettingsDict('MySettings')
)
This is still a fair bit of boilerplate, though. In addition, the ChainMap is missing the subscribe functionality that SettingsDict provides; a plugin would have to subscribe to each individually and manually check whether the value has changed.
A more usable solution would be a single constructor:
settings = SettingsChain('MySettings', window)
settings = SettingsChain('MySettings', view) # includes window implicitly?
This is a bit more opinionated than the user building their own stack piece-by-piece, but it's a lot more concise and would encourage consistency among packages that used it.
Questions:
- Does this generally sound like a reasonable feature to provide?
- What's the right balance of convenience without confusion?
- How should we handle modifying the chain? We could follow the ChainMap convention of modifying the top dict, or we could require that the user specify, e.g.
my_chain.view[key] = value. - What do we do about project data? It's not a real Settings, so even if we shimmed it there's no way to subscribe to changes.
- Ngôn ngữ chính
- Python
- Star
- 56
- Fork
- 5
- Merge trung bình
- 19 phút
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của SublimeText/sublime_lib
-
Conversion errorĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
SublimeText/sublime_lib#210 · 1 bình luận ·
-
documentation
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
SublimeText/sublime_lib#183 ·
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 38/100
SublimeText/sublime_lib#173 · 1 reaction ·
-
Settings listener classesĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
SublimeText/sublime_lib#164 · 1 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
SublimeText/sublime_lib#141 · 2 bình luận ·
Tất cả issue của SublimeText/sublime_lib
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
its-me-prash/vwgroup-connect-ha#2019 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
KonstantinStarovoytov/kitden#21 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
RefactorĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
ehmatthes/gh-profiler#166 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
smart-on-fhir/smart-fetch#73 ·
-
good first issue help wanted
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 85/100
RizgarOzan/playcal#13 ·