Skip to content

Commit

Permalink
feat: add option to increase the default Python recursion depth
Browse files Browse the repository at this point in the history
Fixes #312
  • Loading branch information
gnikit committed Apr 14, 2024
1 parent c129c17 commit 33cc9ee
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,8 @@

### Added

- Added support for changing the default Python recursion depth
([#312](https://github.com/fortran-lang/fortls/issues/312))
- Added support for preprocessor macro expansions
([#368](https://github.com/fortran-lang/fortls/pull/368))
- Added support for leading white spaces in preprocessor directives
Expand Down
1 change: 1 addition & 0 deletions docs/options.rst
Expand Up @@ -47,6 +47,7 @@ All the ``fortls`` settings with their default arguments can be found below
"nthreads": 4,
"notify_init": false,
"incremental_sync": false,
"recursion_limit": 1000,
"sort_keywords": false,
"disable_autoupdate": false,
"debug_log": false,
Expand Down
7 changes: 7 additions & 0 deletions fortls/interface.py
Expand Up @@ -74,6 +74,13 @@ def cli(name: str = "fortls") -> argparse.ArgumentParser:
action="store_true",
help="Use incremental document synchronization (beta)",
)
parser.add_argument(
"--recursion_limit",
type=int,
default=1000,
metavar="INTEGER",
help="Set the maximum recursion depth for the parser (default: %(default)s)",
)
parser.add_argument(
"--sort_keywords",
action="store_true",
Expand Down
14 changes: 14 additions & 0 deletions fortls/langserver.py
Expand Up @@ -198,6 +198,7 @@ def serve_initialize(self, request: dict):
self.source_dirs.add(self.root_path)

self._load_config_file()
update_recursion_limit(self.recursion_limit)
self._resolve_globs_in_paths()
self._config_logger(request)
self._load_intrinsics()
Expand Down Expand Up @@ -1593,6 +1594,7 @@ def _load_config_file_general(self, config_dict: dict) -> None:
"incremental_sync", self.incremental_sync
)
self.sync_type: int = 2 if self.incremental_sync else 1
self.recursion_limit = config_dict.get("recursion_limit", self.recursion_limit)
self.sort_keywords = config_dict.get("sort_keywords", self.sort_keywords)
self.disable_autoupdate = config_dict.get(
"disable_autoupdate", self.disable_autoupdate
Expand Down Expand Up @@ -1826,6 +1828,18 @@ def _update_version_pypi(self, test: bool = False):
return False


def update_recursion_limit(limit: int) -> None:
"""Update the recursion limit of the Python interpreter
Parameters
----------
limit : int
New recursion limit
"""
if limit != sys.getrecursionlimit():
sys.setrecursionlimit(limit)

Check warning on line 1840 in fortls/langserver.py

View check run for this annotation

Codecov / codecov/patch

fortls/langserver.py#L1840

Added line #L1840 was not covered by tests


class JSONRPC2Error(Exception):
def __init__(self, code, message, data=None):
self.code = code
Expand Down
1 change: 1 addition & 0 deletions test/test_interface.py
Expand Up @@ -104,6 +104,7 @@ def test_config_file_general_options():
assert server.incremental_sync
assert server.sort_keywords
assert server.disable_autoupdate
assert server.recursion_limit == 1500


def test_config_file_dir_parsing_options():
Expand Down
1 change: 1 addition & 0 deletions test/test_source/f90_config.json
Expand Up @@ -2,6 +2,7 @@
"nthreads": 8,
"notify_init": true,
"incremental_sync": true,
"recursion_limit": 1500,
"sort_keywords": true,
"disable_autoupdate": true,

Expand Down

0 comments on commit 33cc9ee

Please sign in to comment.