Skip to content

Commit cbb9827

Browse files
committed
Inform the user in case of parsing errors
1 parent 082017c commit cbb9827

File tree

7 files changed

+48
-10
lines changed

7 files changed

+48
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
* in the tiebreak module function tiebreak_on_visual has been added, to enable more coherent tie-breaking
1010

11+
* PopUpErrorAction has been added in order to inform the user in cases where to cannot parse the source code.
12+
1113
### Fixed
1214

1315
* fixed the empty brackets bug in the repair modulebugs with ":" addressed, needs more testing and a subsequent bug
@@ -52,6 +54,10 @@
5254

5355
* additionally, even in case of ties when tie-breaking on the lowest common ancestor, the visual proximity is now taken into account!
5456

57+
* in the partial module, the function partially_parse has been modified in order to accept one more optional Boolean parameter which when True causes the function to raise the initial syntax error it captured instead of returning None objects. By default the parameter is set to False.
58+
59+
* In the same spirit, the query module has been modified and has a new attribute in order to store the above exception. The application module checks if this attribute HUD stored exception and displays an error through the PopUpErrorAction!
60+
5561
## [0.0.3] - 2019-11-18
5662

5763
important patch

application/application.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ def respond_to_query(self,interface,query_description):
3939

4040
# get the corresponding query and execute it
4141
s = get_query(query_description)(code,latest_build)
42-
s(view_information,query_description,extra)
42+
try:
43+
s(view_information,query_description,extra)
44+
except:
45+
pass
46+
47+
# check if there are exceptions
48+
if s.exceptions_raised:
49+
interface.push_action(PopUpErrorAction(str(s.exceptions_raised)))
50+
print(s.exceptions_raised)
4351

4452
# register build for later use
4553
b = s.get_the_latest_build()

doc/SelectArgument.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ But why both "above" and "up"? The difference lies in that above only counts "in
107107

108108
![](./gif/arg5.gif)
109109

110-
Please also pay attention to the fact that logical lines can extend over multiple "physical" lines. In such a case, as illustrated by the last example in the gif, physical lines still determine the line to which above/below refer and result and alternatives from that physical line will be prioritized, but alternatives will also be offered from the whole logical line! Other than that like case one.
110+
Though if we want to be more precise, we count lines that contain the beginning of function calls! this is important because logical lines can extend over multiple "physical" lines. The last example in the gif contains such an example, physical lines still determine the line to which above/below refer and result and alternatives from that physical line will be prioritized, but alternatives will also be offered from the whole logical line!
111+
112+
113+
111114

112115
## Case three
113116

interface/common/actions.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import html
2+
13
class InterfaceAction():
24
"""docstring for InterfaceAction"""
35
def __init__(self):
@@ -207,6 +209,20 @@ def execute(self,view,window,sublime,**kwargs):
207209
window.run_command("hide_panel",{"panel":"console"})
208210
window.run_command("show_panel",{"panel":"output.python_voice_coding_plugin_panel"})
209211

212+
class PopUpErrorAction(InterfaceAction):
213+
"""docstring for DisplayErrorAction"""
214+
def __init__(self, text):
215+
self.text = text
216+
def execute(self,view, sublime,**kwargs):
217+
final_text = "<p></p><h>Something is off!</h>" + "<p>" + html.escape(self.text) + "</p>"
218+
print(" inside final text processing ",final_text)
219+
def on_hide():
220+
view.show_popup(final_text,max_width=1024, max_height=10000, flags= sublime.COOPERATE_WITH_AUTO_COMPLETE)
221+
view.show_popup(final_text,max_width=1024, max_height=10000,
222+
flags= sublime.COOPERATE_WITH_AUTO_COMPLETE,on_hide = on_hide)
223+
print(view.is_popup_visible())
224+
225+
# style=\"background-color:#000080\"
210226

211227

212228

library/partial.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@
3030
################################################################################################
3131
################################################################################################
3232

33-
def partially_parse(code, m = None, atok = None):
33+
def partially_parse(code, m = None, atok = None,rethrow_exception = False):
3434
m = m if m is not None else ModificationHandler(code)
3535
#print(code)
3636
timestamp = m.get_timestamp()
3737
try:
3838
root,atok = build_tree(code)
3939
r = RepairMissing(atok,m,timestamp)
4040
return root,atok,m,r
41-
except:
41+
except Exception as e_first:
4242
atok = atok if atok else asttokens.ASTTokens(parse=False, source_text= code)
43-
print(m)
43+
# print(m)
4444
m = filter_everything(atok,m, timestamp)
4545
m.update()
4646
#print("after filtering",m.history)
@@ -54,16 +54,16 @@ def partially_parse(code, m = None, atok = None):
5454
return root,atok,m,r
5555
except Exception as e:
5656
print(" go to the field\n",m.current_code)
57-
print(" error was\n",e)
57+
print(" error was\n",str(e),"\n",e)
58+
if rethrow_exception :
59+
raise e_first
5860
return None,None,None,None
5961

6062
###############################
6163

6264

6365
def line_partial(code,offset):
64-
print("inside bar shall align")
6566
atok = asttokens.ASTTokens(parse=False, source_text=code)
66-
print([x for x in atok.tokens if x.type== tokenize.NL])
6767
origin = atok.get_token_from_offset(offset)
6868
left, right = expand_to_line_or_statement(atok,origin)
6969
print( left, right )

queries/abstract/query.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ class Query():
55
def __init__(self, code,latest_build = None):
66
self.code = code
77
self.general_build = latest_build
8+
self.exceptions_raised = None
89
self.attempt_build()
10+
911

1012

1113
def __call__(self,view_information,query_description,extra = {}):
@@ -16,7 +18,10 @@ def get_the_latest_build(self):
1618

1719
def attempt_build(self):
1820
if self.general_build is None:
19-
self.general_build = partially_parse(self.code)
21+
try:
22+
self.general_build = partially_parse(self.code,rethrow_exception = True)
23+
except Exception as e:
24+
self.exceptions_raised = e
2025

2126
def _get_selection(self,view_information,extra = {}):
2227
return extra["selection"] if "selection" in extra else view_information["selection"]

queries/big_roi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def preliminary(self,view_information,query_description, extra = {}):
2525
selection = self._get_selection(view_information,extra)
2626
build = self.general_build
2727
if not build or not build[0] :
28-
return None,None
28+
return None,None,None,None
2929
root,atok,m,r = build
3030
selection = m.forward(selection)
3131
origin = nearest_node_from_offset(root,atok, selection[0]) if selection[0]==selection[1] else node_from_range(root,atok, selection)

0 commit comments

Comments
 (0)