src/eric7/RemoteServerInterface/EricServerEditorConfigInterface.py

Thu, 11 Jul 2024 14:21:34 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 11 Jul 2024 14:21:34 +0200
branch
eric7
changeset 10840
c8045d0dbaa7
parent 10776
ec110553c5ab
child 11090
f5f5f5803935
permissions
-rw-r--r--

MicroPython
- Updated the list of known CircuitPython boards for CPy 9.1.0.
- Updated the list of known UF2 capable boards.

# -*- coding: utf-8 -*-

# Copyright (c) 2024 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing the Editor Config interface to the eric-ide server.
"""

import editorconfig

from PyQt6.QtCore import QEventLoop, QObject

from eric7.RemoteServer.EricRequestCategory import EricRequestCategory
from eric7.SystemUtilities import FileSystemUtilities


class EricServerEditorConfigInterface(QObject):
    """
    Class implementing the Editor Config interface to the eric-ide server.
    """

    def __init__(self, serverInterface):
        """
        Constructor

        @param serverInterface reference to the eric-ide server interface
        @type EricServerInterface
        """
        super().__init__(parent=serverInterface)

        self.__serverInterface = serverInterface

    def loadEditorConfig(self, filename):
        """
        Public method to load the editor config for the given file.

        @param filename name of the file to get the editor config for
        @type str
        @return dictionary containing the editor config data
        @rtype dict
        @exception editorconfig.EditorConfigError raised to indicate an
            issue loading the editor config
        """
        loop = QEventLoop()
        ok = False
        config = None

        def callback(reply, params):
            """
            Function to handle the server reply

            @param reply name of the server reply
            @type str
            @param params dictionary containing the reply data
            @type dict
            """
            nonlocal ok, config

            if reply == "LoadEditorConfig":
                ok = params["ok"]
                config = params["config"]
                loop.quit()

        if not self.__serverInterface.isServerConnected():
            raise editorconfig.EditorConfigError(
                "Not connected to an 'eric-ide' server."
            )
        else:
            self.__serverInterface.sendJson(
                category=EricRequestCategory.EditorConfig,
                request="LoadEditorConfig",
                params={"filename": FileSystemUtilities.plainFileName(filename)},
                callback=callback,
            )

            loop.exec()
            if not ok:
                raise editorconfig.EditorConfigError()

            return config

eric ide

mercurial