Skip to content

Commit 84f3787

Browse files
authored
Merge pull request #25 from gnikit/bug/visibility-modules
Bug/visibility modules
2 parents 313b566 + 110302f commit 84f3787

File tree

13 files changed

+413
-324
lines changed

13 files changed

+413
-324
lines changed

.github/workflows/python-publish.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@ jobs:
4141
4242
- name: Set __version__
4343
shell: bash
44-
run: sed -i "s/PLACEHOLDER/${VERSION}/g" "fortls/_version.py"
44+
run: sed -i "s@\".*\"@\"${VERSION}\"@g" "fortls/_version.py"
45+
46+
- name: Commit the new version
47+
shell: bash
48+
run: |
49+
git config --global user.name 'gnikit'
50+
git config --global user.email '[email protected]'
51+
git commit fortls/_version.py -am "Auto-Update version"
52+
git push
4553
4654
- name: Build package
4755
run: python -m build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ docs/fortls_changes.md
99

1010
*.o
1111
*.mod
12+
*.smod
1213
*.log

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# CHANGELONG
22

3+
## 2.0.1
4+
5+
### Added
6+
7+
- Add support for absolute include, source and exclude paths
8+
9+
### Changed
10+
11+
- Changed `USE_info` named tuple to storing use modules as `sets` instead of `lists`
12+
- Changed `include_dirs` from a `list` to a `set`
13+
14+
### Fixed
15+
16+
- Fixed some mutable default argument warnings in methods and classes
17+
- Fixed private variables showing in autocomplete
18+
([#191](https://github.com/hansec/fortran-language-server/issues/191))
19+
([gnikit/fortls#3](https://github.com/gnikit/fortls/issues/3))
20+
321
## 2.0.0
422

523
### Added

fortls/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def debug_server_parser(args):
461461
# Get preprocessor definitions from config file
462462
pp_suffixes = None
463463
pp_defs = {}
464-
include_dirs = []
464+
include_dirs = set()
465465
if args.debug_rootpath:
466466
config_path = os.path.join(args.debug_rootpath, args.config)
467467
config_exists = os.path.isfile(config_path)
@@ -471,9 +471,9 @@ def debug_server_parser(args):
471471
config_dict = json.load(fhandle)
472472
pp_suffixes = config_dict.get("pp_suffixes", None)
473473
pp_defs = config_dict.get("pp_defs", {})
474-
include_dirs = []
475-
for path in config_dict.get("include_dirs", []):
476-
include_dirs.extend(
474+
include_dirs = set()
475+
for path in config_dict.get("include_dirs", set()):
476+
include_dirs.update(
477477
only_dirs(resolve_globs(path, args.debug_rootpath))
478478
)
479479

fortls/helper_functions.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def get_line_prefix(pre_lines: list, curr_line: str, col: int, qs: bool = True)
258258

259259

260260
def resolve_globs(glob_path: str, root_path: str = None) -> list[str]:
261-
"""Resolve glob patterns
261+
"""Resolve paths (absolute and relative) and glob patterns
262262
263263
Parameters
264264
----------
@@ -277,16 +277,14 @@ def resolve_globs(glob_path: str, root_path: str = None) -> list[str]:
277277
Expanded glob patterns with absolute paths.
278278
Absolute paths are used to resolve any potential ambiguity
279279
"""
280-
# Path.glob returns a generator, we then cast the Path obj to a str
281-
# alternatively use p.as_posix()
282-
if root_path:
283-
return [str(p) for p in Path(root_path).resolve().glob(glob_path)]
284-
# Attempt to extract the root and glob pattern from the glob_path
285-
# This is substantially less robust that then above
280+
# Resolve absolute paths i.e. not in our root_path
281+
if os.path.isabs(glob_path) or not root_path:
282+
p = Path(glob_path).resolve()
283+
root = p.root
284+
rel = str(p.relative_to(root)) # contains glob pattern
285+
return [str(p.resolve()) for p in Path(root).glob(rel)]
286286
else:
287-
p = Path(glob_path).expanduser()
288-
parts = p.parts[p.is_absolute() :]
289-
return [str(i) for i in Path(p.root).resolve().glob(str(Path(*parts)))]
287+
return [str(p.resolve()) for p in Path(root_path).resolve().glob(glob_path)]
290288

291289

292290
def only_dirs(paths: list[str], err_msg: list = []) -> list[str]:

fortls/interface.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ def commandline_args(name: str = "fortls") -> argparse.ArgumentParser:
219219
# "--pp_include_dirs", # TODO: make main
220220
type=str,
221221
nargs="*",
222-
default=list(),
222+
default=set(),
223+
action=SetAction,
223224
metavar="DIRS",
224225
help="Folders containing preprocessor files with extensions PP_SUFFIXES.",
225226
)

fortls/langserver.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,10 @@ def get_candidates(
382382
):
383383
#
384384
def child_candidates(
385-
scope, only_list=[], filter_public=True, req_abstract=False
385+
scope, only_list: list = None, filter_public=True, req_abstract=False
386386
):
387+
if only_list is None:
388+
only_list = []
387389
tmp_list = []
388390
# Filter children
389391
nonly = len(only_list)
@@ -1546,8 +1548,8 @@ def __load_config_file_preproc(self, config_dict: dict) -> None:
15461548
if isinstance(self.pp_defs, list):
15471549
self.pp_defs = {key: "" for key in self.pp_defs}
15481550

1549-
for path in config_dict.get("include_dirs", []):
1550-
self.include_dirs.extend(
1551+
for path in config_dict.get("include_dirs", set()):
1552+
self.include_dirs.update(
15511553
only_dirs(resolve_globs(path, self.root_path), self.post_messages)
15521554
)
15531555

fortls/objects.py

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import copy
44
import os
55
import re
6-
from typing import Dict, NamedTuple, List, Pattern
6+
from typing import Dict, NamedTuple, List, Set, Pattern
77
from dataclasses import dataclass
88

99
from fortls.constants import (
@@ -56,7 +56,7 @@
5656
)
5757
USE_info = NamedTuple(
5858
"USE_info",
59-
[("mod_name", str), ("only_list", List[str]), ("rename_map", Dict[str, str])],
59+
[("mod_name", str), ("only_list", Set[str]), ("rename_map", Dict[str, str])],
6060
)
6161
GEN_info = NamedTuple(
6262
"GEN_info",
@@ -79,9 +79,9 @@ def get_use_tree(
7979
scope: fortran_scope,
8080
use_dict: dict,
8181
obj_tree: dict,
82-
only_list: list = [],
83-
rename_map: dict = {},
84-
curr_path: list = [],
82+
only_list: list = None,
83+
rename_map: dict = None,
84+
curr_path: list = None,
8585
):
8686
def intersect_only(use_stmnt):
8787
tmp_list = []
@@ -97,6 +97,13 @@ def intersect_only(use_stmnt):
9797
tmp_map.pop(val1, None)
9898
return tmp_list, tmp_map
9999

100+
if only_list is None:
101+
only_list = []
102+
if rename_map is None:
103+
rename_map = {}
104+
if curr_path is None:
105+
curr_path = []
106+
100107
# Detect and break circular references
101108
if scope.FQSN in curr_path:
102109
return use_dict
@@ -297,15 +304,17 @@ def __init__(
297304
self,
298305
mod_name: str,
299306
line_number: int,
300-
only_list: list = [],
301-
rename_map: dict = {},
307+
only_list: list = None,
308+
rename_map: dict = None,
302309
):
303310
self.mod_name: str = mod_name.lower()
304311
self.line_number: int = line_number
305-
self.only_list: list = [only.lower() for only in only_list]
306-
self.rename_map: dict = {
307-
key.lower(): value.lower() for key, value in rename_map.items()
308-
}
312+
if only_list is not None:
313+
self.only_list: list = [only.lower() for only in only_list]
314+
if rename_map is not None:
315+
self.rename_map: dict = {
316+
key.lower(): value.lower() for key, value in rename_map.items()
317+
}
309318

310319

311320
class fortran_diagnostic:
@@ -466,15 +475,19 @@ def req_named_end(self):
466475
def check_valid_parent(self):
467476
return True
468477

469-
def check_definition(self, obj_tree, known_types={}, interface=False):
478+
def check_definition(self, obj_tree, known_types: dict = None, interface=False):
479+
if known_types is None:
480+
known_types = {}
470481
return None, known_types
471482

472483

473484
class fortran_scope(fortran_obj):
474485
def __init__(self, file_ast, line_number: int, name: str):
475486
self.base_setup(file_ast, line_number, name)
476487

477-
def base_setup(self, file_ast, sline: int, name: str, keywords: list = []):
488+
def base_setup(self, file_ast, sline: int, name: str, keywords: list = None):
489+
if keywords is None:
490+
keywords = []
478491
self.file_ast: fortran_ast = file_ast
479492
self.sline: int = sline
480493
self.eline: int = sline
@@ -514,7 +527,13 @@ def copy_from(self, copy_source):
514527
self.implicit_vars = copy_source.implicit_vars
515528
self.implicit_line = copy_source.implicit_line
516529

517-
def add_use(self, use_mod, line_number, only_list=[], rename_map={}):
530+
def add_use(
531+
self, use_mod, line_number, only_list: list = None, rename_map: dict = None
532+
):
533+
if only_list is None:
534+
only_list = []
535+
if rename_map is None:
536+
rename_map = {}
518537
self.use.append(USE_line(use_mod, line_number, only_list, rename_map))
519538

520539
def set_inherit(self, inherit_type):
@@ -841,8 +860,10 @@ def __init__(
841860
name: str,
842861
args: str = "",
843862
mod_flag: bool = False,
844-
keywords: list = [],
863+
keywords: list = None,
845864
):
865+
if keywords is None:
866+
keywords = []
846867
self.base_setup(file_ast, line_number, name, keywords=keywords)
847868
self.args: str = args.replace(" ", "")
848869
self.args_snip: str = self.args
@@ -1055,10 +1076,12 @@ def __init__(
10551076
name: str,
10561077
args: str = "",
10571078
mod_flag: bool = False,
1058-
keywords: list = [],
1079+
keywords: list = None,
10591080
return_type=None,
10601081
result_var=None,
10611082
):
1083+
if keywords is None:
1084+
keywords = []
10621085
self.base_setup(file_ast, line_number, name, keywords=keywords)
10631086
self.args: str = args.replace(" ", "").lower()
10641087
self.args_snip: str = self.args
@@ -1495,7 +1518,7 @@ class fortran_int(fortran_scope):
14951518
def __init__(
14961519
self,
14971520
file_ast: fortran_ast,
1498-
line_number: list,
1521+
line_number: int,
14991522
name: str,
15001523
abstract: bool = False,
15011524
):
@@ -1540,9 +1563,11 @@ def __init__(
15401563
name: str,
15411564
var_desc: str,
15421565
keywords: list,
1543-
keyword_info: dict = {},
1566+
keyword_info: dict = None,
15441567
link_obj=None,
15451568
):
1569+
if keyword_info is None:
1570+
keyword_info = {}
15461571
self.base_setup(
15471572
file_ast, line_number, name, var_desc, keywords, keyword_info, link_obj
15481573
)
@@ -1920,7 +1945,7 @@ def get_enc_scope_name(self):
19201945
def add_scope(
19211946
self,
19221947
new_scope: fortran_scope,
1923-
END_SCOPE_REGEX,
1948+
END_SCOPE_REGEX: Pattern[str],
19241949
exportable: bool = True,
19251950
req_container: bool = False,
19261951
):

0 commit comments

Comments
 (0)