@@ -63,31 +63,53 @@ async def collect_token_errors(self, sender: Any, document: TextDocument) -> Dia
63
63
from robot .parsing .lexer .tokens import Token
64
64
65
65
result : List [Diagnostic ] = []
66
+ try :
67
+ for token in await self .parent .documents_cache .get_tokens (document ):
68
+ if token .type in [Token .ERROR , Token .FATAL_ERROR ]:
69
+ result .append (self ._create_error_from_token (token ))
70
+
71
+ try :
72
+ for variable_token in token .tokenize_variables ():
73
+ if variable_token == token :
74
+ break
75
+
76
+ if variable_token .type in [Token .ERROR , Token .FATAL_ERROR ]:
77
+ result .append (self ._create_error_from_token (variable_token ))
78
+
79
+ except VariableError as e :
80
+ result .append (
81
+ Diagnostic (
82
+ range = range_from_token (token ),
83
+ message = str (e ),
84
+ severity = DiagnosticSeverity .ERROR ,
85
+ source = self .source_name ,
86
+ code = type (e ).__qualname__ ,
87
+ )
88
+ )
66
89
67
- for token in await self .parent .documents_cache .get_tokens (document ):
68
- if token .type in [Token .ERROR , Token .FATAL_ERROR ]:
69
- result .append (self ._create_error_from_token (token ))
70
-
71
- try :
72
- for variable_token in token .tokenize_variables ():
73
- if variable_token == token :
74
- break
75
-
76
- if variable_token .type in [Token .ERROR , Token .FATAL_ERROR ]:
77
- result .append (self ._create_error_from_token (variable_token ))
78
-
79
- except VariableError as e :
80
- result .append (
90
+ return DiagnosticsResult (self .collect_token_errors , result )
91
+ except BaseException as e :
92
+ return DiagnosticsResult (
93
+ self .collect_token_errors ,
94
+ [
81
95
Diagnostic (
82
- range = range_from_token (token ),
83
- message = str (e ),
96
+ range = Range (
97
+ start = Position (
98
+ line = 0 ,
99
+ character = 0 ,
100
+ ),
101
+ end = Position (
102
+ line = len (document .lines ),
103
+ character = len (document .lines [- 1 ] or "" ),
104
+ ),
105
+ ),
106
+ message = f"Fatal { type (e ).__qualname__ } : { e } " ,
84
107
severity = DiagnosticSeverity .ERROR ,
85
108
source = self .source_name ,
86
109
code = type (e ).__qualname__ ,
87
110
)
88
- )
89
-
90
- return DiagnosticsResult (self .collect_token_errors , result )
111
+ ],
112
+ )
91
113
92
114
@language_id ("robotframework" )
93
115
@_logger .call
@@ -145,7 +167,6 @@ async def collect_walk_model_errors(self, sender: Any, document: TextDocument) -
145
167
@language_id ("robotframework" )
146
168
@_logger .call
147
169
async def collect_namespace_diagnostics (self , sender : Any , document : TextDocument ) -> DiagnosticsResult :
148
-
149
170
namespace = await self .parent .documents_cache .get_namespace (document )
150
171
if namespace is None :
151
172
return DiagnosticsResult (self .collect_namespace_diagnostics , None )
0 commit comments