Skip to content

Commit 75a3cca

Browse files
ali-ghanbariAli Ghanbari
andauthored
added physical-to-logical path mapping command-line option (#57)
--------- Co-authored-by: Ali Ghanbari <[email protected]>
1 parent 35ebaaa commit 75a3cca

File tree

3 files changed

+64
-12
lines changed

3 files changed

+64
-12
lines changed

coqpyt/coq/base_file.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import uuid
44
import tempfile
55
from copy import deepcopy
6-
from typing import Optional, List
6+
from typing import Optional, List, Tuple
77

88
from coqpyt.lsp.structs import (
99
TextDocumentItem,
@@ -43,6 +43,7 @@ def __init__(
4343
timeout: int = 30,
4444
workspace: Optional[str] = None,
4545
coq_lsp: str = "coq-lsp",
46+
coq_lsp_options: Tuple[str] = None,
4647
coqtop: str = "coqtop",
4748
):
4849
"""Creates a CoqFile.
@@ -67,7 +68,9 @@ def __init__(
6768
uri = f"file://{workspace}"
6869
else:
6970
uri = f"file://{self._path}"
70-
self.coq_lsp_client = CoqLspClient(uri, timeout=timeout, coq_lsp=coq_lsp)
71+
self.coq_lsp_client = CoqLspClient(
72+
uri, timeout=timeout, coq_lsp_options=coq_lsp_options, coq_lsp=coq_lsp
73+
)
7174
uri = f"file://{self._path}"
7275
text = self.__read()
7376

coqpyt/coq/lsp/client.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(
3131
timeout: int = 30,
3232
memory_limit: int = 2097152,
3333
coq_lsp: str = "coq-lsp",
34-
coq_lsp_options: str = "-D 0",
34+
coq_lsp_options: Tuple[str] = None,
3535
init_options: Dict = __DEFAULT_INIT_OPTIONS,
3636
):
3737
"""Creates a CoqLspClient
@@ -63,9 +63,21 @@ def __init__(
6363
self.file_progress: Dict[str, List[CoqFileProgressParams]] = {}
6464

6565
if sys.platform.startswith("linux"):
66-
command = f"ulimit -v {memory_limit}; {coq_lsp} {coq_lsp_options}"
66+
command = f"ulimit -v {memory_limit}; {coq_lsp}"
6767
else:
68-
command = f"{coq_lsp} {coq_lsp_options}"
68+
command = f"{coq_lsp}"
69+
70+
if coq_lsp_options is None:
71+
command += " -D 0"
72+
else:
73+
hasDOption = False
74+
for option in coq_lsp_options:
75+
if option.startswith("-D"):
76+
hasDOption = True
77+
break
78+
if not hasDOption:
79+
command += " -D 0"
80+
command += " " + " ".join(coq_lsp_options)
6981

7082
proc = subprocess.Popen(
7183
command,

coqpyt/coq/proof_file.py

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class _AuxFile(object):
3131
def __init__(
3232
self,
3333
file_path,
34+
coq_lsp_options: Tuple[str],
3435
copy: bool = False,
3536
workspace: Optional[str] = None,
3637
timeout: int = 30,
@@ -41,7 +42,9 @@ def __init__(
4142
uri = f"file://{workspace}"
4243
else:
4344
uri = f"file://{self.path}"
44-
self.coq_lsp_client = CoqLspClient(uri, timeout=timeout)
45+
self.coq_lsp_client = CoqLspClient(
46+
uri, coq_lsp_options=coq_lsp_options, timeout=timeout
47+
)
4548

4649
def __enter__(self):
4750
return self
@@ -167,11 +170,16 @@ def __load_library(
167170
library_file: str,
168171
library_hash: str,
169172
timeout: int,
173+
coq_lsp_options: Tuple[str] = None,
170174
workspace: Optional[str] = None,
171175
):
172176
# NOTE: the library_hash attribute is only used for the LRU cache
173177
coq_file = CoqFile(
174-
library_file, workspace=workspace, library=library_name, timeout=timeout
178+
library_file,
179+
workspace=workspace,
180+
coq_lsp_options=coq_lsp_options,
181+
library=library_name,
182+
timeout=timeout,
175183
)
176184
coq_file.run()
177185
context = coq_file.context
@@ -221,6 +229,7 @@ def get_library(
221229
library_name: str,
222230
library_file: str,
223231
timeout: int,
232+
coq_lsp_options: Tuple[str],
224233
workspace: Optional[str] = None,
225234
use_disk_cache: bool = False,
226235
) -> Dict[str, Term]:
@@ -232,7 +241,12 @@ def get_library(
232241
if cached_library is not None:
233242
return cached_library
234243
aux_context = _AuxFile.__load_library(
235-
library_name, library_file, library_hash, timeout, workspace=workspace
244+
library_name,
245+
library_file,
246+
library_hash,
247+
timeout,
248+
coq_lsp_options,
249+
workspace=workspace,
236250
)
237251
# FIXME: we ignore the usage of "Local" from imported files to
238252
# simplify the implementation. However, they can be used:
@@ -260,13 +274,18 @@ def get_libraries(aux_file: "_AuxFile") -> List[str]:
260274

261275
@staticmethod
262276
def get_coq_context(
263-
timeout: int, workspace: Optional[str] = None, use_disk_cache: bool = False
277+
timeout: int,
278+
workspace: Optional[str] = None,
279+
use_disk_cache: bool = False,
280+
coq_lsp_options: Tuple[str] = None,
264281
) -> FileContext:
265282
temp_path = os.path.join(
266283
tempfile.gettempdir(), "aux_" + str(uuid.uuid4()).replace("-", "") + ".v"
267284
)
268285

269-
with _AuxFile(file_path=temp_path, timeout=timeout) as aux_file:
286+
with _AuxFile(
287+
file_path=temp_path, coq_lsp_options=coq_lsp_options, timeout=timeout
288+
) as aux_file:
270289
aux_file.didOpen()
271290
libraries = _AuxFile.get_libraries(aux_file)
272291
for library in libraries:
@@ -284,6 +303,7 @@ def get_coq_context(
284303
timeout,
285304
workspace=workspace,
286305
use_disk_cache=use_disk_cache,
306+
coq_lsp_options=coq_lsp_options,
287307
)
288308
context.add_library(library, terms)
289309

@@ -304,6 +324,7 @@ def __init__(
304324
timeout: int = 30,
305325
workspace: Optional[str] = None,
306326
coq_lsp: str = "coq-lsp",
327+
coq_lsp_options: Tuple[str] = None,
307328
coqtop: str = "coqtop",
308329
error_mode: str = "strict",
309330
use_disk_cache: bool = False,
@@ -333,18 +354,33 @@ def __init__(
333354
"""
334355
if not os.path.isabs(file_path):
335356
file_path = os.path.abspath(file_path)
336-
super().__init__(file_path, library, timeout, workspace, coq_lsp, coqtop)
337-
self.__aux_file = _AuxFile(file_path, timeout=self.timeout, workspace=workspace)
357+
super().__init__(
358+
file_path,
359+
library=library,
360+
timeout=timeout,
361+
workspace=workspace,
362+
coq_lsp=coq_lsp,
363+
coqtop=coqtop,
364+
coq_lsp_options=coq_lsp_options,
365+
)
366+
self.__aux_file = _AuxFile(
367+
file_path,
368+
timeout=self.timeout,
369+
coq_lsp_options=coq_lsp_options,
370+
workspace=workspace,
371+
)
338372
self.__error_mode = error_mode
339373
self.__use_disk_cache = use_disk_cache
340374
self.__aux_file.didOpen()
375+
self.__coq_lsp_options = coq_lsp_options
341376

342377
try:
343378
# We need to update the context already defined in the CoqFile
344379
self.context.update(
345380
_AuxFile.get_coq_context(
346381
self.timeout,
347382
workspace=self.workspace,
383+
coq_lsp_options=coq_lsp_options,
348384
use_disk_cache=self.__use_disk_cache,
349385
)
350386
)
@@ -612,6 +648,7 @@ def __update_libraries(self):
612648
library,
613649
library_file,
614650
self.timeout,
651+
self.__coq_lsp_options,
615652
workspace=self.workspace,
616653
use_disk_cache=self.__use_disk_cache,
617654
)

0 commit comments

Comments
 (0)