|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2024 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Editor Config interface to the eric-ide server. |
|
8 """ |
|
9 |
|
10 import editorconfig |
|
11 |
|
12 from PyQt6.QtCore import QEventLoop, QObject |
|
13 |
|
14 from eric7.RemoteServer.EricRequestCategory import EricRequestCategory |
|
15 from eric7.SystemUtilities import FileSystemUtilities |
|
16 |
|
17 |
|
18 class EricServerEditorConfigInterface(QObject): |
|
19 """ |
|
20 Class implementing the Editor Config interface to the eric-ide server. |
|
21 """ |
|
22 |
|
23 def __init__(self, serverInterface): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param serverInterface reference to the eric-ide server interface |
|
28 @type EricServerInterface |
|
29 """ |
|
30 super().__init__(parent=serverInterface) |
|
31 |
|
32 self.__serverInterface = serverInterface |
|
33 |
|
34 def loadEditorConfig(self, filename): |
|
35 """ |
|
36 Public method to load the editor config for the given file. |
|
37 |
|
38 @param filename name of the file to get the editor config for |
|
39 @type str |
|
40 @return dictionary containing the editor config data |
|
41 @rtype dict |
|
42 @exception EditorConfigError raised to indicate an issue loading the editor |
|
43 config |
|
44 """ |
|
45 loop = QEventLoop() |
|
46 ok = False |
|
47 config = None |
|
48 |
|
49 def callback(reply, params): |
|
50 """ |
|
51 Function to handle the server reply |
|
52 |
|
53 @param reply name of the server reply |
|
54 @type str |
|
55 @param params dictionary containing the reply data |
|
56 @type dict |
|
57 """ |
|
58 nonlocal ok, config |
|
59 |
|
60 if reply == "LoadEditorConfig": |
|
61 ok = params["ok"] |
|
62 config = params["config"] |
|
63 loop.quit() |
|
64 |
|
65 |
|
66 if not self.__serverInterface.isServerConnected(): |
|
67 raise editorconfig.EditorConfigError( |
|
68 "Not connected to an 'eric-ide' server." |
|
69 ) |
|
70 else: |
|
71 self.__serverInterface.sendJson( |
|
72 category=EricRequestCategory.EditorConfig, |
|
73 request="LoadEditorConfig", |
|
74 params={"filename": FileSystemUtilities.plainFileName(filename)}, |
|
75 callback=callback, |
|
76 ) |
|
77 |
|
78 loop.exec() |
|
79 if not ok: |
|
80 raise editorconfig.EditorConfigError() |
|
81 |
|
82 return config |