Skip to content

Commit 33cc9ee

Browse files
committed
feat: add option to increase the default Python recursion depth
Fixes #312
1 parent c129c17 commit 33cc9ee

File tree

6 files changed

+26
-0
lines changed

6 files changed

+26
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### Added
88

9+
- Added support for changing the default Python recursion depth
10+
([#312](https://github.com/fortran-lang/fortls/issues/312))
911
- Added support for preprocessor macro expansions
1012
([#368](https://github.com/fortran-lang/fortls/pull/368))
1113
- Added support for leading white spaces in preprocessor directives

docs/options.rst

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ All the ``fortls`` settings with their default arguments can be found below
4747
"nthreads": 4,
4848
"notify_init": false,
4949
"incremental_sync": false,
50+
"recursion_limit": 1000,
5051
"sort_keywords": false,
5152
"disable_autoupdate": false,
5253
"debug_log": false,

fortls/interface.py

+7
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ def cli(name: str = "fortls") -> argparse.ArgumentParser:
7474
action="store_true",
7575
help="Use incremental document synchronization (beta)",
7676
)
77+
parser.add_argument(
78+
"--recursion_limit",
79+
type=int,
80+
default=1000,
81+
metavar="INTEGER",
82+
help="Set the maximum recursion depth for the parser (default: %(default)s)",
83+
)
7784
parser.add_argument(
7885
"--sort_keywords",
7986
action="store_true",

fortls/langserver.py

+14
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ def serve_initialize(self, request: dict):
198198
self.source_dirs.add(self.root_path)
199199

200200
self._load_config_file()
201+
update_recursion_limit(self.recursion_limit)
201202
self._resolve_globs_in_paths()
202203
self._config_logger(request)
203204
self._load_intrinsics()
@@ -1593,6 +1594,7 @@ def _load_config_file_general(self, config_dict: dict) -> None:
15931594
"incremental_sync", self.incremental_sync
15941595
)
15951596
self.sync_type: int = 2 if self.incremental_sync else 1
1597+
self.recursion_limit = config_dict.get("recursion_limit", self.recursion_limit)
15961598
self.sort_keywords = config_dict.get("sort_keywords", self.sort_keywords)
15971599
self.disable_autoupdate = config_dict.get(
15981600
"disable_autoupdate", self.disable_autoupdate
@@ -1826,6 +1828,18 @@ def _update_version_pypi(self, test: bool = False):
18261828
return False
18271829

18281830

1831+
def update_recursion_limit(limit: int) -> None:
1832+
"""Update the recursion limit of the Python interpreter
1833+
1834+
Parameters
1835+
----------
1836+
limit : int
1837+
New recursion limit
1838+
"""
1839+
if limit != sys.getrecursionlimit():
1840+
sys.setrecursionlimit(limit)
1841+
1842+
18291843
class JSONRPC2Error(Exception):
18301844
def __init__(self, code, message, data=None):
18311845
self.code = code

test/test_interface.py

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def test_config_file_general_options():
104104
assert server.incremental_sync
105105
assert server.sort_keywords
106106
assert server.disable_autoupdate
107+
assert server.recursion_limit == 1500
107108

108109

109110
def test_config_file_dir_parsing_options():

test/test_source/f90_config.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"nthreads": 8,
33
"notify_init": true,
44
"incremental_sync": true,
5+
"recursion_limit": 1500,
56
"sort_keywords": true,
67
"disable_autoupdate": true,
78

0 commit comments

Comments
 (0)