Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to increase the default Python recursion depth #373

Merged
merged 2 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
6 changes: 6 additions & 0 deletions fortls/fortls.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
"default": false,
"type": "boolean"
},
"recursion_limit": {
"title": "Recursion Limit",
"description": "Set the maximum recursion depth for the parser (default: 1000)",
"default": 1000,
"type": "integer"
},
"sort_keywords": {
"title": "Sort Keywords",
"description": "Display variable keywords information, function/subroutine definitions, etc. in a consistent (sorted) manner default: no sorting, display code as is)",
Expand Down
7 changes: 7 additions & 0 deletions fortls/interface.py
Original file line number Diff line number Diff line change
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
18 changes: 18 additions & 0 deletions fortls/langserver.py
Original file line number Diff line number Diff line change
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,22 @@ 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

Examples
--------
>>> update_recursion_limit(10000)
"""
if limit != sys.getrecursionlimit():
sys.setrecursionlimit(limit)


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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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