python类Window()的实例源码

workspace.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_project_path(window: sublime.Window) -> 'Optional[str]':
    """
    Returns the common root of all open folders in the window
    """
    if len(window.folders()):
        folder_paths = window.folders()
        return folder_paths[0]
    else:
        view = window.active_view()
        if view:
            filename = view.file_name()
            if filename:
                project_path = os.path.dirname(filename)
                debug("Couldn't determine project directory since no folders are open!",
                      "Using", project_path, "as a fallback.")
                return project_path
            else:
                debug("Couldn't determine project directory since no folders are open",
                      "and the current file isn't saved on the disk.")
                return None
        else:
            debug("No view is active in current window")
            return None  # https://github.com/tomv564/LSP/issues/219
sublime_plugin.py 文件源码 项目:SublimeTerm 作者: percevalw 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def create_window_commands(window_id):
    window = sublime.Window(window_id)
    cmds = []
    for class_ in window_command_classes:
        cmds.append(class_(window))
    return cmds
sublime_plugin.py 文件源码 项目:SublimeTerm 作者: percevalw 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def on_window_command(window_id, name, args):
    window = sublime.Window(window_id)
    for callback in all_callbacks['on_window_command']:
        try:
            res = callback.on_window_command(window, name, args)
            if isinstance(res, tuple):
                return res
            elif res:
                return (res, None)
        except:
            traceback.print_exc()

    return ("", None)
sublime_plugin.py 文件源码 项目:SublimeTerm 作者: percevalw 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def on_post_window_command(window_id, name, args):
    window = sublime.Window(window_id)
    for callback in all_callbacks['on_post_window_command']:
        try:
            callback.on_post_window_command(window, name, args)
        except:
            traceback.print_exc()
sublime_plugin.py 文件源码 项目:TerminalView 作者: Wramberg 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def create_window_commands(window_id):
    window = sublime.Window(window_id)
    cmds = []
    for class_ in window_command_classes:
        cmds.append(class_(window))
    return cmds
sublime_plugin.py 文件源码 项目:TerminalView 作者: Wramberg 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def on_window_command(window_id, name, args):
    window = sublime.Window(window_id)
    for callback in all_callbacks['on_window_command']:
        try:
            res = callback.on_window_command(window, name, args)
            if isinstance(res, tuple):
                return res
            elif res:
                return (res, None)
        except:
            traceback.print_exc()

    return ("", None)
sublime_plugin.py 文件源码 项目:TerminalView 作者: Wramberg 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def on_post_window_command(window_id, name, args):
    window = sublime.Window(window_id)
    for callback in all_callbacks['on_post_window_command']:
        try:
            callback.on_post_window_command(window, name, args)
        except:
            traceback.print_exc()
diagnostic.py 文件源码 项目:DXMate 作者: jtowers 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def create_output_panel(window: sublime.Window, name: str) -> sublime.View:
    panel = window.create_output_panel(name)
    settings = panel.settings()
    for key, value in OUTPUT_PANEL_SETTINGS.items():
        settings.set(key, value)
    return panel
diagnostic.py 文件源码 项目:DXMate 作者: jtowers 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def update_file_diagnostics(window: sublime.Window, file_path: str, source: str,
                            diagnostics: 'List[Diagnostic]'):
    if diagnostics:
        window_file_diagnostics.setdefault(window.id(), dict()).setdefault(
            file_path, dict())[source] = diagnostics
    else:
        if window.id() in window_file_diagnostics:
            file_diagnostics = window_file_diagnostics[window.id()]
            if file_path in file_diagnostics:
                if source in file_diagnostics[file_path]:
                    del file_diagnostics[file_path][source]
                if not file_diagnostics[file_path]:
                    del file_diagnostics[file_path]
diagnostics.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def update_file_diagnostics(window: sublime.Window, file_path: str, source: str,
                            diagnostics: 'List[Diagnostic]'):
    if diagnostics:
        window_file_diagnostics.setdefault(window.id(), dict()).setdefault(
            file_path, dict())[source] = diagnostics
    else:
        if window.id() in window_file_diagnostics:
            file_diagnostics = window_file_diagnostics[window.id()]
            if file_path in file_diagnostics:
                if source in file_diagnostics[file_path]:
                    del file_diagnostics[file_path][source]
                if not file_diagnostics[file_path]:
                    del file_diagnostics[file_path]
diagnostics.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_window_diagnostics(window: sublime.Window) -> 'Optional[Dict[str, Dict[str, List[Diagnostic]]]]':
    return window_file_diagnostics.get(window.id())
panels.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def create_output_panel(window: sublime.Window, name: str) -> sublime.View:
    panel = window.create_output_panel(name)
    settings = panel.settings()
    for key, value in OUTPUT_PANEL_SETTINGS.items():
        settings.set(key, value)
    return panel
clients.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def window_clients(window: sublime.Window) -> 'Dict[str, Client]':
    if window.id() in clients_by_window:
        return clients_by_window[window.id()]
    else:
        # debug("no clients found for window", window.id())
        return {}
clients.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def add_window_client(window: sublime.Window, config_name: str, client: 'Client'):
    global clients_by_window
    clients_by_window.setdefault(window.id(), {})[config_name] = client
    debug("{} client registered for window {}".format(config_name, window.id()))
