Skip to content

fix: associate block from Function result #280

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

Merged
merged 1 commit into from
May 16, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

### Fixed

- Fixed bug where `associate` blocks for variables pointing to function results
where not properly resolved
([#269](https://github.com/fortran-lang/fortls/issues/269))
- Fixed bug where the `langid` was not propagated correctly from the user
settings to the LSP creation stage for all types of requests.
([#257](https://github.com/fortran-lang/fortls/issues/257))
Expand Down
5 changes: 5 additions & 0 deletions fortls/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,7 @@ def __init__(
args: str = "",
mod_flag: bool = False,
keywords: list = None,
keyword_info: dict = None,
result_type: str = None,
result_name: str = None,
):
Expand All @@ -1173,9 +1174,13 @@ def __init__(
self.result_name: str = result_name
self.result_type: str = result_type
self.result_obj: Variable = None
self.keyword_info: dict = keyword_info
# Set the implicit result() name to be the function name
if self.result_name is None:
self.result_name = self.name
# Used in Associated blocks
if self.keyword_info is None:
self.keyword_info = {}

def copy_interface(self, copy_source: Function):
# Call the parent class method
Expand Down
3 changes: 2 additions & 1 deletion fortls/parse_fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -1493,14 +1493,15 @@ def parse(
log.debug("%s !!! SUBROUTINE - Ln:%d", line, line_no)

elif obj_type == "fun":
keywords, _ = map_keywords(obj_info.keywords)
keywords, keyword_info = map_keywords(obj_info.keywords)
new_fun = Function(
file_ast,
line_no,
obj_info.name,
args=obj_info.args,
mod_flag=obj_info.mod_flag,
keywords=keywords,
keyword_info=keyword_info,
result_type=obj_info.result.type,
result_name=obj_info.result.name,
)
Expand Down
14 changes: 14 additions & 0 deletions test/test_server_hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,20 @@ def test_hover_block():
validate_hover(results, ref_results)


def test_associate_block_func_result():
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir / "hover")})
file_path = test_dir / "hover" / "associate_block_2.f90"
string += hover_req(file_path, 2, 14)
string += hover_req(file_path, 3, 9)
errorcode, results = run_request(string, fortls_args=["--sort_keywords", "-n", "1"])
assert errorcode == 0
ref_results = [
"```fortran90\nLOGICAL FUNCTION :: hi\n```",
"```fortran90\nLOGICAL FUNCTION :: hi\n```",
]
validate_hover(results, ref_results)


def test_hover_submodule_procedure():
"""Test that submodule procedures and functions with modifier keywords
are correctly displayed when hovering.
Expand Down
10 changes: 10 additions & 0 deletions test/test_source/hover/associate_block_2.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
program associate_block_2
implicit none
associate (hi => say_hi())
if (hi) print *, 'Bye'
end associate
contains
logical function say_hi()
say_hi = .true.
end
end program