hansec / fortran-language-server

Fortran Language Server for the Language Server Protocol
MIT License
295 stars 57 forks source link

Certain illegal inline declarations of function return value throw exceptions #154

Closed mystery-e204 closed 4 years ago

mystery-e204 commented 4 years ago

While the following declaration is not legal

integer, allocatable function foo()
end function foo

it nevertheless throws an exception when beginning to type the function name foo or when using mouse hover. The same behavior can be seen when using dimension(...) or pointer in place of allocatable but not when writing something like

integer, real function foo()
end function foo

Here is the traceback:

error handling request {'jsonrpc': '2.0', 'id': 95, 'method': 'textDocument/completion', 'params': {'textDocument': {'uri': 'file:///.../test.f90'}, 'position': {'line': 4, 'character': 34}, 'context': {'triggerKind': 1}}}
Traceback (most recent call last):
  File "/.../fortls/langserver.py", line 165, in handle
    resp = handler(request)
  File "/.../fortls/langserver.py", line 681, in serve_autocomplete
    item_list.append(build_comp(candidate, name_only=name_only, name_replace=name_replace))
  File "/.../fortls/langserver.py", line 516, in build_comp
    doc_str, _ = candidate.get_hover()
  File "/.../fortls/objects.py", line 1518, in get_hover
    hover_str = ", ".join([self.desc] + get_keywords(self.keywords, self.keyword_info))
  File "/.../fortls/objects.py", line 79, in get_keywords
    string_rep = KEYWORD_LIST[keyword_id]
TypeError: list indices must be integers or slices, not str

In this case, keyword_id is in fact the string "allocatable". It seems read_var_def correctly identifies the line as a function, thus calling read_fun_def and setting obj_type = "fun" in process_file. Unfortunately, my investigation stops here as I don't have the time to dig any deeper.