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

Bug/lsp-messages #136

Merged
merged 5 commits into from
May 31, 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
- Added `sitemap.xml` to documentation webpage
([#134](https://github.com/gnikit/fortls/pull/134))

### Fixed

- Fixed bug where error messages did not post correctly
([#135](https://github.com/gnikit/fortls/issues/135))

## 2.7.0

### Added
Expand Down
3 changes: 2 additions & 1 deletion fortls/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ def get_line_prefix(


def resolve_globs(glob_path: str, root_path: str = None) -> list[str]:
"""Resolve paths (absolute and relative) and glob patterns
"""Resolve paths (absolute and relative) and glob patterns while
nonexistent paths are ignored

Parameters
----------
Expand Down
41 changes: 20 additions & 21 deletions fortls/langserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,11 @@ def _load_config_file(self) -> None:

# Check for config file
config_path = os.path.join(self.root_path, self.config)
# NOTE: it would be better if we could distinguish between a user-defined
# and a default config file. If not user-defined then we can check for
# default names, currently only .fortls. If None are found return None
# if user-defined config we would want to throw an error if the file
# cannot be found
if not os.path.isfile(config_path):
return None

Expand Down Expand Up @@ -1521,14 +1526,12 @@ def _load_config_file(self) -> None:
self.debug_log = True

except FileNotFoundError:
self.post_messages(
[Severity.error, f"Error settings file '{self.config}' not found"]
)
self.post_message(f"Configuration file '{self.config}' not found")

except ValueError:
self.post_messages(
[Severity.error, f"Error while parsing '{self.config}' settings file"]
)
# Erroneous json file syntax
except ValueError as e:
msg = f"Error: '{e}' while reading '{self.config}' Configuration file"
self.post_message(msg)

def _load_config_file_dirs(self, config_dict: dict) -> None:
# Exclude paths (directories & files)
Expand All @@ -1540,12 +1543,10 @@ def _load_config_file_dirs(self, config_dict: dict) -> None:
# with glob resolution
source_dirs = config_dict.get("source_dirs", [])
for path in source_dirs:
try:
dirs = only_dirs(resolve_globs(path, self.root_path))
self.source_dirs.update(set(dirs))
except FileNotFoundError as e:
err = f"Directories input in Configuration file do not exit:\n{e}"
self.post_messages([Severity.warn, err])
# 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}
Expand Down Expand Up @@ -1606,18 +1607,16 @@ def _load_config_file_general(self, config_dict: dict) -> None:
)

def _load_config_file_preproc(self, config_dict: dict) -> None:
self.pp_suffixes = config_dict.get("pp_suffixes", None) # TODO: set def
self.pp_defs = config_dict.get("pp_defs", {}) # TODO: set other dif?
self.pp_suffixes = config_dict.get("pp_suffixes", None)
self.pp_defs = config_dict.get("pp_defs", {})
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()):
try:
dirs = only_dirs(resolve_globs(path, self.root_path))
self.include_dirs.update(set(dirs))
except FileNotFoundError as e:
err = f"Directories input in Configuration file do not exit:\n{e}"
self.post_messages([Severity.warn, err])
# 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))

def _add_source_dirs(self) -> None:
"""Will recursively add all subdirectories that contain Fortran
Expand Down
30 changes: 30 additions & 0 deletions test/test_server_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from setup_tests import run_request, test_dir, write_rpc_request


def check_msg(ref, res):
assert ref["type"] == res["type"]
assert ref["message"] == res["message"]


# def test_config_file_non_existent():
# string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
# errcode, results = run_request(string, ["-c", "fake.json"])
#
# ref = {"type": 1, "message": "Configuration file 'fake.json' not found"}
# assert errcode == 0
# check_msg(ref, results[0])


def test_config_file_non_existent_options():
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
errcode, results = run_request(string, ["-c", "wrong_syntax.json"])

ref = {
"type": 1,
"message": (
"Error: 'Expecting ':' delimiter: line 2 column 18 (char 19)' while reading"
" 'wrong_syntax.json' Configuration file"
),
}
assert errcode == 0
check_msg(ref, results[0])
3 changes: 3 additions & 0 deletions test/test_source/wrong_syntax.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"source_dirs", "s"
}