Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gnikit/issue106 #110

Merged
merged 9 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[run]
dynamic_context = test_function
omit =
omit =
fortls/__init__.py
fortls/version.py

Expand All @@ -9,4 +9,4 @@ exclude_lines =
if debug:
log.debug
except:
if not PY3K:
if not PY3K:
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*.pyc
.vscode
*.egg-info
*.egg-info
dist/
build/
docs/_build/
Expand All @@ -14,4 +14,4 @@ fortls/_version.py
*.smod
*.log

.coverage
.coverage
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
- repo: https://github.com/asottile/pyupgrade
rev: v2.32.1
hooks:
- id: pyupgrade
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@

### Added

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

### Changed

- Formatted all files with `pre-commit`

## 2.3.1

### Fixed
Expand Down
16 changes: 13 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,36 @@ To verify that your cloning of the GitHub repository work as expected open a ter
```sh
pytest -v
```

This will run the entire unit test suite. You can also run this to verify that you haven't broken anything in the code.

👉 **Tip!** You can run individual tests by selecting the path to the Python file and the method
👉 **Tip!** You can run individual tests by selecting the path to the Python file and the method

```sh
pytest test/test_interface.py::test_version_update_pypi
```

### Developing & Debugging 🐞️

❗️ Before you start developing, open a terminal inside `fortls` and run:

```sh
pre-commit install
```

This will ensure that all you commits meet the formatting standards of the project.

----

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.
It is however considerably easier to create compact unittests to check if your changes have worked.

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.
Often times small bits of Fortran source code also have to be submited to be used by the test.
You can find varisous test examples in the `tests` directory.


👉 **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.


### Merging

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.
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SPHINXAPIDOC ?= sphinx-apidoc
PANDOC ?= pandoc
PANDOC ?= pandoc
SOURCEDIR = .
BUILDDIR = _build

Expand Down
2 changes: 0 additions & 2 deletions docs/editor_integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,3 @@ Edit your kakrc config to enable kak-lsp, adding fortran as a filetype:
hook global WinSetOption filetype=(fortran) %{
lsp-enable-window
}


4 changes: 2 additions & 2 deletions docs/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ incl_suffixes
.F .f .F03 .f03 .F05 .f05 .F08 .f08 .F18 .f18 .F77 .f77 .F90 .f90 .F95 .f95 .FOR .for .FPP .fpp.
Additional source file extensions can be defined in ``incl_suffixes``.

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


excl_suffixes
Expand Down Expand Up @@ -187,7 +187,7 @@ pp_defs
}
}

Additional **preprocessor definitions** from what are specified in files found in
Additional **preprocessor definitions** from what are specified in files found in
``include_dirs`` can be defined in ``pp_defs``.

