Kirill Simonov avatar Kirill Simonov committed b0fe7e7

Added an error marker to the editor.

Comments (0)

Files changed (4)

src/htsql_tweak/shell/command.py

 from htsql.cmd.command import UniversalCmd, Command
 from htsql.cmd.act import (Act, RenderAction, UnsupportedActionError,
                            produce, analyze)
+from htsql.tr.error import TranslateError
 from htsql.tr.syntax import StringSyntax, NumberSyntax, SegmentSyntax
 from htsql.tr.binding import CommandBinding
 from htsql.tr.signature import Signature, Slot
         yield "}\n"
 
     def render_error(self, exc):
+        detail = exc.detail
+        first_line = 'null'
+        first_column = 'null'
+        last_line = 'null'
+        last_column = 'null'
+        if isinstance(exc, TranslateError) and exc.mark.input:
+            mark = exc.mark
+            first_break = mark.input.rfind('\n', 0, mark.start)+1
+            last_break = mark.input.rfind('\n', 0, mark.end)+1
+            first_line = mark.input.count('\n', 0, first_break)
+            last_line = mark.input.count('\n', 0, last_break)
+            first_column = mark.start-first_break
+            last_column = mark.end-last_break
         yield "{\n"
         yield "  \"type\": \"error\",\n"
-        yield "  \"message\": %s\n" % escape(cgi.escape(str(exc)))
+        yield "  \"detail\": %s,\n" % escape(cgi.escape(detail))
+        yield "  \"first_line\": %s,\n" % first_line
+        yield "  \"first_column\": %s,\n" % first_column
+        yield "  \"last_line\": %s,\n" % last_line
+        yield "  \"last_column\": %s\n" % last_column
         yield "}\n"
 
     def render_product(self, product):

src/htsql_tweak/shell/static/index.html

         </div>
         <div id="error-panel" class="panel">
           <div class="alert">
-            <strong>The server produced an error:</strong>
             <pre id="error"></pre>
             <button id="close-error" class="close">&times;</button>
           </div>

src/htsql_tweak/shell/static/shell.css

   height: 100%;
 }
 
+.input-area .editor-box .CodeMirror .marker {
+  border: dotted #f00;
+  border-width: 0 0 1px 0;
+}
+
 .input-area .button-box {
   position: absolute;
   right: 0;

src/htsql_tweak/shell/static/shell.js

             lastQuery: null,
             lastAction: null,
             table: null,
+            marker: null
         }
     }
 
             return;
         if (state.waiting)
             return;
+        if (state.marker) {
+            state.marker();
+            state.marker = null;
+        }
         state.lastQuery = query;
         state.lastAction = action;
         query = "/evaluate('" + query.replace(/'/g,"''") + "'"
         if (state.$panel)
             state.$panel.hide();
         state.$panel = $errorPanel.show();
-        $error.html(output.message);
+        $error.html(output.detail);
+        if (state.marker) {
+            state.marker();
+            state.marker = null;
+        }
+        if (output.first_line !== null && output.first_column !== null &&
+                output.last_line !== null && output.last_column !== null) {
+            editor.setCursor({ line: output.first_line,
+                               ch: output.first_column });
+            state.marker = editor.markText({ line: output.first_line,
+                                             ch: output.first_column },
+                                           { line: output.last_line,
+                                             ch: output.last_column },
+                                           'marker');
+        }
     }
 
     function handleUnsupported(output) {
     $('#close-sql').hide();
 
     $('title').text(config.databaseName);
-    $('database').text(config.databaseName);
+    $($database).text(config.databaseName);
 
     if (config.evaluateOnStart) {
         $('#run').click();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.