Skip to content

Commit 25c9d32

Browse files
committed
wip jupyterlab
1 parent 22c4dc3 commit 25c9d32

File tree

4 files changed

+85
-7
lines changed

4 files changed

+85
-7
lines changed

server/__main__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from server.controller import odoo_server
55
from server.constants import *
66

7-
FORMAT = '(%(process)d) [%(levelname)s] %(message)s'
7+
FORMAT = '%(asctime)s %(levelname)s: %(message)s'
88

99
def add_arguments(parser):
1010
parser.description = "simple odoo server example"
@@ -39,7 +39,7 @@ def main():
3939
parser = argparse.ArgumentParser()
4040
add_arguments(parser)
4141
args = parser.parse_args()
42-
logging.basicConfig(format=FORMAT, filename=args.log, level=logging.DEBUG, filemode="w")
42+
logging.basicConfig(format=FORMAT, datefmt='%Y-%m-%d %I:%M:%S', filename=args.log, level=logging.DEBUG, filemode="w")
4343

4444
if "alpha" in EXTENSION_VERSION:
4545
logging.getLogger().setLevel(logging.DEBUG)

server/core/odoo.py

+60-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,53 @@
2727
log = logging.getLogger(__name__)
2828

2929

30+
class Postgres():
31+
def __init__(self, db='postgres', autocommit=True, user=None, password=None,
32+
host=None, port=None, as_dict=True, app=None, timeout=None):
33+
self.conn = None
34+
self.cr = None
35+
36+
import psycopg2
37+
import psycopg2.extras
38+
39+
connstring = "dbname=%s" % db
40+
if host or port or user:
41+
connstring += " host=%s" % (host or 'localhost')
42+
if user:
43+
connstring += " user=%s" % user
44+
if port:
45+
connstring += " port=%s" % port
46+
if password:
47+
connstring += " password=%s" % password
48+
try:
49+
self.conn = psycopg2.connect(connstring, application_name=app)
50+
except TypeError:
51+
# We still have to deal with old psycopg2 versions (eg: saas master)
52+
self.conn = psycopg2.connect(connstring)
53+
self.conn.autocommit = autocommit
54+
if as_dict:
55+
self.cr = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
56+
else:
57+
# kept as it's slightly better for performance
58+
self.cr = self.conn.cursor()
59+
if timeout:
60+
self.cr.execute("SET statement_timeout TO %s", (timeout, ))
61+
62+
def __enter__(self):
63+
return self.cr
64+
65+
def __exit__(self, exc_type, exc_value, exc_traceback):
66+
self.close()
67+
68+
def __del__(self):
69+
self.close()
70+
71+
def close(self):
72+
if self.cr:
73+
self.cr.close()
74+
if self.conn:
75+
self.conn.close()
76+
3077

3178
class Odoo():
3279

@@ -97,7 +144,7 @@ def acquire_read(self, timeout=-1):
97144
return
98145
OdooLanguageServer.access_mode.set("read")
99146
yield Odoo.get() == self # to be sure Odoo.instance is still bound to the same instance
100-
147+
101148
self.thread_access_condition.release()
102149
OdooLanguageServer.access_mode.set("none")
103150

@@ -134,16 +181,12 @@ def initialize(ls:LanguageServer = None):
134181

135182
try:
136183
Odoo.instance = Odoo()
137-
log.debug('===========CONFIG ls %s', ls)
138184
odooConfig = ls.lsp.send_request("Odoo/getConfiguration").result()
139-
log.debug('===========odooCONFIG???? %s', odooConfig)
140185
config = ls.get_configuration(WorkspaceConfigurationParams(items=[
141186
ConfigurationItem(
142187
scope_uri='window',
143188
section="Odoo")
144189
])).result()
145-
log.debug('===========CONFIG???? %s', config)
146-
147190
Odoo.instance.refreshMode = config[0]["autoRefresh"]
148191
Odoo.instance.autoSaveDelay = config[0]["autoRefreshDelay"]
149192
ls.file_change_event_queue.set_delay(Odoo.instance.autoSaveDelay)
@@ -158,6 +201,15 @@ def initialize(ls:LanguageServer = None):
158201
Odoo.instance.grammar = parso.load_grammar()
159202
Odoo.instance.start_build_time = time.time()
160203
Odoo.instance.odooPath = odooConfig.odooPath
204+
if hasattr(odooConfig, 'database') and os.environ.get('PGDATABASE'):
205+
Odoo.instance.database = os.environ.get('PGDATABASE')
206+
else:
207+
Odoo.instance.database = False
208+
if Odoo.instance.database:
209+
with Postgres(Odoo.instance.database) as cr:
210+
cr.execute("SELECT name FROM ir_module_module WHERE state = 'installed';")
211+
Odoo.instance.installed_modules = [mod[0] for mod in cr.fetchall()]
212+
161213
if os.name == "nt":
162214
Odoo.instance.odooPath = Odoo.instance.odooPath[0].capitalize() + Odoo.instance.odooPath[1:]
163215
Odoo.instance.load_builtins(ls)
@@ -380,6 +432,9 @@ def build_modules(self, ls):
380432
dirs = os.listdir(path)
381433
for dir in dirs:
382434
if os.path.isdir(os.path.join(path, dir)):
435+
if Odoo.instance.database and dir not in Odoo.instance.installed_modules:
436+
log.info('----skipped %s', dir)
437+
continue
383438
PythonArchBuilder(ls, addonsSymbol, os.path.join(path, dir)).load_arch(require_module=True)
384439
if self.stop_init:
385440
break

server/features/autocomplete.py

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
from lsprotocol.types import (CompletionItemKind, CompletionList, CompletionItemKind, CompletionItem,
77
CompletionItemLabelDetails, MarkupContent, MarkupKind)
88

9+
import logging
10+
11+
log = logging.getLogger(__name__)
12+
913
class AutoCompleteFeature:
1014

1115
@staticmethod
@@ -78,6 +82,9 @@ def build_model_completion_list(models, module):
7882

7983
@staticmethod
8084
def autocomplete(path, content, line, char):
85+
log.info('=========%s', Odoo)
86+
log.info('=========%s', Odoo.get())
87+
log.info('=========%s', Odoo.get().grammar)
8188
parsoTree = Odoo.get().grammar.parse(content, error_recovery=True, cache = False)
8289
element = parsoTree.get_leaf_for_position((line, char-1), include_prefixes=True)
8390
#Test assignement

setup.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import setuptools
2+
3+
4+
setuptools.setup(
5+
version='0.2.2',
6+
name='odoo-language-server',
7+
long_description_content_type='text/markdown',
8+
packages=setuptools.find_packages(),
9+
include_package_data=True,
10+
install_requires=[
11+
'lsprotocol',
12+
'pygls',
13+
'psycopg2',
14+
],
15+
entry_points={'console_scripts': ['odoo-ls = server.__main__:main']},
16+
)

0 commit comments

Comments
 (0)