Skip to content

Commit c986bb4

Browse files
authored
Merge pull request #110 from gnikit/gnikit/issue106
Gnikit/issue106
2 parents c7c3a76 + 50b370d commit c986bb4

37 files changed

+133
-80
lines changed

.coveragerc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[run]
22
dynamic_context = test_function
3-
omit =
3+
omit =
44
fortls/__init__.py
55
fortls/version.py
66

@@ -9,4 +9,4 @@ exclude_lines =
99
if debug:
1010
log.debug
1111
except:
12-
if not PY3K:
12+
if not PY3K:

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*.pyc
22
.vscode
3-
*.egg-info
3+
*.egg-info
44
dist/
55
build/
66
docs/_build/
@@ -14,4 +14,4 @@ fortls/_version.py
1414
*.smod
1515
*.log
1616

17-
.coverage
17+
.coverage

.pre-commit-config.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.2.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files
11+
- repo: https://gitlab.com/pycqa/flake8
12+
rev: 3.9.2
13+
hooks:
14+
- id: flake8
15+
- repo: https://github.com/asottile/pyupgrade
16+
rev: v2.32.1
17+
hooks:
18+
- id: pyupgrade
19+
- repo: https://github.com/pycqa/isort
20+
rev: 5.10.1
21+
hooks:
22+
- id: isort
23+
name: isort (python)
24+
- repo: https://github.com/psf/black
25+
rev: 22.3.0
26+
hooks:
27+
- id: black

CHANGELOG.md

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

77
### Added
88

