Skip to content

Commit e68dd24

Browse files
authored
Merge branch 'master' into pre-commit-ci-update-config
2 parents 92a9577 + 833755e commit e68dd24

File tree

7 files changed

+154
-2
lines changed

7 files changed

+154
-2
lines changed

CHANGELOG.md

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

77
### Added
88

9+
- Added hover messages for Types and Modules
10+
([#208](https://github.com/fortran-lang/fortls/issues/208))
911
- Added support for Markdown intrinsics from the M_intrinsics repository
1012
([#215](https://github.com/fortran-lang/fortls/issues/215))
1113
- Added and create a schema for fortls configuration files

fortls/langserver.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,12 @@ def create_hover(string: str, docs: str | None):
10821082
# Construct hover information
10831083
var_type: int = var_obj.get_type()
10841084
hover_array = []
1085-
if var_type in (SUBROUTINE_TYPE_ID, FUNCTION_TYPE_ID):
1085+
if var_type in (
1086+
SUBROUTINE_TYPE_ID,
1087+
FUNCTION_TYPE_ID,
1088+
MODULE_TYPE_ID,
1089+
CLASS_TYPE_ID,
1090+
):
10861091
hover_array.append(var_obj.get_hover_md(long=True))
10871092
elif var_type == INTERFACE_TYPE_ID:
10881093
for member in var_obj.mems:

fortls/objects.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,11 @@ def get_type(self, no_link=False):
804804
def get_desc(self):
805805
return "MODULE"
806806

807+
def get_hover(self, long=False, drop_arg=-1) -> tuple[str, str]:
808+
hover = f"{self.get_desc()} {self.name}"
809+
doc_str = self.get_documentation()
810+
return hover, doc_str
811+
807812
def check_valid_parent(self):
808813
if self.parent is not None:
809814
return False
@@ -1287,7 +1292,7 @@ def __init__(
12871292
self.inherit_var = None
12881293
self.inherit_tmp = None
12891294
self.inherit_version = -1
1290-
if keywords.count(KEYWORD_ID_DICT["abstract"]) > 0:
1295+
if self.keywords.count(KEYWORD_ID_DICT["abstract"]) > 0:
12911296
self.abstract = True
12921297
else:
12931298
self.abstract = False
@@ -1436,6 +1441,17 @@ def get_actions(self, sline, eline):
14361441
]
14371442
return actions
14381443

1444+
def get_hover(self, long=False, drop_arg=-1) -> tuple[str, str]:
1445+
keywords = [self.get_desc()]
1446+
if self.abstract:
1447+
keywords.append("ABSTRACT")
1448+
if self.inherit:
1449+
keywords.append(f"EXTENDS({self.inherit})")
1450+
decl = ", ".join(keywords)
1451+
hover = f"{decl} :: {self.name}"
1452+
doc_str = self.get_documentation()
1453+
return hover, doc_str
1454+
14391455

14401456
class Block(Scope):
14411457
def __init__(self, file_ast: FortranAST, line_number: int, name: str):

test/test_server_documentation.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,73 @@ def test_doc_multiline_type_bound_procedure_arg_list():
300300
),
301301
True,
302302
)
303+
304+
305+
def test_doxygen_doc_for_module_use():
306+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir / "docs")})
307+
file_path = test_dir / "docs" / "test_module_and_type_doc.f90"
308+
string += hover_request(file_path, 24, 14)
309+
errcode, results = run_request(string)
310+
assert errcode == 0
311+
312+
ref = (
313+
(0, "```fortran90"),
314+
(1, "MODULE doxygen_doc_mod"),
315+
(2, "```"),
316+
(3, "-----"),
317+
(4, "module doc for doxygen_doc_mod"),
318+
(5, ""),
319+
(6, "with info"),
320+
)
321+
check_return(results[1], ref)
322+
323+
324+
def test_ford_doc_for_module_use():
325+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir / "docs")})
326+
file_path = test_dir / "docs" / "test_module_and_type_doc.f90"
327+
string += hover_request(file_path, 25, 14)
328+
errcode, results = run_request(string)
329+
assert errcode == 0
330+
331+
ref = (
332+
(0, "```fortran90"),
333+
(1, "MODULE ford_doc_mod"),
334+
(2, "```"),
335+
(3, "-----"),
336+
(4, "Doc for ford_doc_mod"),
337+
)
338+
check_return(results[1], ref)
339+
340+
341+
def test_doxygen_doc_for_type():
342+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir / "docs")})
343+
file_path = test_dir / "docs" / "test_module_and_type_doc.f90"
344+
string += hover_request(file_path, 27, 11)
345+
errcode, results = run_request(string)
346+
assert errcode == 0
347+
348+
ref = (
349+
(0, "```fortran90"),
350+
(1, "TYPE :: a_t"),
351+
(2, "```"),
352+
(3, "-----"),
353+
(4, "Doc for a_t"),
354+
)
355+
check_return(results[1], ref)
356+
357+
358+
def test_ford_doc_for_type():
359+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir / "docs")})
360+
file_path = test_dir / "docs" / "test_module_and_type_doc.f90"
361+
string += hover_request(file_path, 28, 11)
362+
errcode, results = run_request(string)
363+
assert errcode == 0
364+
365+
ref = (
366+
(0, "```fortran90"),
367+
(1, "TYPE :: b_t"),
368+
(2, "```"),
369+
(3, "-----"),
370+
(4, "Doc for b_t"),
371+
)
372+
check_return(results[1], ref)

test/test_server_hover.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,20 @@ def test_intrinsics():
538538
intrinsics = json.load(f)
539539
ref_results = ["\n-----\n" + intrinsics["SIZE"]]
540540
validate_hover(results, ref_results)
541+
542+
543+
def test_types():
544+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir / "hover")})
545+
file_path = test_dir / "hover" / "types.f90"
546+
string += hover_req(file_path, 3, 25)
547+
string += hover_req(file_path, 6, 44)
548+
string += hover_req(file_path, 9, 35)
549+
550+
errcode, results = run_request(string, fortls_args=["-n", "1"])
551+
assert errcode == 0
552+
ref_results = [
553+
"```fortran90\nTYPE, ABSTRACT :: base_t\n```",
554+
"```fortran90\nTYPE, ABSTRACT, EXTENDS(base_t) :: extends_t\n```",
555+
"```fortran90\nTYPE, EXTENDS(extends_t) :: a_t\n```",
556+
]
557+
validate_hover(results, ref_results)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
!> module doc for doxygen_doc_mod
2+
!!
3+
!! with info
4+
module doxygen_doc_mod
5+
implicit none
6+
7+
!> Doc for a_t
8+
type :: a_t
9+
end type
10+
end module
11+
12+
13+
module ford_doc_mod
14+
!! Doc for ford_doc_mod
15+
implicit none
16+
17+
type :: b_t
18+
!! Doc for b_t
19+
end type
20+
21+
end module
22+
23+
24+
program main
25+
use doxygen_doc_mod
26+
use ford_doc_mod
27+
28+
type(a_t) :: a
29+
type(b_t) :: b
30+
end program

test/test_source/hover/types.f90

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module some_mod
2+
implicit none
3+
4+
type, abstract :: base_t
5+
end type
6+
7+
type, abstract, extends(base_t) :: extends_t
8+
end type
9+
10+
type, extends(extends_t) :: a_t
11+
end type
12+
end module

0 commit comments

Comments
 (0)