settings — IDE 设置

读写 IDE 配置项,支持通用接口与类型化子命名空间。

self.settings 提供 IDE 设置的读写能力。所有设置项以点号分隔的名称标识,例如 theme.modeeditor.font_sizeserial.default_baud_rate。除通用接口外,还提供按领域划分的类型化子命名空间,每个子命名空间暴露成对的 get_X / set_X 方法。

通用方法

方法说明
get(name, callback?)读取任意设置项
set(name, value, callback?)写入任意设置项
list(callback?)列出所有设置项

get(name, callback?)

self.settings.get(
    "theme.mode",
    callback=lambda **cb: print(cb.get("value")),
)

参数:

  • name (str) — 设置项名称,使用点号分隔,如 theme.mode

set(name, value, callback?)

self.settings.set("theme.mode", "dark")

参数:

  • name (str) — 设置项名称
  • value (Any) — 设置值

list(callback?)

self.settings.list(callback=lambda **cb: print(cb))

子命名空间

子命名空间说明键前缀
self.settings.theme外观与样式theme.
self.settings.editor编辑器editor.
self.settings.lsp语言服务器lsp.
self.settings.serial串口serial.
self.settings.terminal终端显示terminal.
self.settings.micropython_stubsMicroPython 类型存根micropython.stubs.

ThemeSettings

self.settings.theme,对应键前缀 theme.

方法对值类型
get_mode / set_modetheme.modestr
get_style / set_styletheme.stylestr
get_color / set_colortheme.colorint (可选)
get_active_plugin_theme_id / set_active_plugin_theme_idtheme.active_plugin_theme_idstr (可选)
get_use_material_context_menu / set_use_material_context_menutheme.use_material_context_menubool
self.settings.theme.get_mode(
    callback=lambda **cb: print(cb.get("value")),
)
self.settings.theme.set_mode("dark")
self.settings.theme.set_use_material_context_menu(True)

EditorSettings

self.settings.editor,对应键前缀 editor.

方法对值类型
get_font_family / set_font_familyeditor.font_familystr
get_font_size / set_font_sizeeditor.font_sizefloat
get_word_wrap / set_word_wrapeditor.word_wrapbool
get_line_number / set_line_numbereditor.line_numberbool
get_chinese_to_unicode / set_chinese_to_unicodeeditor.chinese_to_unicodebool
get_enable_signal_detection / set_enable_signal_detectioneditor.enable_signal_detectionbool
get_upload_confirm_style / set_upload_confirm_styleeditor.upload_confirm_stylestr
get_confirm_shortcut / set_confirm_shortcuteditor.confirm_shortcutstr
get_cancel_shortcut / set_cancel_shortcuteditor.cancel_shortcutstr
get_code_folding / set_code_foldingeditor.code_foldingbool
get_guide_lines / set_guide_lineseditor.guide_linesbool
get_local_suggestions / set_local_suggestionseditor.local_suggestionsbool
get_keyboard_suggestions / set_keyboard_suggestionseditor.keyboard_suggestionsbool
get_use_space_as_tab / set_use_space_as_tabeditor.use_space_as_tabbool
get_tab_size / set_tab_sizeeditor.tab_sizeint
get_gutter_divider / set_gutter_dividereditor.gutter_dividerbool
self.settings.editor.set_font_family("JetBrains Mono")
self.settings.editor.set_font_size(14.0)
self.settings.editor.set_word_wrap(True)
self.settings.editor.set_tab_size(4)

LspSettings

self.settings.lsp,对应键前缀 lsp.

方法对值类型
get_enabled / set_enabledlsp.enabledbool
get_type / set_typelsp.typestr
get_websocket_path / set_websocket_pathlsp.websocket_pathstr
get_stdio_executable / set_stdio_executablelsp.stdio_executablestr
get_stdio_args / set_stdio_argslsp.stdio_argsstr
get_disable_warning / set_disable_warninglsp.disable_warningbool
get_disable_error / set_disable_errorlsp.disable_errorbool
get_semantic_highlighting / set_semantic_highlightinglsp.semantic_highlightingbool
get_code_completion / set_code_completionlsp.code_completionbool
get_hover_info / set_hover_infolsp.hover_infobool
get_code_action / set_code_actionlsp.code_actionbool
get_signature_help / set_signature_helplsp.signature_helpbool
get_document_color / set_document_colorlsp.document_colorbool
get_document_highlight / set_document_highlightlsp.document_highlightbool
get_code_folding / set_code_foldinglsp.code_foldingbool
get_inlay_hint / set_inlay_hintlsp.inlay_hintbool
get_go_to_definition / set_go_to_definitionlsp.go_to_definitionbool
get_rename / set_renamelsp.renamebool
self.settings.lsp.set_enabled(True)
self.settings.lsp.set_type("stdio")
self.settings.lsp.set_stdio_executable("pylsp")

SerialSettings

self.settings.serial,对应键前缀 serial.

方法对值类型
get_default_baud_rate / set_default_baud_rateserial.default_baud_rateint
get_auto_reconnect / set_auto_reconnectserial.auto_reconnectbool
get_repl_mode / set_repl_modeserial.repl_modestr
get_file_transfer_mode / set_file_transfer_modeserial.file_transfer_modestr
get_hardware_reset_strategy / set_hardware_reset_strategyserial.hardware_reset_strategystr
self.settings.serial.set_default_baud_rate(115200)
self.settings.serial.set_auto_reconnect(True)

TerminalSettings

self.settings.terminal,对应键前缀 terminal.

方法对值类型
get_font_family / set_font_familyterminal.font_familystr
get_font_size / set_font_sizeterminal.font_sizefloat
get_line_height / set_line_heightterminal.line_heightfloat
self.settings.terminal.set_font_family("Cascadia Code")
self.settings.terminal.set_font_size(14.0)
self.settings.terminal.set_line_height(1.5)

MicroPythonStubsSettings

self.settings.micropython_stubs,对应键前缀 micropython.stubs.

方法对值类型
get_enabled / set_enabledmicropython.stubs.enabledbool
get_auto_detect_layers / set_auto_detect_layersmicropython.stubs.auto_detect_layersbool
get_layers / set_layersmicropython.stubs.layerslist[dict]
get_extra_paths / set_extra_pathsmicropython.stubs.extra_pathslist[str]
self.settings.micropython_stubs.set_enabled(True)
self.settings.micropython_stubs.set_layers([
    {"provider": "my-stubs", "profile": "esp32"},
])
self.settings.micropython_stubs.set_extra_paths(["/path/to/stubs"])

使用示例

class SetupPlugin(UiPlugin):
    def configure_editor(self):
        self.settings.editor.set_font_family("JetBrains Mono")
        self.settings.editor.set_font_size(14.0)
        self.settings.editor.set_use_space_as_tab(True)

    def read_setting(self):
        self.settings.get(
            "editor.font_size",
            callback=lambda **cb: print(cb.get("value")),
        )

    def list_all(self):
        self.settings.list(callback=lambda **cb: print(cb))

设置名使用点号分隔且区分大小写,拼写错误会导致读取或写入失败。set 会立即生效并持久化,请谨慎覆盖用户配置。

On this page