clients.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def unload_old_clients(window: sublime.Window):
    project_path = get_project_path(window)
    clients_by_config = window_clients(window)
    clients_to_unload = {}
    for config_name, client in clients_by_config.items():
        if client and client.get_project_path() != project_path:
            debug('unload', config_name, 'project path changed from', client.get_project_path(), 'to', project_path)
            clients_to_unload[config_name] = client

    for config_name, client in clients_to_unload.items():
        del clients_by_config[config_name]
        unload_client(client)
main.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def is_starting_config(window: sublime.Window, config_name: str):
    if window.id() in starting_configs_by_window:
        return config_name in starting_configs_by_window[window.id()]
    else:
        return False
main.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def set_starting_config(window: sublime.Window, config_name: str):
    starting_configs_by_window.setdefault(window.id(), set()).add(config_name)
main.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def clear_starting_config(window: sublime.Window, config_name: str):
    starting_configs_by_window[window.id()].remove(config_name)
documents.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def get_document_state(window: sublime.Window, path: str) -> DocumentState:
    window_document_states = document_states.setdefault(window.id(), {})
    if path not in window_document_states:
        window_document_states[path] = DocumentState(path)
    return window_document_states[path]
documents.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def has_document_state(window: sublime.Window, path: str):
    window_id = window.id()
    if window_id not in document_states:
        return False
    return path in document_states[window_id]
documents.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def clear_document_state(window: sublime.Window, path: str):
    window_id = window.id()
    if window_id in document_states:
        del document_states[window_id][path]
documents.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def clear_document_states(window: sublime.Window):
    if window.id() in document_states:
        del document_states[window.id()]
workspace.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_project_config(window: sublime.Window) -> dict:
    project_data = window.project_data() or dict()
    project_settings = project_data.setdefault('settings', dict())
    project_lsp_settings = project_settings.setdefault('LSP', dict())
    return project_lsp_settings
diagnostics.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def ensure_diagnostics_panel(window: sublime.Window):
    return window.find_output_panel("diagnostics") or create_diagnostics_panel(window)
diagnostics.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def update_diagnostics_panel(window: sublime.Window):
    assert window, "missing window!"
    base_dir = get_project_path(window)

    panel = ensure_diagnostics_panel(window)
    assert panel, "must have a panel now!"

    diagnostics_by_file = get_window_diagnostics(window)
    if diagnostics_by_file is not None:
        active_panel = window.active_panel()
        is_active_panel = (active_panel == "output.diagnostics")
        panel.settings().set("result_base_dir", base_dir)
        panel.set_read_only(False)
        if diagnostics_by_file:
            to_render = []
            for file_path, source_diagnostics in diagnostics_by_file.items():
                relative_file_path = os.path.relpath(file_path, base_dir) if base_dir else file_path
                if source_diagnostics:
                    to_render.append(format_diagnostics(relative_file_path, source_diagnostics))
            panel.run_command("lsp_update_panel", {"characters": "\n".join(to_render)})
            if settings.auto_show_diagnostics_panel and not active_panel:
                window.run_command("show_panel",
                                   {"panel": "output.diagnostics"})
        else:
            panel.run_command("lsp_clear_panel")
            if settings.auto_show_diagnostics_panel and is_active_panel:
                window.run_command("hide_panel",
                                   {"panel": "output.diagnostics"})
        panel.set_read_only(True)
references.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def ensure_references_panel(window: sublime.Window):
    return window.find_output_panel("references") or create_references_panel(window)
references.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def create_references_panel(window: sublime.Window):
    panel = create_output_panel(window, "references")
    panel.settings().set("result_file_regex",
                         r"^\s+\S\s+(\S.+)\s+(\d+):?(\d+)$")
    panel.assign_syntax("Packages/" + PLUGIN_NAME +
                        "/Syntaxes/References.sublime-syntax")
    # Call create_output_panel a second time after assigning the above
    # settings, so that it'll be picked up as a result buffer
    # see: Packages/Default/exec.py#L228-L230
    panel = window.create_output_panel("references")
    return panel
sublime_plugin.py 文件源码 项目:windows-st-portable-x64 作者: zce 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def create_window_commands(window_id):
    window = sublime.Window(window_id)
    cmds = []
    for class_ in window_command_classes:
        cmds.append(class_(window))
    return cmds
sublime_plugin.py 文件源码 项目:windows-st-portable-x64 作者: zce 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def on_window_command(window_id, name, args):
    window = sublime.Window(window_id)
    for callback in all_callbacks['on_window_command']:
        try:
            res = callback.on_window_command(window, name, args)
            if isinstance(res, tuple):
                return res
            elif res:
                return (res, None)
        except:
            traceback.print_exc()

    return ("", None)
sublime_plugin.py 文件源码 项目:windows-st-portable-x64 作者: zce 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def on_post_window_command(window_id, name, args):
    window = sublime.Window(window_id)
    for callback in all_callbacks['on_post_window_command']:
        try:
            callback.on_post_window_command(window, name, args)
        except:
            traceback.print_exc()


问题


面经


文章

微信
公众号

扫码关注公众号