Skip to content

Commit c6a09d3

Browse files
authored
Merge pull request #136 from gnikit/bug/lsp-messages
Bug/lsp-messages
2 parents cbc6892 + f26ad73 commit c6a09d3

File tree

5 files changed

+60
-22
lines changed

5 files changed

+60
-22
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
- Added `sitemap.xml` to documentation webpage
1010
([#134](https://github.com/gnikit/fortls/pull/134))
1111

12+
### Fixed
13+
14+
- Fixed bug where error messages did not post correctly
15+
([#135](https://github.com/gnikit/fortls/issues/135))
16+
1217
## 2.7.0
1318

1419
### Added

fortls/helper_functions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ def get_line_prefix(
297297

298298

299299
def resolve_globs(glob_path: str, root_path: str = None) -> list[str]:
300-
"""Resolve paths (absolute and relative) and glob patterns
300+
"""Resolve paths (absolute and relative) and glob patterns while
301+
nonexistent paths are ignored
301302
302303
Parameters
303304
----------

fortls/langserver.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,11 @@ def _load_config_file(self) -> None:
14921492

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

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

15231528
except FileNotFoundError:
1524-
self.post_messages(
1525-
[Severity.error, f"Error settings file '{self.config}' not found"]
1526-
)
1529+
self.post_message(f"Configuration file '{self.config}' not found")
15271530

1528-
except ValueError:
1529-
self.post_messages(
1530-
[Severity.error, f"Error while parsing '{self.config}' settings file"]
1531-
)
1531+
# Erroneous json file syntax
1532+
except ValueError as e:
1533+
msg = f"Error: '{e}' while reading '{self.config}' Configuration file"
1534+
self.post_message(msg)
15321535

15331536
def _load_config_file_dirs(self, config_dict: dict) -> None:
15341537
# Exclude paths (directories & files)
@@ -1540,12 +1543,10 @@ def _load_config_file_dirs(self, config_dict: dict) -> None:
15401543
# with glob resolution
15411544
source_dirs = config_dict.get("source_dirs", [])
15421545
for path in source_dirs:
1543-
try:
1544-
dirs = only_dirs(resolve_globs(path, self.root_path))
1545-
self.source_dirs.update(set(dirs))
1546-
except FileNotFoundError as e:
1547-
err = f"Directories input in Configuration file do not exit:\n{e}"
1548-
self.post_messages([Severity.warn, err])
1546+
# resolve_globs filters any nonexisting directories so FileNotFoundError
1547+
# found inside only_dirs can never be raised
1548+
dirs = only_dirs(resolve_globs(path, self.root_path))
1549+
self.source_dirs.update(set(dirs))
15491550

15501551
# Keep all directories present in source_dirs but not excl_paths
15511552
self.source_dirs = {i for i in self.source_dirs if i not in self.excl_paths}
@@ -1606,18 +1607,16 @@ def _load_config_file_general(self, config_dict: dict) -> None:
16061607
)
16071608

16081609
def _load_config_file_preproc(self, config_dict: dict) -> None:
1609-
self.pp_suffixes = config_dict.get("pp_suffixes", None) # TODO: set def
1610-
self.pp_defs = config_dict.get("pp_defs", {}) # TODO: set other dif?
1610+
self.pp_suffixes = config_dict.get("pp_suffixes", None)
1611+
self.pp_defs = config_dict.get("pp_defs", {})
16111612
if isinstance(self.pp_defs, list):
16121613
self.pp_defs = {key: "" for key in self.pp_defs}
16131614

16141615
for path in config_dict.get("include_dirs", set()):
1615-
try:
1616-
dirs = only_dirs(resolve_globs(path, self.root_path))
1617-
self.include_dirs.update(set(dirs))
1618-
except FileNotFoundError as e:
1619-
err = f"Directories input in Configuration file do not exit:\n{e}"
1620-
self.post_messages([Severity.warn, err])
1616+
# resolve_globs filters any nonexisting directories so FileNotFoundError
1617+
# found inside only_dirs can never be raised
1618+
dirs = only_dirs(resolve_globs(path, self.root_path))
1619+
self.include_dirs.update(set(dirs))
16211620

16221621
def _add_source_dirs(self) -> None:
16231622
"""Will recursively add all subdirectories that contain Fortran

test/test_server_messages.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from setup_tests import run_request, test_dir, write_rpc_request
2+
3+
4+
def check_msg(ref, res):
5+
assert ref["type"] == res["type"]
6+
assert ref["message"] == res["message"]
7+
8+
9+
# def test_config_file_non_existent():
10+
# string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
11+
# errcode, results = run_request(string, ["-c", "fake.json"])
12+
#
13+
# ref = {"type": 1, "message": "Configuration file 'fake.json' not found"}
14+
# assert errcode == 0
15+
# check_msg(ref, results[0])
16+
17+
18+
def test_config_file_non_existent_options():
19+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
20+
errcode, results = run_request(string, ["-c", "wrong_syntax.json"])
21+
22+
ref = {
23+
"type": 1,
24+
"message": (
25+
"Error: 'Expecting ':' delimiter: line 2 column 18 (char 19)' while reading"
26+
" 'wrong_syntax.json' Configuration file"
27+
),
28+
}
29+
assert errcode == 0
30+
check_msg(ref, results[0])

test/test_source/wrong_syntax.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"source_dirs", "s"
3+
}

0 commit comments

Comments
 (0)