Skip to content

Commit 1873065

Browse files
folk85gnikit
andauthored
fix: allow whitespaces around % access operator
Allows the use of whitespaces around the `%` operator in derived types. Fixes #286 --------- Co-authored-by: gnikit <[email protected]>
1 parent 039131b commit 1873065

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
### Fixed
3131

32+
- Fixed bug where type fields or methods were not detected if spaces were
33+
used around `%`
34+
([#286](https://github.com/fortran-lang/fortls/issues/286))
3235
- Fixed bug where Go To Implementation would not work for submodules
3336
([#74](https://github.com/fortran-lang/fortls/issues/74))
3437
- Fixed bug where `associate` blocks for variables pointing to function results

fortls/helper_functions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,9 @@ def get_var_stack(line: str) -> list[str]:
553553
>>> get_var_stack('myarray(i)%foo%bar')
554554
['myarray', 'foo', 'bar']
555555
556+
>>> get_var_stack('myarray( i ) % foo % bar')
557+
['myarray', 'foo', 'bar']
558+
556559
In this case it will operate at the end of the string i.e. ``'this%foo'``
557560
558561
>>> get_var_stack('CALL self%method(this%foo')
@@ -569,13 +572,14 @@ def get_var_stack(line: str) -> list[str]:
569572
# Continuation of variable after paren requires '%' character
570573
iLast = 0
571574
for i, section in enumerate(sections):
572-
if not line[section.start : section.end].startswith("%"):
575+
if not line[section.start : section.end].strip().startswith("%"):
573576
iLast = i
574577
final_var = ""
575578
for section in sections[iLast:]:
576579
final_var += line[section.start : section.end]
577580

578581
if final_var is not None:
582+
final_var = "%".join([i.strip() for i in final_var.split("%")])
579583
final_op_split: list[str] = FRegex.OBJBREAK.split(final_var)
580584
return final_op_split[-1].split("%")
581585
else:

test/test_server_completion.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,29 @@ def test_comp10():
225225
validate_comp(results[i + 1], ref)
226226

227227

228+
def test_comp11():
229+
"""Indicate the derived types arguments separated with spaces and types"""
230+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
231+
file_path = test_dir / "test_prog.f08"
232+
string += comp_request(file_path, 23, 26)
233+
string += comp_request(file_path, 27, 28)
234+
string += comp_request(file_path, 28, 30)
235+
string += comp_request(file_path, 29, 30)
236+
errcode, results = run_request(string, ["--use_signature_help", "-n1"])
237+
assert errcode == 0
238+
239+
exp_results = (
240+
# test_prog.f08
241+
[1, "val", "REAL(8)"],
242+
[1, "val", "REAL(8)"],
243+
[1, "val", "REAL(8)"],
244+
[1, "val", "REAL(8)"],
245+
)
246+
assert len(exp_results) == len(results) - 1
247+
for i, ref in enumerate(exp_results):
248+
validate_comp(results[i + 1], ref)
249+
250+
228251
def test_comp_import_host_association():
229252
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
230253
file_path = test_dir / "test_import.f90"

test/test_source/test_prog.f08

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PROGRAM test_program
88
REAL(8) :: x,y
99
COMPLEX(8) :: xc,yc
1010
TYPE(vector) :: loc_vector
11-
TYPE(scaled_vector) :: stretch_vector
11+
TYPE(scaled_vector) :: stretch_vector, vector1d(1)
1212
!
1313
y = myfun(n,x)
1414
CALL glob_sub(n,xc,yc)
@@ -25,4 +25,7 @@ PROGRAM test_program
2525
!
2626
CALL test_sig_Sub(a,b,opt2=c,opt3=d)
2727
PRINT*, module_variable
28+
y = stretch_vector%scale % val
29+
y = stretch_vector % scale % val
30+
y = vector1d( 1 ) % scale % val
2831
END PROGRAM test_program

0 commit comments

Comments
 (0)