Skip to content

Commit

Permalink
Merge pull request #138 from gnikit/gnikit/issue137
Browse files Browse the repository at this point in the history
Gnikit/issue137
  • Loading branch information
gnikit authored May 31, 2022
2 parents c6a09d3 + 5ec2737 commit 6b47337
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
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 comments in the `json` configuration files
([#137](https://github.com/gnikit/fortls/issues/137))
- Added `sitemap.xml` to documentation webpage
([#134](https://github.com/gnikit/fortls/pull/134))

Expand Down
11 changes: 3 additions & 8 deletions fortls/langserver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# TODO: enable jsonc C-style comments
from __future__ import annotations

import json
Expand All @@ -14,6 +13,7 @@
from typing import Pattern
from urllib.error import URLError

import json5
from packaging import version

# Local modules
Expand Down Expand Up @@ -1502,12 +1502,7 @@ def _load_config_file(self) -> None:

try:
with open(config_path, "r") as jsonfile:
# Allow for jsonc C-style commnets
# jsondata = "".join(
# line for line in jsonfile if not line.startswith("//")
# )
# config_dict = json.loads(jsondata)
config_dict = json.load(jsonfile)
config_dict = json5.load(jsonfile)

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

# Erroneous json file syntax
except ValueError as e:
msg = f"Error: '{e}' while reading '{self.config}' Configuration file"
msg = f'Error: "{e}" while reading "{self.config}" Configuration file'
self.post_message(msg)

def _load_config_file_dirs(self, config_dict: dict) -> None:
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ project_urls =
packages = find:
python_requires = >= 3.7
install_requires =
json5
packaging
importlib-metadata; python_version < "3.8"
typing-extensions; python_version < "3.8"
Expand Down
4 changes: 2 additions & 2 deletions test/test_server_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def test_config_file_non_existent_options():
ref = {
"type": 1,
"message": (
"Error: 'Expecting ':' delimiter: line 2 column 18 (char 19)' while reading"
" 'wrong_syntax.json' Configuration file"
'Error: "<string>:2 Unexpected "," at column 18" while reading'
' "wrong_syntax.json" Configuration file'
),
}
assert errcode == 0
Expand Down
2 changes: 2 additions & 0 deletions test/test_source/.fortls
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
// Directories to be scanned for source files
"source_dirs": [
"**/"
],
// These are regular expressions, files and paths that can be ignored
"excl_paths": [
"excldir/**",
"./diag/",
Expand Down

0 comments on commit 6b47337

Please sign in to comment.