Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL 语句前面存在空白行时,错误提示未能在正确的位置显示 #12

Open
whinc opened this issue Apr 17, 2020 · 1 comment

Comments

@whinc
Copy link

whinc commented Apr 17, 2020

当 SQL 语句前面存在空白行时,解析结果中的 error.suggestions.token 为null,导致无法正确提示发生错误的位置,现象如下:
image

解析结果如下:

{
  "success": false,
  "ast": null,
  "cursorKeyPath": [],
  "nextMatchings": [
    {
      "type": "string",
      "value": "UPDATE"
    },
    {
      "type": "string",
      "value": "set"
    },
    {
      "type": "string",
      "value": "insert"
    },
    {
      "type": "string",
      "value": "create"
    },
    {
      "type": "string",
      "value": "select"
    }
  ],
  "error": {
    "suggestions": [
      {
        "type": "string",
        "value": "select"
      },
      {
        "type": "string",
        "value": "create"
      },
      {
        "type": "string",
        "value": "insert"
      },
      {
        "type": "string",
        "value": "set"
      },
      {
        "type": "string",
        "value": "UPDATE"
      }
    ],
    "token": null,
    "reason": "incomplete"
  },
  "debugInfo": {
    "tokens": [
      {
        "type": "word",
        "value": "selec",
        "position": [
          2,
          6
        ]
      }
    ],
    "callVisiterCount": 38,
    "costs": {
      "lexer": 0,
      "parser": 0
    }
  }
}

Demo 中关于错误提示位置的处理:

const errorPosition = parseResult.error.token
? {
startLineNumber: model.getPositionAt(parseResult.error.token.position[0]).lineNumber,
startColumn: model.getPositionAt(parseResult.error.token.position[0]).column,
endLineNumber: model.getPositionAt(parseResult.error.token.position[1]).lineNumber,
endColumn: model.getPositionAt(parseResult.error.token.position[1]).column + 1,
}
: {
startLineNumber: 0,
startColumn: 0,
endLineNumber: 0,
endColumn: 0,
};

期望结果:
未完整的语句,error.suggestion.token 能给出错误位置的token,如{type: "string", value: "selec", position: [1, 6]}

@whinc
Copy link
Author

whinc commented Apr 17, 2020

debugInfo 中有这个未完成语句的 token 信息,用这个信息可以设置正确的错误提示位置,但是这个是 debugInfo,担心依赖该字段会导致后续升级 break。

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant