示例#1
0
 def check_return(result_array, checks):
     def find_in_results(uri, sline):
         for (i, result) in enumerate(result_array):
             if (result["uri"] == uri) and (result["range"]["start"]["line"] == sline):
                 del result_array[i]
                 return result
         return None
     assert len(result_array) == len(checks)
     for check in checks:
         result = find_in_results(path_to_uri(check[0]), check[1])
         assert (result is not None)
         assert result["range"]["start"]["character"] == check[2]
         assert result["range"]["end"]["character"] == check[3]
示例#2
0
 def check_return(result_array, checks):
     assert result_array["uri"] == path_to_uri(checks[2])
     assert result_array["range"]["start"]["line"] == checks[0]
     assert result_array["range"]["start"]["line"] == checks[1]
示例#3
0
 def check_return(result_array, checks):
     assert len(result_array) == len(checks)
     for (i, check) in enumerate(checks):
         assert result_array[i]["uri"] == path_to_uri(check[2])
         assert result_array[i]["range"]["start"]["character"] == check[0]
         assert result_array[i]["range"]["end"]["character"] == check[1]
示例#4
0
 def check_file(self, obj_tree, file_contents):
     errors = []
     tmp_list = self.scope_list[:]
     if self.none_scope is not None:
         tmp_list += [self.none_scope]
     for error in self.parse_errors:
         errors.append({
             "range": {
                 "start": {
                     "line": error["line"] - 1,
                     "character": error["schar"]
                 },
                 "end": {
                     "line": error["line"] - 1,
                     "character": error["echar"]
                 }
             },
             "message": error["mess"],
             "severity": error["sev"]
         })
     for error in self.end_errors:
         if error[0] >= 0:
             message = 'Unexpected end of scope at line {0}'.format(
                 error[0])
         else:
             message = 'Unexpected end statement: No open scopes'
         errors.append({
             "range": {
                 "start": {
                     "line": error[1] - 1,
                     "character": 0
                 },
                 "end": {
                     "line": error[1] - 1,
                     "character": 0
                 }
             },
             "message": message,
             "severity": 1
         })
     for scope in tmp_list:
         if not scope.check_valid_parent():
             errors.append({
                 "range": {
                     "start": {
                         "line": scope.sline - 1,
                         "character": 0
                     },
                     "end": {
                         "line": scope.sline - 1,
                         "character": 0
                     }
                 },
                 "message":
                 'Invalid parent for "{0}" declaration'.format(
                     scope.get_desc()),
                 "severity":
                 1
             })
         for error in scope.check_double_def(file_contents, obj_tree):
             # Check preproc if
             if self.check_ppif(error[1]):
                 continue
             if error[0] == 0:
                 message = 'Variable "{0}" declared twice in scope'.format(
                     error[4])
                 severity = 1
             elif error[0] == 1:
                 message = 'Variable "{0}" masks variable in parent scope'.format(
                     error[4])
                 severity = 2
             else:
                 continue
             errors.append({
                 "range": {
                     "start": {
                         "line": error[1],
                         "character": error[2]
                     },
                     "end": {
                         "line": error[1],
                         "character": error[3]
                     }
                 },
                 "message":
                 message,
                 "severity":
                 severity,
                 "relatedInformation": [{
                     "location": {
                         "uri": path_to_uri(error[5]),
                         "range": {
                             "start": {
                                 "line": error[6],
                                 "character": 0
                             },
                             "end": {
                                 "line": error[6],
                                 "character": 0
                             }
                         }
                     },
                     "message": ""
                 }]
             })
         for error in scope.check_use(obj_tree, file_contents):
             # Check preproc if
             if self.check_ppif(error[0]):
                 continue
             errors.append({
                 "range": {
                     "start": {
                         "line": error[0],
                         "character": error[1]
                     },
                     "end": {
                         "line": error[0],
                         "character": error[2]
                     }
                 },
                 "message":
                 'Module "{0}" not found in project'.format(error[3]),
                 "severity":
                 3
             })
     return errors