Skip to content

Commit 6b47337

Browse files
authored
Merge pull request #138 from gnikit/gnikit/issue137
Gnikit/issue137
2 parents c6a09d3 + 5ec2737 commit 6b47337

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### Added
88

9+
- Added support for comments in the `json` configuration files
10+
([#137](https://github.com/gnikit/fortls/issues/137))
911
- Added `sitemap.xml` to documentation webpage
1012
([#134](https://github.com/gnikit/fortls/pull/134))
1113

fortls/langserver.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# TODO: enable jsonc C-style comments
21
from __future__ import annotations
32

43
import json
@@ -14,6 +13,7 @@
1413
from typing import Pattern
1514
from urllib.error import URLError
1615

16+
import json5
1717
from packaging import version
1818

1919
# Local modules
@@ -1502,12 +1502,7 @@ def _load_config_file(self) -> None:
15021502

15031503
try:
15041504
with open(config_path, "r") as jsonfile:
1505-
# Allow for jsonc C-style commnets
1506-
# jsondata = "".join(
1507-
# line for line in jsonfile if not line.startswith("//")
1508-
# )
1509-
# config_dict = json.loads(jsondata)
1510-
config_dict = json.load(jsonfile)
1505+
config_dict = json5.load(jsonfile)
15111506

15121507
# Include and Exclude directories
15131508
self._load_config_file_dirs(config_dict)
@@ -1530,7 +1525,7 @@ def _load_config_file(self) -> None:
15301525

15311526
# Erroneous json file syntax
15321527
except ValueError as e:
1533-
msg = f"Error: '{e}' while reading '{self.config}' Configuration file"
1528+
msg = f'Error: "{e}" while reading "{self.config}" Configuration file'
15341529
self.post_message(msg)
15351530

15361531
def _load_config_file_dirs(self, config_dict: dict) -> None:

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ project_urls =
3939
packages = find:
4040
python_requires = >= 3.7
4141
install_requires =
42+
json5
4243
packaging
4344
importlib-metadata; python_version < "3.8"
4445
typing-extensions; python_version < "3.8"

test/test_server_messages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def test_config_file_non_existent_options():
2222
ref = {
2323
"type": 1,
2424
"message": (
25-
"Error: 'Expecting ':' delimiter: line 2 column 18 (char 19)' while reading"
26-
" 'wrong_syntax.json' Configuration file"
25+
'Error: "<string>:2 Unexpected "," at column 18" while reading'
26+
' "wrong_syntax.json" Configuration file'
2727
),
2828
}
2929
assert errcode == 0

test/test_source/.fortls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
2+
// Directories to be scanned for source files
23
"source_dirs": [
34
"**/"
45
],
6+
// These are regular expressions, files and paths that can be ignored
57
"excl_paths": [
68
"excldir/**",
79
"./diag/",

0 commit comments

Comments
 (0)