diff -r b2e75ba58a30 -r 7f7ff7456904 src/eric7/RemoteServerInterface/EricServerEditorConfigInterface.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/eric7/RemoteServerInterface/EricServerEditorConfigInterface.py Tue Jun 11 16:42:56 2024 +0200 @@ -0,0 +1,82 @@ +# -*- 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 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