Skip to content
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 @@ -6,6 +6,7 @@

### Added

- Added multiple unittests for diagnostic messages
- Added `pre-commit` hook to the project
([#106](https://github.com/gnikit/fortls/issues/106))
- Added Code of Conduct
Expand All @@ -14,6 +15,8 @@

### Changed

- Changed the naming convention for Fortran Objects
([#109](https://github.com/gnikit/fortls/issues/109))
- Formatted all files with `pre-commit`

## 2.3.1
Expand Down
4 changes: 2 additions & 2 deletions fortls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .interface import commandline_args
from .jsonrpc import JSONRPC2Connection, ReadWriter, path_from_uri
from .langserver import LangServer
from .parse_fortran import fortran_file
from .parse_fortran import FortranFile
from .version import __version__

__all__ = ["__version__"]
Expand Down Expand Up @@ -484,7 +484,7 @@ def debug_server_parser(args):
#
print("\nTesting parser")
print(' File = "{}"'.format(args.debug_filepath))
file_obj = fortran_file(args.debug_filepath, pp_suffixes)
file_obj = FortranFile(args.debug_filepath, pp_suffixes)
err_str, _ = file_obj.load_from_disk()
if err_str:
error_exit(f"Reading file failed: {err_str}")
Expand Down
26 changes: 13 additions & 13 deletions fortls/ftypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@dataclass
class VAR_info:
class VarInfo:
"""Holds information about a Fortran VARIABLE"""

var_type: str #: Type of variable e.g. ``INTEGER``, ``REAL``, etc.
Expand All @@ -18,7 +18,7 @@ class VAR_info:


@dataclass
class SELECT_info:
class SelectInfo:
"""Holds information about a SELECT construct"""

type: int #: Type of SELECT e.g. normal, select type, select kind, select rank
Expand All @@ -27,7 +27,7 @@ class SELECT_info:


@dataclass
class CLASS_info:
class ClassInfo:
"""Holds information about a Fortran CLASS"""

name: str #: Class name
Expand All @@ -36,7 +36,7 @@ class CLASS_info:


@dataclass
class USE_info:
class UseInfo:
"""Holds information about a Fortran USE statement"""

mod_name: str #: Module name
Expand All @@ -47,7 +47,7 @@ class USE_info:


@dataclass
class GEN_info:
class GenProcDefInfo:
"""Holds information about a GENERIC PROCEDURE DEFINITION"""

bound_name: str #: Procedure name
Expand All @@ -56,31 +56,31 @@ class GEN_info:


@dataclass
class SMOD_info:
class SmodInfo:
"""Holds information about Fortran SUBMODULES"""

name: str #: Submodule name
parent: str #: Submodule i.e. module, parent


@dataclass
class INT_info:
class InterInfo:
"""Holds information about a Fortran INTERFACE"""

name: str #: Interface name
abstract: bool #: Whether or not the interface is abstract


@dataclass
class VIS_info:
class VisInfo:
"""Holds information about the VISIBILITY of a module's contents"""

type: int #: Visibility type 0: PUBLIC 1: PRIVATE TODO: convert to boolean
obj_names: list[str] #: Module variables, procedures, etc. with that visibility


@dataclass
class INCLUDE_info:
class IncludeInfo:
"""Holds information about a Fortran INCLUDE statement"""

line_number: int #: Line number of include
Expand All @@ -90,7 +90,7 @@ class INCLUDE_info:


@dataclass
class SUB_info:
class SubInfo:
"""Holds information about a Fortran SUBROUTINE"""

name: str #: Procedure name
Expand All @@ -102,7 +102,7 @@ class SUB_info:


@dataclass
class RESULT_sig:
class ResultSig:
"""Holds information about the RESULT section of a Fortran FUNCTION"""

name: str = field(default=None) #: Variable name of result
Expand All @@ -112,11 +112,11 @@ class RESULT_sig:


@dataclass
class FUN_sig(SUB_info):
class FunSig(SubInfo):
"""Holds information about a Fortran FUNCTION"""

#: Function's result with default ``result.name = name``
result: RESULT_sig = field(default_factory=RESULT_sig)
result: ResultSig = field(default_factory=ResultSig)

def __post_init__(self):
if not self.result.name:
Expand Down
32 changes: 15 additions & 17 deletions fortls/intrinsics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

from fortls.helper_functions import map_keywords
from fortls.objects import (
fortran_ast,
fortran_function,
fortran_module,
fortran_obj,
fortran_subroutine,
fortran_type,
fortran_var,
FortranAST,
FortranObj,
Function,
Module,
Subroutine,
Type,
Variable,
)

none_ast = fortran_ast()
none_ast = FortranAST()
lowercase_intrinsics = False


Expand All @@ -21,7 +21,7 @@ def set_lowercase_intrinsics():
lowercase_intrinsics = True


class fortran_intrinsic_obj(fortran_obj):
class Intrinsic(FortranObj):
def __init__(self, name, type, doc_str=None, args="", parent=None):
self.name = name
self.type = type
Expand Down Expand Up @@ -87,7 +87,7 @@ def create_int_object(name, json_obj, type):
if lowercase_intrinsics:
name = name.lower()
args = args.lower()
return fortran_intrinsic_obj(name, type, doc_str=doc_str, args=args)
return Intrinsic(name, type, doc_str=doc_str, args=args)

def create_object(json_obj, enc_obj=None):
if enc_obj is not None:
Expand All @@ -105,14 +105,14 @@ def create_object(json_obj, enc_obj=None):
name = name.lower()
args = args.lower()
if json_obj["type"] == 0:
mod_tmp = fortran_module(none_ast, 0, name)
mod_tmp = Module(none_ast, 0, name)
if "use" in json_obj:
mod_tmp.add_use(json_obj["use"], 0)
return mod_tmp
elif json_obj["type"] == 1:
return fortran_subroutine(none_ast, 0, name, args=args)
return Subroutine(none_ast, 0, name, args=args)
elif json_obj["type"] == 2:
return fortran_function(
return Function(
none_ast,
0,
name,
Expand All @@ -122,11 +122,9 @@ def create_object(json_obj, enc_obj=None):
# keyword_info=keyword_info,
)
elif json_obj["type"] == 3:
return fortran_var(
none_ast, 0, name, json_obj["desc"], keywords, keyword_info
)
return Variable(none_ast, 0, name, json_obj["desc"], keywords, keyword_info)
elif json_obj["type"] == 4:
return fortran_type(none_ast, 0, name, keywords)
return Type(none_ast, 0, name, keywords)
else:
raise ValueError

Expand Down
32 changes: 16 additions & 16 deletions fortls/langserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@
set_keyword_ordering,
)
from fortls.intrinsics import (
fortran_intrinsic_obj,
Intrinsic,
get_intrinsic_keywords,
load_intrinsics,
set_lowercase_intrinsics,
)
from fortls.json_templates import change_json, symbol_json, uri_json
from fortls.jsonrpc import JSONRPC2Connection, path_from_uri, path_to_uri
from fortls.objects import (
FortranAST,
Variable,
climb_type_tree,
find_in_scope,
find_in_workspace,
fortran_ast,
fortran_var,
get_use_tree,
)
from fortls.parse_fortran import fortran_file, get_line_context
from fortls.parse_fortran import FortranFile, get_line_context
from fortls.regex_patterns import src_file_exts
from fortls.version import __version__

Expand All @@ -70,7 +70,7 @@ def __init__(self, conn, settings: dict):
self.conn: JSONRPC2Connection = conn
self.running: bool = True
self.root_path: str = None
self.workspace: dict[str, fortran_file] = {}
self.workspace: dict[str, FortranFile] = {}
self.obj_tree: dict = {}
self.link_version = 0
self._version = version.parse(__version__)
Expand Down Expand Up @@ -496,7 +496,7 @@ def build_comp(
params: dict = request["params"]
uri: str = params["textDocument"]["uri"]
path: str = path_from_uri(uri)
file_obj: fortran_file = self.workspace.get(path)
file_obj: FortranFile = self.workspace.get(path)
if file_obj is None:
return None
# Check line
Expand Down Expand Up @@ -673,7 +673,7 @@ def build_comp(

def get_definition(
self,
def_file: fortran_file,
def_file: FortranFile,
def_line: int,
def_char: int,
hover_req: bool = False,
Expand Down Expand Up @@ -716,7 +716,7 @@ def get_definition(
return None
# Search in Preprocessor defined variables
if def_name in def_file.pp_defs:
var = fortran_var(
var = Variable(
def_file.ast,
def_line + 1,
def_name,
Expand Down Expand Up @@ -778,7 +778,7 @@ def get_definition(
):
var_type = f"{FORTRAN_LITERAL}STRING"
if var_type:
return fortran_var(
return Variable(
curr_scope.file_ast,
def_line + 1,
def_name,
Expand Down Expand Up @@ -897,7 +897,7 @@ def get_all_references(
self,
def_obj,
type_mem: bool,
file_obj: fortran_file = None,
file_obj: FortranFile = None,
):
# Search through all files
def_name: str = def_obj.name.lower()
Expand Down Expand Up @@ -1124,7 +1124,7 @@ def serve_implementation(self, request: dict):
if var_obj is None:
return None
# Intrinsics do not have implementations we can access
if isinstance(var_obj, fortran_intrinsic_obj):
if isinstance(var_obj, Intrinsic):
return None
# Construct implementation reference
if var_obj.parent.get_type() == CLASS_TYPE_ID:
Expand All @@ -1147,7 +1147,7 @@ def serve_rename(self, request: dict):
def_obj = self.get_definition(file_obj, def_line, def_char)
if def_obj is None:
return None
if isinstance(def_obj, fortran_intrinsic_obj):
if isinstance(def_obj, Intrinsic):
self.post_message("Rename failed: Cannot rename intrinsics", Severity.warn)
return None
# Determine global accesibility and type membership
Expand Down Expand Up @@ -1335,11 +1335,11 @@ def update_workspace_file(
file_obj = self.workspace.get(filepath)
if read_file:
if file_obj is None:
file_obj = fortran_file(filepath, self.pp_suffixes)
file_obj = FortranFile(filepath, self.pp_suffixes)
# Create empty file if not yet saved to disk
if not os.path.isfile(filepath):
if allow_empty:
file_obj.ast = fortran_ast(file_obj)
file_obj.ast = FortranAST(file_obj)
self.workspace[filepath] = file_obj
return False, None
else:
Expand Down Expand Up @@ -1405,7 +1405,7 @@ def file_init(
fortran_file | str
A Fortran file object or a string containing the error message
"""
file_obj = fortran_file(filepath, pp_suffixes)
file_obj = FortranFile(filepath, pp_suffixes)
err_str, _ = file_obj.load_from_disk()
if err_str:
return err_str
Expand Down Expand Up @@ -1704,7 +1704,7 @@ def _load_intrinsics(self) -> None:

def _create_ref_link(self, obj) -> dict:
"""Create a link reference to an object"""
obj_file: fortran_file = obj.file_ast.file
obj_file: FortranFile = obj.file_ast.file
sline, (schar, echar) = obj_file.find_word_in_code_line(obj.sline - 1, obj.name)
if schar < 0:
schar = echar = 0
Expand Down
Loading