9+
- Added `pre-commit` hook to the project
10+
([#106](https://github.com/gnikit/fortls/issues/106))
911
- Added Code of Conduct
1012
- Added basic support for hovering over `ASSOCIATE` blocks
1113
([#62](https://github.com/gnikit/fortls/issues/62))
1214

15+
### Changed
16+
17+
- Formatted all files with `pre-commit`
18+
1319
## 2.3.1
1420

1521
### Fixed

CONTRIBUTING.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,36 @@ To verify that your cloning of the GitHub repository work as expected open a ter
3838
```sh
3939
pytest -v
4040
```
41+
4142
This will run the entire unit test suite. You can also run this to verify that you haven't broken anything in the code.
4243

43-
👉 **Tip!** You can run individual tests by selecting the path to the Python file and the method
44+
👉 **Tip!** You can run individual tests by selecting the path to the Python file and the method
45+
4446
```sh
4547
pytest test/test_interface.py::test_version_update_pypi
4648
```
4749

4850
### Developing & Debugging 🐞️
4951

52+
❗️ Before you start developing, open a terminal inside `fortls` and run:
53+
54+
```sh
55+
pre-commit install
56+
```
57+
58+
This will ensure that all you commits meet the formatting standards of the project.
59+
60+
----
61+
5062
You can now start writing code! Your local `fortls` version will be updated with every code change you make, so you can use your normal code editor to checkout the `fortls` features that you have implemented.
5163
It is however considerably easier to create compact unittests to check if your changes have worked.
5264

5365
A `fortls` test normally involves writing a Python function which sends a JSONRPC request to the server and then test checks for the correct server response.
5466
Often times small bits of Fortran source code also have to be submited to be used by the test.
5567
You can find varisous test examples in the `tests` directory.
5668

57-
5869
👉 **Tip!** You can attach a debugger to the main `fortls` source code during unittesting which should allow you to pause, break, step into, etc. while testing, thus making it easier to find mistakes.
5970

60-
6171
### Merging
6272

6373
To merge your changes to the main `fortls` repository push your branch on GitHub and open a [Pull Request](https://github.com/gnikit/fortls/pulls). Ping `@gnikit` to review your PR.

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
SPHINXOPTS ?=
77
SPHINXBUILD ?= sphinx-build
88
SPHINXAPIDOC ?= sphinx-apidoc
9-
PANDOC ?= pandoc
9+
PANDOC ?= pandoc
1010
SOURCEDIR = .
1111
BUILDDIR = _build
1212

docs/editor_integration.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,3 @@ Edit your kakrc config to enable kak-lsp, adding fortran as a filetype:
120120
hook global WinSetOption filetype=(fortran) %{
121121
lsp-enable-window
122122
}
123-
124-

docs/options.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ incl_suffixes
108108
.F .f .F03 .f03 .F05 .f05 .F08 .f08 .F18 .f18 .F77 .f77 .F90 .f90 .F95 .f95 .FOR .for .FPP .fpp.
109109
Additional source file extensions can be defined in ``incl_suffixes``.
110110

111-
.. note:: The default file extensions cannot be overwritten. ``incl_suffixes`` will only append to the default extensions.
111+
.. note:: The default file extensions cannot be overwritten. ``incl_suffixes`` will only append to the default extensions.
112112

113113

114114
excl_suffixes
@@ -187,7 +187,7 @@ pp_defs
187187
}
188188
}
189189
190-
Additional **preprocessor definitions** from what are specified in files found in
190+
Additional **preprocessor definitions** from what are specified in files found in
191191
``include_dirs`` can be defined in ``pp_defs``.
192192

193193
.. note:: Definitions in ``pp_defs`` will override definitions from ``include_dirs``

fortls/__init__.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@ def debug_server_general(args, settings):
8686
"Specified 'debug_rootpath' does not exist or is not a directory"
8787
)
8888
print('\nTesting "initialize" request:')
89-
print(' Root = "{0}"'.format(args.debug_rootpath))
89+
print(' Root = "{}"'.format(args.debug_rootpath))
9090
s.serve_initialize({"params": {"rootPath": args.debug_rootpath}})
9191
if len(s.post_messages) == 0:
9292
print(" Successful!")
9393
else:
9494
print(" Successful with errors:")
9595
for message in s.post_messages:
96-
print(" {0}".format(message[1]))
96+
print(" {}".format(message[1]))
9797
# Print module directories
9898
print("\n Source directories:")
9999
for source_dir in s.source_dirs:
100-
print(" {0}".format(source_dir))
100+
print(" {}".format(source_dir))
101101
#
102102
if args.debug_diagnostics:
103103
print('\nTesting "textDocument/publishDiagnostics" notification:')
@@ -117,7 +117,7 @@ def debug_server_general(args, settings):
117117
sline = diag["range"]["start"]["line"]
118118
message = diag["message"]
119119
sev = sev_map[diag["severity"] - 1]
120-
print(' {0:5d}:{1} "{2}"'.format(sline, sev, message))
120+
print(' {:5d}:{} "{}"'.format(sline, sev, message))
121121
#
122122
if args.debug_symbols:
123123
print('\nTesting "textDocument/documentSymbol" request:')
@@ -192,7 +192,7 @@ def debug_server_general(args, settings):
192192
else:
193193
for obj in completion_results:
194194
print(
195-
" {0}: {1} -> {2}".format(
195+
" {}: {} -> {}".format(
196196
obj["kind"], obj["label"], obj["detail"]
197197
)
198198
)
@@ -220,11 +220,11 @@ def debug_server_general(args, settings):
220220
print(json.dumps(signature_results, indent=2))
221221
else:
222222
active_param = signature_results.get("activeParameter", 0)
223-
print(" Active param = {0}".format(active_param))
223+
print(" Active param = {}".format(active_param))
224224
active_signature = signature_results.get("activeSignature", 0)
225-
print(" Active sig = {0}".format(active_signature))
225+
print(" Active sig = {}".format(active_signature))
226226
for i, signature in enumerate(signature_results["signatures"]):
227-
print(" {0}".format(signature["label"]))
227+
print(" {}".format(signature["label"]))
228228
for j, obj in enumerate(signature["parameters"]):
229229
if (i == active_signature) and (j == active_param):
230230
active_mark = "*"
@@ -278,14 +278,14 @@ def debug_server_general(args, settings):
278278
if args.debug_full_result:
279279
print(json.dumps(definition_results, indent=2))
280280
else:
281-
print(' URI = "{0}"'.format(definition_results["uri"]))
281+
print(' URI = "{}"'.format(definition_results["uri"]))
282282
print(
283-
" Line = {0}".format(
283+
" Line = {}".format(
284284
definition_results["range"]["start"]["line"] + 1
285285
)
286286
)
287287
print(
288-
" Char = {0}".format(
288+
" Char = {}".format(
289289
definition_results["range"]["start"]["character"] + 1
290290
)
291291
)
@@ -345,7 +345,7 @@ def debug_server_general(args, settings):
345345
print("=======")
346346
for result in ref_results:
347347
print(
348-
" {0} ({1}, {2})".format(
348+
" {} ({}, {})".format(
349349
result["uri"],
350350
result["range"]["start"]["line"] + 1,
351351
result["range"]["start"]["character"] + 1,
@@ -379,7 +379,7 @@ def debug_server_general(args, settings):
379379
print("=======")
380380
for uri, result in ref_results["changes"].items():
381381
path = path_from_uri(uri)
382-
print('File: "{0}"'.format(path))
382+
print('File: "{}"'.format(path))
383383
file_obj = s.workspace.get(path)
384384
if file_obj is not None:
385385
file_contents = file_obj.contents_split
@@ -388,22 +388,22 @@ def debug_server_general(args, settings):
388388
end_line = change["range"]["end"]["line"]
389389
start_col = change["range"]["start"]["character"]
390390
end_col = change["range"]["end"]["character"]
391-
print(" {0}, {1}".format(start_line + 1, end_line + 1))
391+
print(" {}, {}".format(start_line + 1, end_line + 1))
392392
new_contents = []
393393
for i in range(start_line, end_line + 1):
394394
line = file_contents[i]
395-
print(" - {0}".format(line))
395+
print(" - {}".format(line))
396396
if i == start_line:
397397
new_contents.append(
398398
line[:start_col] + change["newText"]
399399
)
400400
if i == end_line:
401401
new_contents[-1] += line[end_col:]
402402
for line in new_contents:
403-
print(" + {0}".format(line))
403+
print(" + {}".format(line))
404404
print()
405405
else:
406-
print('Unknown file: "{0}"'.format(path))
406+
print('Unknown file: "{}"'.format(path))
407407
print("=======")
408408
#
409409
if args.debug_actions:
@@ -434,12 +434,10 @@ def debug_server_general(args, settings):
434434
else:
435435
for result in action_results:
436436
print(
437-
"Kind = '{0}', Title = '{1}'".format(
438-
result["kind"], result["title"]
439-
)
437+
"Kind = '{}', Title = '{}'".format(result["kind"], result["title"])
440438
)
441439
for editUri, editChange in result["edit"]["changes"].items():
442-
print("\nChange: URI = '{0}'".format(editUri))
440+
print("\nChange: URI = '{}'".format(editUri))
443441
pp.pprint(editChange)
444442
print()
445443
tmpout.close()
@@ -485,7 +483,7 @@ def debug_server_parser(args):
485483
print(f"Error while parsing '{args.config}' settings file")
486484
#
487485
print("\nTesting parser")
488-
print(' File = "{0}"'.format(args.debug_filepath))
486+
print(' File = "{}"'.format(args.debug_filepath))
489487
file_obj = fortran_file(args.debug_filepath, pp_suffixes)
490488
err_str, _ = file_obj.load_from_disk()
491489
if err_str:
@@ -495,11 +493,11 @@ def debug_server_parser(args):
495493
file_ast = file_obj.parse(debug=True, pp_defs=pp_defs, include_dirs=include_dirs)
496494
print("\n=========\nObject Tree\n=========\n")
497495
for obj in file_ast.get_scopes():
498-
print("{0}: {1}".format(obj.get_type(), obj.FQSN))
496+
print("{}: {}".format(obj.get_type(), obj.FQSN))
499497
print_children(obj)
500498
print("\n=========\nExportable Objects\n=========\n")
501499
for _, obj in file_ast.global_dict.items():
502-
print("{0}: {1}".format(obj.get_type(), obj.FQSN))
500+
print("{}: {}".format(obj.get_type(), obj.FQSN))
503501

504502

505503
def check_request_params(args, loc_needed=True):
@@ -508,17 +506,17 @@ def check_request_params(args, loc_needed=True):
508506
file_exists = os.path.isfile(args.debug_filepath)
509507
if file_exists is False:
510508
error_exit("Specified 'debug_filepath' does not exist")
511-
print(' File = "{0}"'.format(args.debug_filepath))
509+
print(' File = "{}"'.format(args.debug_filepath))
512510
if loc_needed:
513511
if args.debug_line is None:
514512
error_exit("'debug_line' not specified for debug request")
515-
print(" Line = {0}".format(args.debug_line))
513+
print(" Line = {}".format(args.debug_line))
516514
if args.debug_char is None:
517515
error_exit("'debug_char' not specified for debug request")
518-
print(" Char = {0}\n".format(args.debug_char))
516+
print(" Char = {}\n".format(args.debug_char))
519517

520518

521519
def print_children(obj, indent=""):
522520
for child in obj.get_children():
523-
print(" {0}{1}: {2}".format(indent, child.get_type(), child.FQSN))
521+
print(" {}{}: {}".format(indent, child.get_type(), child.FQSN))
524522
print_children(child, indent + " ")

fortls/helper_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ def strip_strings(in_line: str, maintain_len: bool = False) -> str:
107107
"""
108108

109109
def repl_sq(m):
110-
return "'{0}'".format(" " * (len(m.group()) - 2))
110+
return "'{}'".format(" " * (len(m.group()) - 2))
111111

112112
def repl_dq(m):
113-
return '"{0}"'.format(" " * (len(m.group()) - 2))
113+
return '"{}"'.format(" " * (len(m.group()) - 2))
114114

115115
if maintain_len:
116116
out_line = FRegex.SQ_STRING.sub(repl_sq, in_line)

0 commit comments

Comments
 (0)