diff options
author | Tristan Gingold <tgingold@free.fr> | 2022-06-24 19:47:33 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2022-06-25 06:50:56 +0200 |
commit | d737564887fd1603c89a045e7b985b765c16d2d6 (patch) | |
tree | 05072e689982ca33935a156cde5fa108bd562f5d /pyGHDL/lsp | |
parent | f682dca71469ded57bb637c29e41897672cffa99 (diff) | |
download | ghdl-d737564887fd1603c89a045e7b985b765c16d2d6.tar.gz ghdl-d737564887fd1603c89a045e7b985b765c16d2d6.tar.bz2 ghdl-d737564887fd1603c89a045e7b985b765c16d2d6.zip |
pyGHDL/lsp: load files as bytes string
Diffstat (limited to 'pyGHDL/lsp')
-rw-r--r-- | pyGHDL/lsp/document.py | 3 | ||||
-rw-r--r-- | pyGHDL/lsp/workspace.py | 6 |
2 files changed, 5 insertions, 4 deletions
diff --git a/pyGHDL/lsp/document.py b/pyGHDL/lsp/document.py index dd7f694a1..2656606c6 100644 --- a/pyGHDL/lsp/document.py +++ b/pyGHDL/lsp/document.py @@ -35,9 +35,8 @@ class Document(object): self._tree = nodes.Null_Iir @staticmethod - def load(source, dirname, filename): + def load(src_bytes, dirname, filename): # Write text to file buffer. - src_bytes = source.encode(Document.encoding, "replace") src_len = len(src_bytes) buf_len = src_len + Document.initial_gap_size fileid = name_table.Get_Identifier(filename) diff --git a/pyGHDL/lsp/workspace.py b/pyGHDL/lsp/workspace.py index 54fa17ce6..3b75a6493 100644 --- a/pyGHDL/lsp/workspace.py +++ b/pyGHDL/lsp/workspace.py @@ -96,7 +96,9 @@ class Workspace(object): # We assume the path is correct. path = lsp.path_from_uri(doc_uri) if source is None: - source = open(path).read() + source = open(path, "rb").read() + 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) @@ -152,7 +154,7 @@ class Workspace(object): absname = os.path.join(self._root_path, name) # Create a document for this file. try: - fd = open(absname) + fd = open(absname, "rb") sfe = document.Document.load(fd.read(), self._root_path, name) fd.close() except OSError as err: |