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

Resolve glob errors in cmd #144

Merged
merged 1 commit into from
Jun 8, 2022
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
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

## Unreleased

## 2.9.0

### Fixed

- Fixed glob pattern resolution for command line arguments
([#142](https://github.com/gnikit/fortls/issues/142))

### Changed

- Changed the default value of the following options when a mix the command line
interface and the `json` interface are used. Instead of having the `json` interface
default the values to an empty set it now defaults to the values of the
command line: `excl_paths`, `source_dirs`, `incl_suffixes`, `excl_suffixes`, `include_dirs`
([#143](https://github.com/gnikit/fortls/issues/143))

## 2.8.0

### Added
Expand Down
2 changes: 2 additions & 0 deletions fortls/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def commandline_args(name: str = "fortls") -> argparse.ArgumentParser:
"--incl_suffixes",
type=str,
nargs="*",
default=set(),
action=SetAction,
metavar="SUFFIXES",
help=(
"Consider additional file extensions to the default (default: "
Expand Down
54 changes: 33 additions & 21 deletions fortls/langserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def serve_initialize(self, request: dict):
self.source_dirs.add(self.root_path)

self._load_config_file()
self._resolve_globs_in_paths()
self._config_logger(request)
self._load_intrinsics()
self._add_source_dirs()
Expand Down Expand Up @@ -1529,26 +1530,12 @@ def _load_config_file(self) -> None:
self.post_message(msg)

def _load_config_file_dirs(self, config_dict: dict) -> None:
# Exclude paths (directories & files)
# with glob resolution
for path in config_dict.get("excl_paths", []):
self.excl_paths.update(set(resolve_globs(path, self.root_path)))

# Source directory paths (directories)
# with glob resolution
source_dirs = config_dict.get("source_dirs", [])
for path in source_dirs:
# resolve_globs filters any nonexisting directories so FileNotFoundError
# found inside only_dirs can never be raised
dirs = only_dirs(resolve_globs(path, self.root_path))
self.source_dirs.update(set(dirs))

# Keep all directories present in source_dirs but not excl_paths
self.source_dirs = {i for i in self.source_dirs if i not in self.excl_paths}
self.incl_suffixes = config_dict.get("incl_suffixes", [])
self.excl_paths = set(config_dict.get("excl_paths", self.excl_paths))
self.source_dirs = set(config_dict.get("source_dirs", self.source_dirs))
self.incl_suffixes = set(config_dict.get("incl_suffixes", self.incl_suffixes))
# Update the source file REGEX
self.FORTRAN_SRC_EXT_REGEX = src_file_exts(self.incl_suffixes)
self.excl_suffixes = set(config_dict.get("excl_suffixes", []))
self.excl_suffixes = set(config_dict.get("excl_suffixes", self.excl_suffixes))

def _load_config_file_general(self, config_dict: dict) -> None:
# General options ------------------------------------------------------
Expand Down Expand Up @@ -1607,11 +1594,36 @@ def _load_config_file_preproc(self, config_dict: dict) -> None:
if isinstance(self.pp_defs, list):
self.pp_defs = {key: "" for key in self.pp_defs}

for path in config_dict.get("include_dirs", set()):
self.include_dirs = set(config_dict.get("include_dirs", self.include_dirs))

def _resolve_globs_in_paths(self) -> None:
"""Resolves glob patterns in `excl_paths`, `source_dirs` and `include_dirs`.
Also performs the exclusion of `excl_paths` from `source_dirs`.
"""
# Exclude paths (directories & files) with glob resolution
excl_paths = set()
for path in self.excl_paths:
excl_paths.update(set(resolve_globs(path, self.root_path)))
self.excl_paths = excl_paths.copy()

# Source directory paths (directories) with glob resolution
source_dirs = set()
for path in self.source_dirs:
# resolve_globs filters any nonexisting directories so FileNotFoundError
# found inside only_dirs can never be raised
source_dirs.update(set(only_dirs(resolve_globs(path, self.root_path))))
self.source_dirs = source_dirs.copy()

# Keep all directories present in source_dirs but not excl_paths
self.source_dirs = {i for i in self.source_dirs if i not in self.excl_paths}

# Preprocessor includes
include_dirs = set()
for path in self.include_dirs:
# resolve_globs filters any nonexisting directories so FileNotFoundError
# found inside only_dirs can never be raised
dirs = only_dirs(resolve_globs(path, self.root_path))
self.include_dirs.update(set(dirs))
include_dirs.update(set(only_dirs(resolve_globs(path, self.root_path))))
self.include_dirs = include_dirs.copy()

def _add_source_dirs(self) -> None:
"""Will recursively add all subdirectories that contain Fortran
Expand Down
10 changes: 5 additions & 5 deletions test/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_command_line_file_parsing_options():
" --excl_suffixes _tmp.f90 _h5hut_tests.F90 --excl_paths exclude tests".split()
)
assert args.source_dirs == {"tmp", "./local", "/usr/include/**"}
assert args.incl_suffixes == [".FF", ".fpc", ".h", "f20"]
assert args.incl_suffixes == {".FF", ".fpc", ".h", "f20"}
assert args.excl_suffixes == {"_tmp.f90", "_h5hut_tests.F90"}
assert args.excl_paths == {"exclude", "tests"}

Expand Down Expand Up @@ -109,10 +109,10 @@ def test_config_file_general_options():
def test_config_file_dir_parsing_options():
server, r = unittest_server_init()
# File parsing
assert server.source_dirs == {f'{r/"subdir"}', f'{r/"pp"}', f'{r/"pp"/"include"}'}
assert server.incl_suffixes == [".FF", ".fpc", ".h", "f20"]
assert server.source_dirs == {"pp/**", "subdir"}
assert server.incl_suffixes == {".FF", ".fpc", ".h", "f20"}
assert server.excl_suffixes == {"_tmp.f90", "_h5hut_tests.F90"}
assert server.excl_paths == {f'{r/"excldir"}', f'{r/"hover"}'}
assert server.excl_paths == {"excldir", "hover/**"}


def test_config_file_autocomplete_options():
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_config_file_preprocessor_options():
server, root = unittest_server_init()
# Preprocessor options
assert server.pp_suffixes == [".h", ".fh"]
assert server.include_dirs == {f'{root/"include"}'}
assert server.include_dirs == {"./include/**"}
assert server.pp_defs == {
"HAVE_PETSC": "",
"HAVE_ZOLTAN": "",
Expand Down