Skip to content

Commit a3ffc88

Browse files
authored
Fix error in Windows in zh_CN locale
By default python in Windows in zh_CN will use GBK to open files, since we're using UTF-8 now, it will throw error like this: Traceback (most recent call last): File "C:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Program Files\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Program Files\Python310\Scripts\fortls.exe\__main__.py", line 7, in <module> File "C:\Program Files\Python310\lib\site-packages\fortls\__init__.py", line 56, in main LangServer( File "C:\Program Files\Python310\lib\site-packages\fortls\langserver.py", line 119, in __init__ ) = load_intrinsics() File "C:\Program Files\Python310\lib\site-packages\fortls\intrinsics.py", line 168, in load_intrinsics intrin_file = json.load(fid) File "C:\Program Files\Python310\lib\json\__init__.py", line 293, in load return loads(fp.read(), UnicodeDecodeError: 'gbk' codec can't decode byte 0x99 in position 11899: illegal multibyte sequence
1 parent 914ff47 commit a3ffc88

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

fortls/intrinsics.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def add_children(json_obj, fort_obj):
142142
os.path.dirname(os.path.abspath(__file__)), "statements.json"
143143
)
144144
statements = {"var_def": [], "int_stmnts": []}
145-
with open(json_file, "r") as fid:
145+
with open(json_file, "r", encoding="utf-8") as fid:
146146
intrin_file = json.load(fid)
147147
for key in statements:
148148
for name, json_obj in sorted(intrin_file[key].items()):
@@ -153,7 +153,7 @@ def add_children(json_obj, fort_obj):
153153
os.path.dirname(os.path.abspath(__file__)), "keywords.json"
154154
)
155155
keywords = {"var_def": [], "arg": [], "type_mem": [], "vis": [], "param": []}
156-
with open(json_file, "r") as fid:
156+
with open(json_file, "r", encoding="utf-8") as fid:
157157
intrin_file = json.load(fid)
158158
for key in keywords:
159159
for name, json_obj in sorted(intrin_file[key].items()):
@@ -164,7 +164,7 @@ def add_children(json_obj, fort_obj):
164164
os.path.dirname(os.path.abspath(__file__)), "intrinsic_funs.json"
165165
)
166166
int_funs = []
167-
with open(json_file, "r") as fid:
167+
with open(json_file, "r", encoding="utf-8") as fid:
168168
intrin_file = json.load(fid)
169169
for name, json_obj in sorted(intrin_file.items()):
170170
int_funs.append(create_int_object(name, json_obj, json_obj["type"]))
@@ -175,7 +175,7 @@ def add_children(json_obj, fort_obj):
175175
os.path.dirname(os.path.abspath(__file__)), "intrinsic_mods.json"
176176
)
177177
int_mods = []
178-
with open(json_file, "r") as fid:
178+
with open(json_file, "r", encoding="utf-8") as fid:
179179
intrin_file = json.load(fid)
180180
for key, json_obj in intrin_file.items():
181181
fort_obj = create_object(json_obj)

0 commit comments

Comments
 (0)