aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2023-04-24 19:39:07 +0200
committerTristan Gingold <tgingold@free.fr>2023-04-24 19:39:07 +0200
commitf27fa74f758572bfe367967a37fd515598042093 (patch)
tree4986e19bac0b723022881bcfa5ca5b0998a72e36
parentd2c1b7a5c1a1f68e7b8f99f29c46d1f050452963 (diff)
downloadghdl-f27fa74f758572bfe367967a37fd515598042093.tar.gz
ghdl-f27fa74f758572bfe367967a37fd515598042093.tar.bz2
ghdl-f27fa74f758572bfe367967a37fd515598042093.zip
pyGHDL/lsp: support library in hdl-prj.json
-rw-r--r--pyGHDL/lsp/document.py15
-rw-r--r--pyGHDL/lsp/workspace.py21
2 files changed, 22 insertions, 14 deletions
diff --git a/pyGHDL/lsp/document.py b/pyGHDL/lsp/document.py
index ff7227301..cc8ca2226 100644
--- a/pyGHDL/lsp/document.py
+++ b/pyGHDL/lsp/document.py
@@ -29,10 +29,11 @@ class Document(object):
initial_gap_size = 4096
- def __init__(self, uri, sfe=None, version=None):
+ def __init__(self, uri, sfe=None, lib=None, version=None):
self.uri = uri
self.version = version
self._fe = sfe
+ self.library = lib
self.gap_size = Document.initial_gap_size
self._tree = nodes.Null_Iir
@@ -128,7 +129,12 @@ class Document(object):
files_map_editor.Check_Buffer_Content(self._fe, ctypes.c_char_p(text_bytes), len(text_bytes))
@staticmethod
- def add_to_library(tree):
+ def add_to_library(tree, library):
+ # Set the target library
+ if library is None:
+ library = 'work'
+ libraries.Work_Library_Name.value = name_table.Get_Identifier(library)
+ libraries.Load_Work_Library(False)
# Detach the chain of units.
unit = nodes.Get_First_Design_Unit(tree)
nodes.Set_First_Design_Unit(tree, nodes.Null_Iir)
@@ -153,8 +159,9 @@ class Document(object):
tree = sem_lib.Load_File(self._fe)
if tree == nodes.Null_Iir:
return
- self._tree = Document.add_to_library(tree)
- log.debug("add_to_library(%u) -> %u", tree, self._tree)
+ self._tree = Document.add_to_library(tree, self.library)
+ log.debug("add_to_library(%u, '%s') -> %u",
+ tree, self.library, self._tree)
if self._tree == nodes.Null_Iir:
return
nodes.Set_Design_File_Source(self._tree, self._fe)
diff --git a/pyGHDL/lsp/workspace.py b/pyGHDL/lsp/workspace.py
index 6c312b203..6d5e40d1c 100644
--- a/pyGHDL/lsp/workspace.py
+++ b/pyGHDL/lsp/workspace.py
@@ -78,20 +78,20 @@ class Workspace(object):
def root_uri(self):
return self._root_uri
- def _create_document(self, doc_uri, sfe, version=None):
+ def _create_document(self, doc_uri, sfe, lib, version=None):
"""Create a document and put it in this workspace."""
- doc = document.Document(doc_uri, sfe, version)
+ doc = document.Document(doc_uri, sfe, lib, version)
self._docs[doc_uri] = doc
self._fe_map[sfe] = doc
return doc
- def create_document_from_sfe(self, sfe, abspath):
+ def create_document_from_sfe(self, sfe, abspath, lib):
# A filename has been given without a corresponding document.
# Create the document.
# Common case: an error message was reported in a non-open document.
# Create a document so that it could be reported to the client.
doc_uri = lsp.path_to_uri(os.path.normpath(abspath))
- return self._create_document(doc_uri, sfe)
+ return self._create_document(doc_uri, sfe, lib)
def create_document_from_uri(self, doc_uri, source=None, version=None):
# A document is referenced by an uri but not known. Load it.
@@ -102,7 +102,7 @@ class Workspace(object):
else:
source = source.encode(document.Document.encoding, "replace")
sfe = document.Document.load(source, os.path.dirname(path), os.path.basename(path))
- return self._create_document(doc_uri, sfe)
+ return self._create_document(doc_uri, sfe, None)
def get_or_create_document(self, doc_uri):
res = self.get_document(doc_uri)
@@ -145,11 +145,11 @@ class Workspace(object):
if not os.path.isabs(filename):
dirname = pyutils.name_image(files_map.Get_Directory_Name(sfe))
filename = os.path.join(dirname, filename)
- doc = self.create_document_from_sfe(sfe, filename)
+ doc = self.create_document_from_sfe(sfe, filename, None)
return doc
- def add_vhdl_file(self, name):
- log.info("loading %s", name)
+ def add_vhdl_file(self, name, lib):
+ log.info("loading %s in library %s", name, lib)
if os.path.isabs(name):
absname = name
else:
@@ -162,7 +162,7 @@ class Workspace(object):
except OSError as err:
self._server.show_message(lsp.MessageType.Error, f"cannot load {name}: {err.strerror}")
return
- doc = self.create_document_from_sfe(sfe, absname)
+ doc = self.create_document_from_sfe(sfe, absname, lib)
doc.parse_document()
def read_project(self):
@@ -222,8 +222,9 @@ class Workspace(object):
if not isinstance(name, str):
raise ProjectError("a 'file' is not a string")
lang = f.get("language", "vhdl")
+ lib = f.get("library", None)
if lang == "vhdl":
- self.add_vhdl_file(name)
+ self.add_vhdl_file(name, lib)
except ProjectError as e:
self._server.show_message(lsp.MessageType.Error, f"error in project file: {e.msg}")