.. note:: Definitions in ``pp_defs`` will override definitions from ``include_dirs``
Expand Down
54 changes: 26 additions & 28 deletions fortls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ def debug_server_general(args, settings):
"Specified 'debug_rootpath' does not exist or is not a directory"
)
print('\nTesting "initialize" request:')
print(' Root = "{0}"'.format(args.debug_rootpath))
print(' Root = "{}"'.format(args.debug_rootpath))
s.serve_initialize({"params": {"rootPath": args.debug_rootpath}})
if len(s.post_messages) == 0:
print(" Successful!")
else:
print(" Successful with errors:")
for message in s.post_messages:
print(" {0}".format(message[1]))
print(" {}".format(message[1]))
# Print module directories
print("\n Source directories:")
for source_dir in s.source_dirs:
print(" {0}".format(source_dir))
print(" {}".format(source_dir))
#
if args.debug_diagnostics:
print('\nTesting "textDocument/publishDiagnostics" notification:')
Expand All @@ -117,7 +117,7 @@ def debug_server_general(args, settings):
sline = diag["range"]["start"]["line"]
message = diag["message"]
sev = sev_map[diag["severity"] - 1]
print(' {0:5d}:{1} "{2}"'.format(sline, sev, message))
print(' {:5d}:{} "{}"'.format(sline, sev, message))
#
if args.debug_symbols:
print('\nTesting "textDocument/documentSymbol" request:')
Expand Down Expand Up @@ -192,7 +192,7 @@ def debug_server_general(args, settings):
else:
for obj in completion_results:
print(
" {0}: {1} -> {2}".format(
" {}: {} -> {}".format(
obj["kind"], obj["label"], obj["detail"]
)
)
Expand Down Expand Up @@ -220,11 +220,11 @@ def debug_server_general(args, settings):
print(json.dumps(signature_results, indent=2))
else:
active_param = signature_results.get("activeParameter", 0)
print(" Active param = {0}".format(active_param))
print(" Active param = {}".format(active_param))
active_signature = signature_results.get("activeSignature", 0)
print(" Active sig = {0}".format(active_signature))
print(" Active sig = {}".format(active_signature))
for i, signature in enumerate(signature_results["signatures"]):
print(" {0}".format(signature["label"]))
print(" {}".format(signature["label"]))
for j, obj in enumerate(signature["parameters"]):
if (i == active_signature) and (j == active_param):
active_mark = "*"
Expand Down Expand Up @@ -278,14 +278,14 @@ def debug_server_general(args, settings):
if args.debug_full_result:
print(json.dumps(definition_results, indent=2))
else:
print(' URI = "{0}"'.format(definition_results["uri"]))
print(' URI = "{}"'.format(definition_results["uri"]))
print(
" Line = {0}".format(
" Line = {}".format(
definition_results["range"]["start"]["line"] + 1
)
)
print(
" Char = {0}".format(
" Char = {}".format(
definition_results["range"]["start"]["character"] + 1
)
)
Expand Down Expand Up @@ -345,7 +345,7 @@ def debug_server_general(args, settings):
print("=======")
for result in ref_results:
print(
" {0} ({1}, {2})".format(
" {} ({}, {})".format(
result["uri"],
result["range"]["start"]["line"] + 1,
result["range"]["start"]["character"] + 1,
Expand Down Expand Up @@ -379,7 +379,7 @@ def debug_server_general(args, settings):
print("=======")
for uri, result in ref_results["changes"].items():
path = path_from_uri(uri)
print('File: "{0}"'.format(path))
print('File: "{}"'.format(path))
file_obj = s.workspace.get(path)
if file_obj is not None:
file_contents = file_obj.contents_split
Expand All @@ -388,22 +388,22 @@ def debug_server_general(args, settings):
end_line = change["range"]["end"]["line"]
start_col = change["range"]["start"]["character"]
end_col = change["range"]["end"]["character"]
print(" {0}, {1}".format(start_line + 1, end_line + 1))
print(" {}, {}".format(start_line + 1, end_line + 1))
new_contents = []
for i in range(start_line, end_line + 1):
line = file_contents[i]
print(" - {0}".format(line))
print(" - {}".format(line))
if i == start_line:
new_contents.append(
line[:start_col] + change["newText"]
)
if i == end_line:
new_contents[-1] += line[end_col:]
for line in new_contents:
print(" + {0}".format(line))
print(" + {}".format(line))
print()
else:
print('Unknown file: "{0}"'.format(path))
print('Unknown file: "{}"'.format(path))
print("=======")
#
if args.debug_actions:
Expand Down Expand Up @@ -434,12 +434,10 @@ def debug_server_general(args, settings):
else:
for result in action_results:
print(
"Kind = '{0}', Title = '{1}'".format(
result["kind"], result["title"]
)
"Kind = '{}', Title = '{}'".format(result["kind"], result["title"])
)
for editUri, editChange in result["edit"]["changes"].items():
print("\nChange: URI = '{0}'".format(editUri))
print("\nChange: URI = '{}'".format(editUri))
pp.pprint(editChange)
print()
tmpout.close()
Expand Down Expand Up @@ -485,7 +483,7 @@ def debug_server_parser(args):
print(f"Error while parsing '{args.config}' settings file")
#
print("\nTesting parser")
print(' File = "{0}"'.format(args.debug_filepath))
print(' File = "{}"'.format(args.debug_filepath))
file_obj = fortran_file(args.debug_filepath, pp_suffixes)
err_str, _ = file_obj.load_from_disk()
if err_str:
Expand All @@ -495,11 +493,11 @@ def debug_server_parser(args):
file_ast = file_obj.parse(debug=True, pp_defs=pp_defs, include_dirs=include_dirs)
print("\n=========\nObject Tree\n=========\n")
for obj in file_ast.get_scopes():
print("{0}: {1}".format(obj.get_type(), obj.FQSN))
print("{}: {}".format(obj.get_type(), obj.FQSN))
print_children(obj)
print("\n=========\nExportable Objects\n=========\n")
for _, obj in file_ast.global_dict.items():
print("{0}: {1}".format(obj.get_type(), obj.FQSN))
print("{}: {}".format(obj.get_type(), obj.FQSN))


def check_request_params(args, loc_needed=True):
Expand All @@ -508,17 +506,17 @@ def check_request_params(args, loc_needed=True):
file_exists = os.path.isfile(args.debug_filepath)
if file_exists is False:
error_exit("Specified 'debug_filepath' does not exist")
print(' File = "{0}"'.format(args.debug_filepath))
print(' File = "{}"'.format(args.debug_filepath))
if loc_needed:
if args.debug_line is None:
error_exit("'debug_line' not specified for debug request")
print(" Line = {0}".format(args.debug_line))
print(" Line = {}".format(args.debug_line))
if args.debug_char is None:
error_exit("'debug_char' not specified for debug request")
print(" Char = {0}\n".format(args.debug_char))
print(" Char = {}\n".format(args.debug_char))


def print_children(obj, indent=""):
for child in obj.get_children():
print(" {0}{1}: {2}".format(indent, child.get_type(), child.FQSN))
print(" {}{}: {}".format(indent, child.get_type(), child.FQSN))
print_children(child, indent + " ")
4 changes: 2 additions & 2 deletions fortls/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ def strip_strings(in_line: str, maintain_len: bool = False) -> str:
"""

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

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

if maintain_len:
out_line = FRegex.SQ_STRING.sub(repl_sq, in_line)
Expand Down
2 changes: 1 addition & 1 deletion fortls/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ def get_hover(self, long=False, include_doc=True, drop_arg=-1):
if self.is_parameter() and self.param_val:
hover_str += f" :: {self.name} = {self.param_val}"
if include_doc and (doc_str is not None):
hover_str += "\n {0}".format("\n ".join(doc_str.splitlines()))
hover_str += "\n {}".format("\n ".join(doc_str.splitlines()))
return hover_str, True

def get_keywords(self):
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "fortls/_version.py"

[tool.isort]
profile = "black"
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dev =
pytest-cov >= 2.12.1
black
isort
pre-commit
docs =
sphinx >= 4.0.0
sphinx_rtd_theme
Expand Down
Loading