Skip to content

Commit f68595d

Browse files
committed
Initialises log channel
1 parent 87471bb commit f68595d

File tree

6 files changed

+29
-22
lines changed

6 files changed

+29
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
- Update constant parameters for `omp_lib` and `omp_lib_kinds` Interface v5.0
1818
- Format json files with `prettier`
19+
- Initialises the log channel and adds `$/setTrace` to override client's (i.e. VS Code) loglevel
1920

2021
### Fixes
2122

fortls/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import sys
2+
import logging
23

34
PY3K = sys.version_info >= (3, 0)
45

6+
log = logging.getLogger(__name__)
7+
58
# Global variables
69
sort_keywords = True
710

fortls/helper_functions.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from __future__ import annotations
22

3-
import logging
43
import os
54
from pathlib import Path
65

7-
from fortls.constants import KEYWORD_ID_DICT, KEYWORD_LIST, sort_keywords
6+
from fortls.constants import KEYWORD_ID_DICT, KEYWORD_LIST, log, sort_keywords
87
from fortls.regex_patterns import (
98
DQ_STRING_REGEX,
109
FIXED_COMMENT_LINE_MATCH,
@@ -18,8 +17,6 @@
1817
WORD_REGEX,
1918
)
2019

21-
log = logging.getLogger(__name__)
22-
2320

2421
def expand_name(line: str, char_poss: int) -> str:
2522
"""Get full word containing given cursor position

fortls/jsonrpc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import logging
32

43
try:
54
import Queue
@@ -16,7 +15,7 @@
1615
from urllib2 import quote
1716
from urlparse import unquote
1817

19-
log = logging.getLogger(__name__)
18+
from fortls.constants import log
2019

2120

2221
def path_from_uri(uri: str) -> str:

fortls/langserver.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing import Pattern
1212

1313
# Local modules
14+
from fortls._version import __version__
1415
from fortls.constants import (
1516
CLASS_TYPE_ID,
1617
FORTRAN_LITERAL,
@@ -21,6 +22,7 @@
2122
SELECT_TYPE_ID,
2223
SUBROUTINE_TYPE_ID,
2324
VAR_TYPE_ID,
25+
log,
2426
)
2527
from fortls.helper_functions import (
2628
expand_name,
@@ -55,7 +57,6 @@
5557
src_file_exts,
5658
)
5759

58-
log = logging.getLogger(__name__)
5960
# Global regexes
6061
# TODO: I think this can be replaced by fortls.regex_patterns type & class
6162
TYPE_DEF_REGEX = re.compile(r"[ ]*(TYPE|CLASS)[ ]*\([a-z0-9_ ]*$", re.I)
@@ -179,6 +180,7 @@ def noop(request):
179180
"workspace/didChangeWatchedFiles": noop,
180181
"workspace/symbol": self.serve_workspace_symbol,
181182
"$/cancelRequest": noop,
183+
"$/setTrace": noop,
182184
"shutdown": noop,
183185
"exit": self.serve_exit,
184186
}.get(request["method"], self.serve_default)
@@ -190,7 +192,7 @@ def noop(request):
190192
try:
191193
handler(request)
192194
except:
193-
log.warning("error handling notification %s", request, exc_info=True)
195+
log.exception("error handling request: %s", request, exc_info=True)
194196
return
195197
#
196198
try:
@@ -220,6 +222,11 @@ def serve_initialize(self, request):
220222
params.get("rootUri") or params.get("rootPath") or ""
221223
)
222224
self.source_dirs.add(self.root_path)
225+
logging.basicConfig(
226+
format="[%(levelname)-.4s - %(asctime)s] %(message)s",
227+
datefmt="%H:%M:%S",
228+
level=logging.INFO,
229+
)
223230
self.__config_logger(request)
224231
init_debug_log = self.__load_config_file()
225232
if init_debug_log:
@@ -229,6 +236,7 @@ def serve_initialize(self, request):
229236

230237
# Initialize workspace
231238
self.workspace_init()
239+
log.info(f"fortls - Fortran Language Server v{__version__} Initialized")
232240
#
233241
server_capabilities = {
234242
"completionProvider": {
@@ -251,7 +259,7 @@ def serve_initialize(self, request):
251259
if self.enable_code_actions:
252260
server_capabilities["codeActionProvider"] = True
253261
if self.notify_init:
254-
self.post_messages.append([3, "FORTLS initialization complete"])
262+
self.post_messages.append([3, "fortls initialization complete"])
255263
return {"capabilities": server_capabilities}
256264

257265
def serve_workspace_symbol(self, request):

fortls/parse_fortran.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from __future__ import print_function, annotations
1+
from __future__ import annotations, print_function
22

33
import hashlib
44
import logging
@@ -12,6 +12,7 @@
1212
PY3K,
1313
SELECT_TYPE_ID,
1414
SUBMODULE_TYPE_ID,
15+
log,
1516
)
1617
from fortls.helper_functions import (
1718
detect_fixed_format,
@@ -25,6 +26,16 @@
2526
strip_strings,
2627
)
2728
from fortls.objects import (
29+
CLASS_info,
30+
FUN_info,
31+
GEN_info,
32+
INT_info,
33+
SELECT_info,
34+
SMOD_info,
35+
SUB_info,
36+
USE_info,
37+
VAR_info,
38+
VIS_info,
2839
fortran_associate,
2940
fortran_ast,
3041
fortran_block,
@@ -43,16 +54,6 @@
4354
fortran_type,
4455
fortran_var,
4556
fortran_where,
46-
VAR_info,
47-
SUB_info,
48-
FUN_info,
49-
SELECT_info,
50-
CLASS_info,
51-
USE_info,
52-
GEN_info,
53-
SMOD_info,
54-
INT_info,
55-
VIS_info,
5657
)
5758
from fortls.regex_patterns import (
5859
ASSOCIATE_REGEX,
@@ -131,8 +132,6 @@
131132
if not PY3K:
132133
import io
133134

134-
log = logging.getLogger(__name__)
135-
136135

137136
def get_line_context(line: str) -> tuple[str, None]:
138137
"""Get context of ending position in line (for completion)

0 commit comments

Comments
 (0)