Skip to content

Commit 4a3587a

Browse files
authored
Merge pull request #185 from gnikit/feat/multiple-configs
feat: adds more default configuration file names
2 parents 433d30d + 490f704 commit 4a3587a

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ If applicable, add screenshots or GIF/MP4 animations to help explain your proble
3939
- the Fortran extension for the code editor and its version [e.g. Modern Fortran v3.0.0] (if applicable)
4040

4141
**Configuration information (please complete the following information):**
42-
- Your `.fortls` configuration file OR any other JSON config being used (if any)
42+
- Your `.fortlsrc` or `.fortls.json` or `.fortls` configuration file OR any other JSON config being used (if any)
4343
- Any settings specified through your extension [e.g. for VS Code settings from `settings.json`]
4444

4545
**Additional context**

CHANGELOG.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
## Unreleased
44

5-
## 2.14.0
5+
## 2.13.0
66

77
### Added
88

9+
- Added additional default configuration file names `.fortlsrc`, `.fortls.json`
10+
([#184](https://github.com/gnikit/fortls/issues/184))
911
- Added coverage testing for multiple Python versions
1012
([#168](https://github.com/gnikit/fortls/pull/178))
11-
12-
## 2.13.0
13-
14-
### Added
15-
1613
- Added pre-commit.ci to `fortls`
1714
([#168](https://github.com/gnikit/fortls/issues/168))
1815

docs/options.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ Configuration using the command line
2525
Configuration using a file
2626
--------------------------
2727

28-
A configuration file is a JSON style file that contains project specific
29-
settings for ``fortls``. By default the name of the filepath is assumed to be
30-
``root_path/.fortls`` but different files can be used through the command line
31-
interface e.g. ``fortls --config my_project.json``.
28+
A configuration file is a JSONC (JSON with comments) file that contains project specific
29+
settings for ``fortls``. By default, the Language Server will recognise 3 default
30+
names ``.fortlsrc``, ``.fortls.json`` and ``.fortls`` (in that order)
31+
under the ``root_path`` of the project, e.g. ``root_path/.fortlsrc``.
32+
A different configuration file name can be passed with the command line
33+
interface options ``--config`` e.g. ``fortls --config my_project.json``.
3234

3335
The settings that can be specified in the configuration file are identical to
3436
the ones available through the command line interface having removed the leading

fortls/interface.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def cli(name: str = "fortls") -> argparse.ArgumentParser:
2626
formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=60),
2727
epilog=(
2828
"All options starting with '--' can also be set in a configuration file, by"
29-
" default named '.fortls' (other names/paths can specified via -c or"
29+
" default named '.fortlsrc', '.fortls.json' or '.fortls'"
30+
" (other names/paths can specified via -c or"
3031
" --config). For more details see our documentation:"
3132
" https://gnikit.github.io/fortls/options.html#available-options"
3233
),
@@ -43,8 +44,11 @@ def cli(name: str = "fortls") -> argparse.ArgumentParser:
4344
"-c",
4445
"--config",
4546
type=str,
46-
default=".fortls",
47-
help="Configuration options file (default file name: %(default)s)",
47+
default=".fortlsrc",
48+
help=(
49+
"Configuration options file (default file name: %(default)s, other"
50+
" default supported names: .fortls.json, .fortls)"
51+
),
4852
)
4953
parser.add_argument(
5054
"-n",

fortls/langserver.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,16 +1492,21 @@ def serve_default(self, request: dict):
14921492
def _load_config_file(self) -> None:
14931493
"""Loads the configuration file for the Language Server"""
14941494

1495-
# Check for config file
1496-
config_path = os.path.join(self.root_path, self.config)
1497-
# NOTE: it would be better if we could distinguish between a user-defined
1498-
# and a default config file. If not user-defined then we can check for
1499-
# default names, currently only .fortls. If None are found return None
1500-
# if user-defined config we would want to throw an error if the file
1501-
# cannot be found
1502-
if not os.path.isfile(config_path):
1495+
# Check for config files
1496+
default_conf_files = [self.config, ".fortlsrc", ".fortls.json", ".fortls"]
1497+
present_conf_files = [
1498+
os.path.isfile(os.path.join(self.root_path, f)) for f in default_conf_files
1499+
]
1500+
if not any(present_conf_files):
15031501
return None
15041502

1503+
# Load the first config file found
1504+
for f, present in zip(default_conf_files, present_conf_files):
1505+
if not present:
1506+
continue
1507+
config_path = os.path.join(self.root_path, f)
1508+
break
1509+
15051510
try:
15061511
with open(config_path, "r") as jsonfile:
15071512
config_dict = json5.load(jsonfile)

0 commit comments

Comments
 (0)