Browse Source

优化代码提示&优化`LINQ`提示

mxd 3 years ago
parent
commit
a96ae4cea4

+ 1 - 1
magic-editor/src/console/src/scripts/editor/high-light.js

@@ -18,7 +18,7 @@ export const HighLightOptions = {
                 cases: {
                     '@builtinFunctions': 'predefined',
                     "~(new|var|if|else|for|in|return|import|break|continue|as|null|true|false|try|catch|finally|async|while|exit|asc|desc|ASC|DESC|assert|let|const|throw)[\\s]?": {token: "keywords"},
-                    "~(select|from|left|join|on|and|or|order|by|where|group|having|SELECT|FROM|LEFT|JOIN|ON|AND|OR|ORDER|BY|WHERE|GROUP|HAVING)[\\s]{1}": {token: "keywords"},
+                    "~(select|from|left|join|on|and|or|order|by|where|group|having|limit|offset|SELECT|FROM|LEFT|JOIN|ON|AND|OR|ORDER|BY|WHERE|GROUP|HAVING|LIMIT|OFFSET)[\\s]{1}": {token: "keywords"},
                     "@default": "identifier"
                 }
             }],

+ 1 - 1
magic-editor/src/console/src/scripts/editor/hover.js

@@ -15,7 +15,7 @@ import JavaClass from "./java-class"
 import RequestParameter from './request-parameter.js';
 
 const findBestMatch = (node, row, col) => {
-    let expressions = node.expressions();
+    let expressions = node.expressions().filter(it => it);
     for (let index in expressions) {
         let expr = expressions[index];
         if (expr instanceof FunctionCall && expr.target instanceof VariableAccess && expr.getSpan().inPosition(row, col)) {

+ 4 - 2
magic-editor/src/console/src/scripts/parsing/ast.js

@@ -594,7 +594,7 @@ class ClassConverter extends Expression {
 }
 
 class LinqSelect extends Expression {
-    constructor(span, fields, from, joins, where, groups, having, orders) {
+    constructor(span, fields, from, joins, where, groups, having, orders, limit, offset) {
         super(span)
         this.fields = fields;
         this.from = from;
@@ -603,6 +603,8 @@ class LinqSelect extends Expression {
         this.groups = groups;
         this.having = having;
         this.orders = orders;
+        this.limit = limit;
+        this.offset = offset;
     }
 
     expressions() {
@@ -613,7 +615,7 @@ class LinqSelect extends Expression {
         if (this.having) {
             temp.push(this.having)
         }
-        return [...this.fields, this.from, ...this.joins, ...this.groups, ...temp, ...this.orders];
+        return [...this.fields, this.from, ...this.joins, ...this.groups, ...temp, ...this.orders, this.limit, this.offset];
     }
 
     async getJavaType() {

+ 1 - 1
magic-editor/src/console/src/scripts/parsing/index.js

@@ -294,7 +294,7 @@ class CharacterStream {
         if (this.index >= this.end)
             return false;
         let c = this.source.charAt(this.index);
-        if (!isNaN(c)) {
+        if (c!== ' ' && !isNaN(c)) {
             if (consume)
                 this.index++;
             return true;

+ 12 - 4
magic-editor/src/console/src/scripts/parsing/parser.js

@@ -39,7 +39,7 @@ import {
 } from './ast.js'
 
 export const keywords = ["import", "as", "var", "let", "const", "return", "break", "continue", "if", "for", "in", "new", "true", "false", "null", "else", "try", "catch", "finally", "async", "while", "exit", "and", "or", "throw"/*"assert"*/];
-export const linqKeywords = ["from", "join", "left", "group", "by", "as", "having", "and", "or", "in", "where", "on"];
+export const linqKeywords = ["from", "join", "left", "group", "by", "as", "having", "and", "or", "in", "where", "on", "limit", "offset"];
 const binaryOperatorPrecedence = [
     [TokenType.Assignment],
     [TokenType.RShift2Equal, TokenType.RShiftEqual, TokenType.LShiftEqual, TokenType.XorEqual, TokenType.BitOrEqual, TokenType.BitAndEqual, TokenType.PercentEqual, TokenType.ForwardSlashEqual, TokenType.AsteriskEqual, TokenType.MinusEqual, TokenType.PlusEqual],
@@ -93,7 +93,8 @@ export class Parser {
     }
 
     validateNode(node) {
-        if (node instanceof Literal) {
+        if (node instanceof Literal || node instanceof VariableAccess || node instanceof MapOrArrayAccess) {
+            console.log(new Error('111111'))
             throw new ParseException('literal cannot be used alone', node.getSpan());
         }
     }
@@ -582,7 +583,7 @@ export class Parser {
     }
 
     parseSelect() {
-        let opeing = this.stream.expect("select", true).getSpan();
+        let opening = this.stream.expect("select", true).getSpan();
         this.linqLevel++;
         let fields = this.parseLinqFields();
         this.stream.expect("from", true);
@@ -599,8 +600,15 @@ export class Parser {
         }
         let orders = this.parseLinqOrders();
         this.linqLevel--;
+        let limit,offset;
+        if(this.stream.match("limit", true, true)){
+            limit = this.parseExpression();
+            if(this.stream.match("offset", true, true)){
+                offset = this.parseExpression();
+            }
+        }
         let close = this.stream.getPrev().getSpan();
-        return new LinqSelect(new Span(opeing, close), fields, from, joins, where, groups, having, orders);
+        return new LinqSelect(new Span(opening, close), fields, from, joins, where, groups, having, orders, limit, offset);
     }
 
     parseGroup() {