Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: correct parse syntax error position (#15857)
h3n4l5c37ac7dad7d
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.goindex 65078f356b..c96f940129 100644--- a/backend/api/v1/sql_service.go+++ b/backend/api/v1/sql_service.go@@ -247,8 +247,8 @@ func (s *SQLService) Query(ctx context.Context, request *v1pb.QueryRequest) (*v1Status: v1pb.PlanCheckRun_Result_ERROR,Report: &v1pb.PlanCheckRun_Result_SqlReviewReport_{SqlReviewReport: &v1pb.PlanCheckRun_Result_SqlReviewReport{- Line: int32(syntaxErr.Line),- Column: int32(syntaxErr.Column),+ Line: int32(syntaxErr.Position.GetLine()),+ Column: int32(syntaxErr.Position.GetColumn()),},},},@@ -1391,8 +1391,8 @@ func validateQueryRequest(instance *store.InstanceMessage, statement string) errStatus: v1pb.PlanCheckRun_Result_ERROR,Report: &v1pb.PlanCheckRun_Result_SqlReviewReport_{SqlReviewReport: &v1pb.PlanCheckRun_Result_SqlReviewReport{- Line: int32(syntaxErr.Line),- Column: int32(syntaxErr.Column),+ Line: int32(syntaxErr.Position.GetLine()),+ Column: int32(syntaxErr.Position.GetColumn()),},},},diff --git a/backend/common/position.go b/backend/common/position.goindex 14963574e3..33c7ef4185 100644--- a/backend/common/position.go+++ b/backend/common/position.go@@ -1,8 +1,11 @@package commonimport (+ "strings""unicode/utf8"+ lsp "github.com/bytebase/lsp-protocol"+storepb "github.com/bytebase/bytebase/proto/generated-go/store")@@ -116,3 +119,81 @@ func ConvertANTLRLineToPosition(line int) *storepb.Position {Line: int32(positionLine),}}++// UTF16Position is a position in a text expressed as zero-based line and zero-based column counted in UTF-16 code units.+type UTF16Position = lsp.Position++// ConvertPositionToUTF16Position converts a Position to a UTF16Position in a given text.+// If the Position is nil, it returns a UTF16Position with line and character set to 0.+// If the line in Position is out of the end of text, replace it with the last line.+// If the column in Position is out of the end of line, replace it with the last column.+func ConvertPositionToUTF16Position(p *storepb.Position, text string) *UTF16Position {+ if p == nil {+ return &UTF16Position{+ Line: 0,+ Character: 0,+ }+ }+ lines := strings.Split(text, "\n")+ lineNumber := p.Line+ if lineNumber >= int32(len(lines)) {+ lineNumber = int32(len(lines)) - 1+ }+ u16CodeUnits := 0+ byteOffset := 0+ line := lines[lineNumber]+ for _, r := range line {+ if byteOffset >= int(p.Column) {+ break+ }+ byteOffset += len(string(r))+ u16CodeUnits+++ if r > 0xFFFF {+ // Need surrogate pair.+ u16CodeUnits+++ }+ }++ return &UTF16Position{+ Line: uint32(lineNumber),+ Character: uint32(u16CodeUnits),+ }+}++func ConvertTiDBParserErrorPositionToPosition(line, column int) *storepb.Position {+ if line < 1 {+ line = 1+ }+ if column < 1 {+ column = 1+ }++ return &storepb.Position{+ Line: int32(line) - 1,+ Column: int32(column) - 1,+ }+}++func ConvertPGParserErrorCursorPosToPosition(cursorPos int, text string) *storepb.Position {+ if cursorPos >= 1 {+ cursorPos--+ }+ line := 0+ column := 0+ rText := []rune(text)+ for i, r := range rText {+ if i >= cursorPos {+ break+ }+ if r == '\n' {+ line+++ column = 0+ continue+ }+ column += len(string(r))+ }+ return &storepb.Position{+ Line: int32(line),+ Column: int32(column),+ }+}diff --git a/backend/common/position_test.go b/backend/common/position_test.goindex 5cebcc2ecf..e8923af318 100644--- a/backend/common/position_test.go+++ b/backend/common/position_test.go@@ -75,3 +75,41 @@ func TestConvertANTLRPositionToPosition(t *testing.T) {a.Equalf(tc.want, got, "Test case: %s", tc.description)}}++func TestConvertPositionToUTF16Position(t *testing.T) {+ testCases := []struct {+ description string+ text string+ position *storepb.Position+ want *UTF16Position+ }{+ {+ description: "empty text",+ text: "",+ position: &storepb.Position{Line: 0, Column: 0},+ want: &UTF16Position{Line: 0, Character: 0},+ },+ {+ description: "ascii",+ text: "hello, world",+ position: &storepb.Position{Line: 0, Column: 6},+ want: &UTF16Position{Line: 0, Character: 6},+ },+ {+ description: "surrogate pairs",+ // 𝄞 encoded in utf16 with 2 code units, and 4 code units in utf8.+ text: "abc𝄞def",+ position: &storepb.Position{Line: 0, Column: 7},+ want: &UTF16Position{+ Line: 0,+ Character: 5,+ },+ },+ }++ a := require.New(t)+ for _, tc := range testCases {+ got := ConvertPositionToUTF16Position(tc.position, tc.text)+ a.Equalf(tc.want, got, "Test case: %s", tc.description)+ }+}diff --git a/backend/component/sheet/sheet.go b/backend/component/sheet/sheet.goindex 20094f6043..ed2467ade6 100644--- a/backend/component/sheet/sheet.go+++ b/backend/component/sheet/sheet.go@@ -283,8 +283,8 @@ func partiqlSyntaxCheck(statement string) (any, []*storepb.Advice) {Title: SyntaxErrorTitle,Content: syntaxErr.Message,StartPosition: &storepb.Position{- Line: int32(syntaxErr.Line),- Column: int32(syntaxErr.Column),+ Line: int32(syntaxErr.Position.GetLine()),+ Column: int32(syntaxErr.Position.GetColumn()),},},}@@ -317,8 +317,8 @@ func mssqlSyntaxCheck(statement string) (any, []*storepb.Advice) {Title: SyntaxErrorTitle,Content: syntaxErr.Message,StartPosition: &storepb.Position{- Line: int32(syntaxErr.Line),- Column: int32(syntaxErr.Column),+ Line: int32(syntaxErr.Position.GetLine()),+ Column: int32(syntaxErr.Position.GetColumn()),},},}@@ -351,8 +351,8 @@ func snowflakeSyntaxCheck(statement string) (any, []*storepb.Advice) {Title: SyntaxErrorTitle,Content: syntaxErr.Message,StartPosition: &storepb.Position{- Line: int32(syntaxErr.Line),- Column: int32(syntaxErr.Column),+ Line: int32(syntaxErr.Position.GetLine()),+ Column: int32(syntaxErr.Position.GetColumn()),},},}@@ -384,8 +384,8 @@ func oracleSyntaxCheck(statement string) (any, []*storepb.Advice) {Title: SyntaxErrorTitle,Content: syntaxErr.Message,StartPosition: &storepb.Position{- Line: int32(syntaxErr.Line),- Column: int32(syntaxErr.Column),+ Line: int32(syntaxErr.Position.GetLine()),+ Column: int32(syntaxErr.Position.GetColumn()),},},}@@ -477,8 +477,8 @@ func mysqlSyntaxCheck(statement string) (any, []*storepb.Advice) {Title: SyntaxErrorTitle,Content: syntaxErr.Message,StartPosition: &storepb.Position{- Line: int32(syntaxErr.Line),- Column: int32(syntaxErr.Column),+ Line: int32(syntaxErr.Position.GetLine()),+ Column: int32(syntaxErr.Position.GetColumn()),},},}diff --git a/backend/plugin/parser/base/base.go b/backend/plugin/parser/base/base.goindex bc583b2662..a90a3da831 100644--- a/backend/plugin/parser/base/base.go+++ b/backend/plugin/parser/base/base.go@@ -4,6 +4,9 @@ import ("fmt""github.com/antlr4-go/antlr/v4"++ "github.com/bytebase/bytebase/backend/common"+ storepb "github.com/bytebase/bytebase/proto/generated-go/store")// SingleSQL is a separate SQL split from multi-SQL.@@ -39,8 +42,7 @@ type SingleSQL struct {// SyntaxError is a syntax error.type SyntaxError struct {- Line int- Column int+ Position *storepb.PositionMessage stringRawMessage string}@@ -52,32 +54,54 @@ func (e *SyntaxError) Error() string {// ParseErrorListener is a custom error listener for PLSQL parser.type ParseErrorListener struct {- BaseLine int- Err *SyntaxError+ BaseLine int+ Err *SyntaxError+ Statement string}// SyntaxError returns the errors.func (l *ParseErrorListener) SyntaxError(_ antlr.Recognizer, token any, line, column int, message string, _ antlr.RecognitionException) {- if l.Err == nil {- errMessage := ""- if token, ok := token.(*antlr.CommonToken); ok {- stream := token.GetInputStream()- start := token.GetStart() - 40- if start < 0 {- start = 0- }- stop := token.GetStop()- if stop >= stream.Size() {- stop = stream.Size() - 1- }- errMessage = fmt.Sprintf("related text: %s", stream.GetTextFromInterval(antlr.NewInterval(start, stop)))+ if l.Err != nil {+ return+ }++ errMessage := ""+ if token, ok := token.(*antlr.CommonToken); ok {+ stream := token.GetInputStream()+ start := token.GetStart() - 40+ if start < 0 {+ start = 0+ }+ stop := token.GetStop()+ if stop >= stream.Size() {+ stop = stream.Size() - 1}+ errMessage = fmt.Sprintf("related text: %s", stream.GetTextFromInterval(antlr.NewInterval(start, stop)))+ }+ if l.Statement == "" {l.Err = &SyntaxError{- Line: line + l.BaseLine,- Column: column,- Message: fmt.Sprintf("Syntax error at line %d:%d \n%s", line+l.BaseLine, column, errMessage),+ Position: &storepb.Position{+ Line: int32(line + l.BaseLine),+ Column: int32(column),+ },RawMessage: message,+ Message: fmt.Sprintf("Syntax error at line %d:%d \n%s", line+l.BaseLine, column, errMessage),}+ return+ }++ p := common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{+ Line: int32(line),+ Column: int32(column),+ }, l.Statement)+ p.Line += int32(l.BaseLine)+ l.Err = &SyntaxError{+ Position: &storepb.Position{+ Line: p.Line,+ Column: p.Column,+ },+ RawMessage: message,+ Message: fmt.Sprintf("Syntax error at line %d:%d \n%s", p.Line, p.Column, errMessage),}}diff --git a/backend/plugin/parser/base/diagnose.go b/backend/plugin/parser/base/diagnose.goindex 1e9cce51d5..a822b1edd9 100644--- a/backend/plugin/parser/base/diagnose.go+++ b/backend/plugin/parser/base/diagnose.go@@ -1,6 +1,10 @@package base-import lsp "github.com/bytebase/lsp-protocol"+import (+ lsp "github.com/bytebase/lsp-protocol"++ "github.com/bytebase/bytebase/backend/common"+)// DiagnosticContext is the context for diagnosing SQL statements.type DiagnoseContext struct {@@ -8,25 +12,23 @@ type DiagnoseContext struct {type Diagnostic = lsp.Diagnostic-func ConvertSyntaxErrorToDiagnostic(err *SyntaxError) Diagnostic {+func ConvertSyntaxErrorToDiagnostic(err *SyntaxError, statement string) Diagnostic {+ start := *common.ConvertPositionToUTF16Position(err.Position, statement)+ end := start+ end.Character+++ message := err.Message+ if err.RawMessage != "" {+ // Use RawMessage which created by antlr runtime, do not need our fine-tuned message+ // because we had indicated the error position in the message.+ message = err.RawMessage+ }return Diagnostic{Range: lsp.Range{- Start: lsp.Position{- // Convert to zero-based.- Line: uint32(err.Line) - 1,- Character: uint32(err.Column),- },- End: lsp.Position{- // Convert to zero-based.- Line: uint32(err.Line) - 1,- // The end position is exclusive.- Character: uint32(err.Column) + 1,- },+ Start: start,+ End: end,},Severity: lsp.SeverityError,Source: "Syntax check",- // Use RawMessage which created by antlr runtime, do not need our fine-tuned message- // because we had indicated the error position in the message.- Message: err.RawMessage,+ Message: message,}}diff --git a/backend/plugin/parser/bigquery/bigquery.go b/backend/plugin/parser/bigquery/bigquery.goindex 9e7b285d4e..cac117eb7d 100644--- a/backend/plugin/parser/bigquery/bigquery.go+++ b/backend/plugin/parser/bigquery/bigquery.go@@ -26,11 +26,15 @@ func ParseBigQuerySQL(statement string) (*ParseResult, error) {// Remove default error listener and add our own error listener.lexer.RemoveErrorListeners()- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.AddErrorListener(lexerErrorListener)p.RemoveErrorListeners()- parserErrorListener := &base.ParseErrorListener{}+ parserErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }p.AddErrorListener(parserErrorListener)p.BuildParseTrees = truediff --git a/backend/plugin/parser/bigquery/dignose.go b/backend/plugin/parser/bigquery/dignose.goindex e3d40ba5bd..3c82042057 100644--- a/backend/plugin/parser/bigquery/dignose.go+++ b/backend/plugin/parser/bigquery/dignose.go@@ -20,7 +20,7 @@ func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]badiagnostics := make([]base.Diagnostic, 0)syntaxError := parseGoogleSQLStatement(statement)if syntaxError != nil {- diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(syntaxError))+ diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(syntaxError, statement))}return diagnostics, nil@@ -39,13 +39,13 @@ func parseGoogleSQLStatement(statement string) *base.SyntaxError {p := parser.NewGoogleSQLParser(stream)lexerErrorListener := &base.ParseErrorListener{- BaseLine: 0,+ Statement: statement,}lexer.RemoveErrorListeners()lexer.AddErrorListener(lexerErrorListener)parserErrorListener := &base.ParseErrorListener{- BaseLine: 0,+ Statement: statement,}p.RemoveErrorListeners()p.AddErrorListener(parserErrorListener)diff --git a/backend/plugin/parser/bigquery/query_span_test.go b/backend/plugin/parser/bigquery/query_span_test.goindex ad43ebbd86..e03fdf074d 100644--- a/backend/plugin/parser/bigquery/query_span_test.go+++ b/backend/plugin/parser/bigquery/query_span_test.go@@ -133,11 +133,15 @@ func TestGetPossibleColumnResources(t *testing.T) {p := parser.NewGoogleSQLParser(stream)// Remove default error listener and add our own error listener.lexer.RemoveErrorListeners()- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: tc.inputExpr,+ }lexer.AddErrorListener(lexerErrorListener)p.RemoveErrorListeners()- parserErrorListener := &base.ParseErrorListener{}+ parserErrorListener := &base.ParseErrorListener{+ Statement: tc.inputExpr,+ }p.AddErrorListener(parserErrorListener)p.BuildParseTrees = truediff --git a/backend/plugin/parser/cosmosdb/cosmosdb.go b/backend/plugin/parser/cosmosdb/cosmosdb.goindex 40b0312ee9..bdfc38b51f 100644--- a/backend/plugin/parser/cosmosdb/cosmosdb.go+++ b/backend/plugin/parser/cosmosdb/cosmosdb.go@@ -17,11 +17,15 @@ func ParseCosmosDBQuery(statement string) ([]*ParseResult, error) {stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)p := parser.NewCosmosDBParser(stream)- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.RemoveErrorListeners()lexer.AddErrorListener(lexerErrorListener)- parserErrorListener := &base.ParseErrorListener{}+ parserErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }p.RemoveErrorListeners()p.AddErrorListener(parserErrorListener)diff --git a/backend/plugin/parser/elasticsearch/diagnose.go b/backend/plugin/parser/elasticsearch/diagnose.goindex f2351d5db7..de862d383f 100644--- a/backend/plugin/parser/elasticsearch/diagnose.go+++ b/backend/plugin/parser/elasticsearch/diagnose.go@@ -5,6 +5,7 @@ import (lsp "github.com/bytebase/lsp-protocol"+ "github.com/bytebase/bytebase/backend/common""github.com/bytebase/bytebase/backend/plugin/parser/base""github.com/bytebase/bytebase/proto/generated-go/store")@@ -22,19 +23,13 @@ func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]bafor _, err := range parseResult.Errors {if err != nil {// TODO(zp): unify the position in diagnose.+ start := *common.ConvertPositionToUTF16Position(err.Position, statement)+ end := start+ end.Character++diagnostics = append(diagnostics, base.Diagnostic{Range: lsp.Range{- Start: lsp.Position{- // Convert to zero-based.- Line: uint32(err.Line),- Character: uint32(err.Column),- },- End: lsp.Position{- // Convert to zero-based.- Line: uint32(err.Line),- // The end position is exclusive.- Character: uint32(err.Column) + 1,- },+ Start: start,+ End: end,},Severity: lsp.SeverityError,Source: "Syntax check",diff --git a/backend/plugin/parser/elasticsearch/parser.go b/backend/plugin/parser/elasticsearch/parser.goindex c2df768c59..73c3007a2e 100644--- a/backend/plugin/parser/elasticsearch/parser.go+++ b/backend/plugin/parser/elasticsearch/parser.go@@ -12,6 +12,7 @@ import ("github.com/pkg/errors""github.com/bytebase/bytebase/backend/plugin/parser/base"+ storepb "github.com/bytebase/bytebase/proto/generated-go/store")type ParseResult struct {@@ -205,8 +206,8 @@ func ParseElasticsearchREST(text string) (*ParseResult, error) {column := 0pos := 0if i > 0 {- line = syntaxErrors[i-1].Line- column = syntaxErrors[i-1].Column+ line = int(syntaxErrors[i-1].Position.Line)+ column = int(syntaxErrors[i-1].Position.Column)pos = p.errors[i-1].byteOffset}boundary := p.errors[i].byteOffset@@ -228,8 +229,10 @@ func ParseElasticsearchREST(text string) (*ParseResult, error) {}}syntaxErrors = append(syntaxErrors, &base.SyntaxError{- Line: line,- Column: column,+ Position: &storepb.Position{+ Line: int32(line),+ Column: int32(column),+ },Message: err.message,})}diff --git a/backend/plugin/parser/elasticsearch/test-data/parse-elasticsearch-rest.yaml b/backend/plugin/parser/elasticsearch/test-data/parse-elasticsearch-rest.yamlindex a83392cfc7..2d542804bb 100644--- a/backend/plugin/parser/elasticsearch/test-data/parse-elasticsearch-rest.yaml+++ b/backend/plugin/parser/elasticsearch/test-data/parse-elasticsearch-rest.yaml@@ -13,8 +13,9 @@startoffset: 292endoffset: 319errors:- - line: 2- column: 2+ - position:+ line: 2+ column: 2message: expected one of GET/POST/PUT/DELETE/HEAD/PATCHrawmessage: ""- description: simplediff --git a/backend/plugin/parser/mysql/completion.go b/backend/plugin/parser/mysql/completion.goindex 9742b888eb..bec7fb122b 100644--- a/backend/plugin/parser/mysql/completion.go+++ b/backend/plugin/parser/mysql/completion.go@@ -1259,7 +1259,9 @@ func skipHeadingSQLWithoutSemicolon(statement string, caretLine int, caretOffsetlexer := mysql.NewMySQLLexer(input)stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)lexer.RemoveErrorListeners()- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.AddErrorListener(lexerErrorListener)stream.Fill()diff --git a/backend/plugin/parser/mysql/diagnose.go b/backend/plugin/parser/mysql/diagnose.goindex 1f3219f48a..4683a78e67 100644--- a/backend/plugin/parser/mysql/diagnose.go+++ b/backend/plugin/parser/mysql/diagnose.go@@ -26,7 +26,7 @@ func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]badiagnostics := make([]base.Diagnostic, 0)syntaxError := parseMySQLStatement(statement)if syntaxError != nil {- diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(syntaxError))+ diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(syntaxError, statement))}return diagnostics, nil@@ -45,13 +45,15 @@ func parseMySQLStatement(statement string) *base.SyntaxError {p := parser.NewMySQLParser(stream)lexerErrorListener := &base.ParseErrorListener{- BaseLine: 0,+ Statement: statement,+ BaseLine: 0,}lexer.RemoveErrorListeners()lexer.AddErrorListener(lexerErrorListener)parserErrorListener := &base.ParseErrorListener{- BaseLine: 0,+ Statement: statement,+ BaseLine: 0,}p.RemoveErrorListeners()p.AddErrorListener(parserErrorListener)diff --git a/backend/plugin/parser/mysql/mysql.go b/backend/plugin/parser/mysql/mysql.goindex d1111d166c..b296eaefee 100644--- a/backend/plugin/parser/mysql/mysql.go+++ b/backend/plugin/parser/mysql/mysql.go@@ -180,7 +180,9 @@ func parseSingleStatement(baseLine int, statement string) (antlr.Tree, *antlr.Cofunc mysqlAddSemicolonIfNeeded(sql string) string {lexer := parser.NewMySQLLexer(antlr.NewInputStream(sql))- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: sql,+ }lexer.RemoveErrorListeners()lexer.AddErrorListener(lexerErrorListener)stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)diff --git a/backend/plugin/parser/mysql/split.go b/backend/plugin/parser/mysql/split.goindex 2ccec5ed6e..ad3eb384e7 100644--- a/backend/plugin/parser/mysql/split.go+++ b/backend/plugin/parser/mysql/split.go@@ -28,7 +28,7 @@ func SplitSQL(statement string) ([]base.SingleSQL, error) {if err != nil {slog.Info("failed to split MySQL statement, use parser instead", "statement", statement)// Use parser to split statement.- return splitByParser(lexer, stream)+ return splitByParser(statement, lexer, stream)}return list, nil}@@ -162,13 +162,17 @@ func hasDelimiterStatement(stream *antlr.CommonTokenStream) bool {return false}-func splitByParser(lexer *parser.MySQLLexer, stream *antlr.CommonTokenStream) ([]base.SingleSQL, error) {+func splitByParser(statement string, lexer *parser.MySQLLexer, stream *antlr.CommonTokenStream) ([]base.SingleSQL, error) {p := parser.NewMySQLParser(stream)- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.RemoveErrorListeners()lexer.AddErrorListener(lexerErrorListener)- parserErrorListener := &base.ParseErrorListener{}+ parserErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }p.RemoveErrorListeners()p.AddErrorListener(parserErrorListener)diff --git a/backend/plugin/parser/partiql/completion.go b/backend/plugin/parser/partiql/completion.goindex 99d2540cf2..0775864686 100644--- a/backend/plugin/parser/partiql/completion.go+++ b/backend/plugin/parser/partiql/completion.go@@ -488,7 +488,9 @@ func skipHeadingSQLWithoutSemicolon(statement string, caretLine int, caretOffsetlexer := partiqlparser.NewPartiQLLexer(input)stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)lexer.RemoveErrorListeners()- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.AddErrorListener(lexerErrorListener)stream.Fill()diff --git a/backend/plugin/parser/partiql/partiql.go b/backend/plugin/parser/partiql/partiql.goindex 2b73932c9f..b04087ab3d 100644--- a/backend/plugin/parser/partiql/partiql.go+++ b/backend/plugin/parser/partiql/partiql.go@@ -26,11 +26,15 @@ func ParsePartiQL(statement string) (*ParseResult, error) {// Remove default error listener and add our own error listener.lexer.RemoveErrorListeners()- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.AddErrorListener(lexerErrorListener)p.RemoveErrorListeners()- parserErrorListener := &base.ParseErrorListener{}+ parserErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }p.AddErrorListener(parserErrorListener)p.BuildParseTrees = truediff --git a/backend/plugin/parser/partiql/split.go b/backend/plugin/parser/partiql/split.goindex 3bb5555756..688eb3554d 100644--- a/backend/plugin/parser/partiql/split.go+++ b/backend/plugin/parser/partiql/split.go@@ -16,14 +16,18 @@ func init() {func SplitSQL(statement string) ([]base.SingleSQL, error) {lexer := parser.NewPartiQLLexer(antlr.NewInputStream(statement))- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.RemoveErrorListeners()lexer.AddErrorListener(lexerErrorListener)stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)p := parser.NewPartiQLParserParser(stream)- parserErrorListener := &base.ParseErrorListener{}+ parserErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }p.RemoveErrorListeners()p.AddErrorListener(parserErrorListener)diff --git a/backend/plugin/parser/pg/completion.go b/backend/plugin/parser/pg/completion.goindex 06fe1d1ce2..a4b179e279 100644--- a/backend/plugin/parser/pg/completion.go+++ b/backend/plugin/parser/pg/completion.go@@ -1222,7 +1222,9 @@ func skipHeadingSQLWithoutSemicolon(statement string, caretLine int, caretOffsetlexer := pg.NewPostgreSQLLexer(input)stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)lexer.RemoveErrorListeners()- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.AddErrorListener(lexerErrorListener)stream.Fill()diff --git a/backend/plugin/parser/pg/diagnose.go b/backend/plugin/parser/pg/diagnose.goindex 40d95f0b53..155f88c0d2 100644--- a/backend/plugin/parser/pg/diagnose.go+++ b/backend/plugin/parser/pg/diagnose.go@@ -23,7 +23,7 @@ func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]badiagnostics := make([]base.Diagnostic, 0)syntaxError := parsePostgreSQLStatement(statement)if syntaxError != nil {- diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(syntaxError))+ diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(syntaxError, statement))}return diagnostics, nil@@ -41,12 +41,15 @@ func parsePostgreSQLStatement(statement string) *base.SyntaxError {lexer := parser.NewPostgreSQLLexer(antlr.NewInputStream(statement))stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)p := parser.NewPostgreSQLParser(stream)- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.RemoveErrorListeners()lexer.AddErrorListener(lexerErrorListener)parserErrorListener := &base.ParseErrorListener{- BaseLine: 0,+ Statement: statement,+ BaseLine: 0,}p.RemoveErrorListeners()p.AddErrorListener(parserErrorListener)diff --git a/backend/plugin/parser/pg/pg.go b/backend/plugin/parser/pg/pg.goindex 49c184836b..aae5ea5d72 100644--- a/backend/plugin/parser/pg/pg.go+++ b/backend/plugin/parser/pg/pg.go@@ -20,11 +20,15 @@ func ParsePostgreSQL(sql string) (*ParseResult, error) {lexer := parser.NewPostgreSQLLexer(antlr.NewInputStream(sql))stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)p := parser.NewPostgreSQLParser(stream)- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: sql,+ }lexer.RemoveErrorListeners()lexer.AddErrorListener(lexerErrorListener)- parserErrorListener := &base.ParseErrorListener{}+ parserErrorListener := &base.ParseErrorListener{+ Statement: sql,+ }p.RemoveErrorListeners()p.AddErrorListener(parserErrorListener)diff --git a/backend/plugin/parser/pg/pg_test.go b/backend/plugin/parser/pg/pg_test.goindex 421a99b68a..c0d84a5165 100644--- a/backend/plugin/parser/pg/pg_test.go+++ b/backend/plugin/parser/pg/pg_test.go@@ -20,7 +20,7 @@ func TestPostgreSQLParser(t *testing.T) {},{statement: "SELECT a > (select max(a) from t1) FROM",- errorMessage: "Syntax error at line 1:39 \nrelated text: SELECT a > (select max(a) from t1) FROM",+ errorMessage: "Syntax error at line 0:39 \nrelated text: SELECT a > (select max(a) from t1) FROM",},}diff --git a/backend/plugin/parser/pg/query.go b/backend/plugin/parser/pg/query.goindex 5b8e6f01f1..c0dd7400e9 100644--- a/backend/plugin/parser/pg/query.go+++ b/backend/plugin/parser/pg/query.go@@ -11,6 +11,7 @@ import (pgparser "github.com/pganalyze/pg_query_go/v6/parser""github.com/pkg/errors"+ "github.com/bytebase/bytebase/backend/common""github.com/bytebase/bytebase/backend/common/log""github.com/bytebase/bytebase/backend/plugin/parser/base""github.com/bytebase/bytebase/backend/plugin/parser/sql/ast"@@ -197,32 +198,18 @@ func extractRangeVarFromJSON(currentDatabase string, currentSchema string, jsonDfunc convertToSyntaxError(statement string, err error) *base.SyntaxError {if pgErr, ok := err.(*pgparser.Error); ok {- line, column := getLineAndColumn(statement, pgErr.Cursorpos)+ position := common.ConvertPGParserErrorCursorPosToPosition(pgErr.Cursorpos, statement)return &base.SyntaxError{- Line: line,- Column: column,- Message: pgErr.Message,+ Position: position,+ Message: pgErr.Message,}}return &base.SyntaxError{- Line: 1,- Column: 0,+ Position: &storepb.Position{+ Line: 0,+ Column: 0,+ },Message: err.Error(),}}--func getLineAndColumn(statement string, pos int) (int, int) {- var line, column int- runes := []rune(statement)- for i := 0; i < pos && i < len(runes); i++ {- if runes[i] == '\n' {- line++- column = 0- } else {- column++- }- }-- return line + 1, column-}diff --git a/backend/plugin/parser/pg/split.go b/backend/plugin/parser/pg/split.goindex a84007efc3..383173e3c3 100644--- a/backend/plugin/parser/pg/split.go+++ b/backend/plugin/parser/pg/split.go@@ -27,18 +27,22 @@ func SplitSQL(statement string) ([]base.SingleSQL, error) {if err != nil {slog.Info("failed to split PostgreSQL statement", "statement", statement)// Use parser to split statement.- return splitByParser(lexer, stream)+ return splitByParser(statement, lexer, stream)}return list, nil}-func splitByParser(lexer *parser.PostgreSQLLexer, stream *antlr.CommonTokenStream) ([]base.SingleSQL, error) {+func splitByParser(statement string, lexer *parser.PostgreSQLLexer, stream *antlr.CommonTokenStream) ([]base.SingleSQL, error) {p := parser.NewPostgreSQLParser(stream)- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.RemoveErrorListeners()lexer.AddErrorListener(lexerErrorListener)- parserErrorListener := &base.ParseErrorListener{}+ parserErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }p.RemoveErrorListeners()p.AddErrorListener(parserErrorListener)diff --git a/backend/plugin/parser/plsql/completion.go b/backend/plugin/parser/plsql/completion.goindex a924d3e764..31b9090e4d 100644--- a/backend/plugin/parser/plsql/completion.go+++ b/backend/plugin/parser/plsql/completion.go@@ -1148,7 +1148,9 @@ func skipHeadingSQLWithoutSemicolon(statement string, caretLine int, caretOffsetlexer := plsql.NewPlSqlLexer(input)stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)lexer.RemoveErrorListeners()- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.AddErrorListener(lexerErrorListener)stream.Fill()diff --git a/backend/plugin/parser/plsql/diagnose.go b/backend/plugin/parser/plsql/diagnose.goindex 5b2478a841..a6239494df 100644--- a/backend/plugin/parser/plsql/diagnose.go+++ b/backend/plugin/parser/plsql/diagnose.go@@ -22,7 +22,7 @@ func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]badiagnostics := make([]base.Diagnostic, 0)syntaxError := parsePLSQLStatement(statement)if syntaxError != nil {- diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(syntaxError))+ diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(syntaxError, statement))}return diagnostics, nil@@ -42,11 +42,15 @@ func parsePLSQLStatement(statement string) *base.SyntaxError {p := parser.NewPlSqlParser(stream)p.SetVersion12(true)- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.RemoveErrorListeners()lexer.AddErrorListener(lexerErrorListener)- parserErrorListener := &base.ParseErrorListener{}+ parserErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }p.RemoveErrorListeners()p.AddErrorListener(parserErrorListener)diff --git a/backend/plugin/parser/plsql/plsql.go b/backend/plugin/parser/plsql/plsql.goindex 4f2f3d0c38..b14a66d644 100644--- a/backend/plugin/parser/plsql/plsql.go+++ b/backend/plugin/parser/plsql/plsql.go@@ -54,11 +54,15 @@ func ParsePLSQL(sql string) (antlr.Tree, *antlr.CommonTokenStream, error) {p := parser.NewPlSqlParser(stream)p.SetVersion12(true)- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: sql,+ }lexer.RemoveErrorListeners()lexer.AddErrorListener(lexerErrorListener)- parserErrorListener := &base.ParseErrorListener{}+ parserErrorListener := &base.ParseErrorListener{+ Statement: sql,+ }p.RemoveErrorListeners()p.AddErrorListener(parserErrorListener)diff --git a/backend/plugin/parser/plsql/plsql_test.go b/backend/plugin/parser/plsql/plsql_test.goindex 2ff2378803..907dc74c59 100644--- a/backend/plugin/parser/plsql/plsql_test.go+++ b/backend/plugin/parser/plsql/plsql_test.go@@ -34,7 +34,7 @@ func TestPLSQLParser(t *testing.T) {},{statement: "SELECT * FROM t1 WHERE c1 = ",- errorMessage: "Syntax error at line 1:26 \nrelated text: SELECT * FROM t1 WHERE c1 =",+ errorMessage: "Syntax error at line 0:26 \nrelated text: SELECT * FROM t1 WHERE c1 =",},}diff --git a/backend/plugin/parser/snowflake/diagnose.go b/backend/plugin/parser/snowflake/diagnose.goindex c6876e9bfa..14c41e346b 100644--- a/backend/plugin/parser/snowflake/diagnose.go+++ b/backend/plugin/parser/snowflake/diagnose.go@@ -20,7 +20,7 @@ func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]badiagnostics := make([]base.Diagnostic, 0)syntaxError := parseSnowflakeStatement(statement)if syntaxError != nil {- diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(syntaxError))+ diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(syntaxError, statement))}return diagnostics, nil@@ -39,13 +39,15 @@ func parseSnowflakeStatement(statement string) *base.SyntaxError {p := parser.NewSnowflakeParser(stream)lexerErrorListener := &base.ParseErrorListener{- BaseLine: 0,+ Statement: statement,+ BaseLine: 0,}lexer.RemoveErrorListeners()lexer.AddErrorListener(lexerErrorListener)parserErrorListener := &base.ParseErrorListener{- BaseLine: 0,+ Statement: statement,+ BaseLine: 0,}p.RemoveErrorListeners()p.AddErrorListener(parserErrorListener)diff --git a/backend/plugin/parser/snowflake/snowflake.go b/backend/plugin/parser/snowflake/snowflake.goindex 2c5533e9fe..1b1fcf935d 100644--- a/backend/plugin/parser/snowflake/snowflake.go+++ b/backend/plugin/parser/snowflake/snowflake.go@@ -26,11 +26,15 @@ func ParseSnowSQL(statement string) (*ParseResult, error) {// Remove default error listener and add our own error listener.lexer.RemoveErrorListeners()- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.AddErrorListener(lexerErrorListener)p.RemoveErrorListeners()- parserErrorListener := &base.ParseErrorListener{}+ parserErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }p.AddErrorListener(parserErrorListener)p.BuildParseTrees = truediff --git a/backend/plugin/parser/snowflake/snowflake_test.go b/backend/plugin/parser/snowflake/snowflake_test.goindex da2818b188..d8d08f8a76 100644--- a/backend/plugin/parser/snowflake/snowflake_test.go+++ b/backend/plugin/parser/snowflake/snowflake_test.go@@ -48,11 +48,7 @@ func TestParseSnowSQL(t *testing.T) {}{{sql: `SELECT t.a, t.b FRO table_name t;`,- err: "Syntax error at line 1:31 \nrelated text: SELECT t.a, t.b FRO table_name t",- },- {- sql: `SELECT t.a, t.b FROM table_name }t;`,- err: "Syntax error at line 1:32 \nrelated text: SELECT t.a, t.b FROM table_name }",+ err: "Syntax error at line 0:31 \nrelated text: SELECT t.a, t.b FRO table_name t",},}diff --git a/backend/plugin/parser/spanner/dignose.go b/backend/plugin/parser/spanner/dignose.goindex c1b7f06dca..86eb96b5cf 100644--- a/backend/plugin/parser/spanner/dignose.go+++ b/backend/plugin/parser/spanner/dignose.go@@ -20,7 +20,7 @@ func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]badiagnostics := make([]base.Diagnostic, 0)syntaxError := parseGoogleSQLStatement(statement)if syntaxError != nil {- diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(syntaxError))+ diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(syntaxError, statement))}return diagnostics, nil@@ -39,13 +39,15 @@ func parseGoogleSQLStatement(statement string) *base.SyntaxError {p := parser.NewGoogleSQLParser(stream)lexerErrorListener := &base.ParseErrorListener{- BaseLine: 0,+ Statement: statement,+ BaseLine: 0,}lexer.RemoveErrorListeners()lexer.AddErrorListener(lexerErrorListener)parserErrorListener := &base.ParseErrorListener{- BaseLine: 0,+ Statement: statement,+ BaseLine: 0,}p.RemoveErrorListeners()p.AddErrorListener(parserErrorListener)diff --git a/backend/plugin/parser/spanner/query_span_test.go b/backend/plugin/parser/spanner/query_span_test.goindex b8c07a74a5..fc861b12c4 100644--- a/backend/plugin/parser/spanner/query_span_test.go+++ b/backend/plugin/parser/spanner/query_span_test.go@@ -133,11 +133,15 @@ func TestGetPossibleColumnResources(t *testing.T) {p := parser.NewGoogleSQLParser(stream)// Remove default error listener and add our own error listener.lexer.RemoveErrorListeners()- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: tc.inputExpr,+ }lexer.AddErrorListener(lexerErrorListener)p.RemoveErrorListeners()- parserErrorListener := &base.ParseErrorListener{}+ parserErrorListener := &base.ParseErrorListener{+ Statement: tc.inputExpr,+ }p.AddErrorListener(parserErrorListener)p.BuildParseTrees = truediff --git a/backend/plugin/parser/spanner/spanner.go b/backend/plugin/parser/spanner/spanner.goindex 8a910a537b..48818be14f 100644--- a/backend/plugin/parser/spanner/spanner.go+++ b/backend/plugin/parser/spanner/spanner.go@@ -26,11 +26,15 @@ func ParseSpannerGoogleSQL(statement string) (*ParseResult, error) {// Remove default error listener and add our own error listener.lexer.RemoveErrorListeners()- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.AddErrorListener(lexerErrorListener)p.RemoveErrorListeners()- parserErrorListener := &base.ParseErrorListener{}+ parserErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }p.AddErrorListener(parserErrorListener)p.BuildParseTrees = truediff --git a/backend/plugin/parser/tidb/tidb.go b/backend/plugin/parser/tidb/tidb.goindex a992033da5..b1145fee70 100644--- a/backend/plugin/parser/tidb/tidb.go+++ b/backend/plugin/parser/tidb/tidb.go@@ -18,6 +18,7 @@ import (parser "github.com/bytebase/tidb-parser"+ "github.com/bytebase/bytebase/backend/common""github.com/bytebase/bytebase/backend/plugin/parser/base""github.com/bytebase/bytebase/backend/plugin/parser/tokenizer")@@ -65,13 +66,15 @@ func parseSingleStatement(baseLine int, statement string) (antlr.Tree, *antlr.Cop := parser.NewTiDBParser(stream)lexerErrorListener := &base.ParseErrorListener{- BaseLine: baseLine,+ Statement: statement,+ BaseLine: baseLine,}lexer.RemoveErrorListeners()lexer.AddErrorListener(lexerErrorListener)parserErrorListener := &base.ParseErrorListener{- BaseLine: baseLine,+ Statement: statement,+ BaseLine: baseLine,}p.RemoveErrorListeners()p.AddErrorListener(parserErrorListener)@@ -225,9 +228,8 @@ func convertParserError(parserErr error) error {return parserErr}return &base.SyntaxError{- Line: line,- Column: column,- Message: parserErr.Error(),+ Position: common.ConvertTiDBParserErrorPositionToPosition(line, column),+ Message: parserErr.Error(),}}@@ -300,7 +302,9 @@ func TypeString(tp byte) string {func tidbAddSemicolonIfNeeded(sql string) string {lexer := parser.NewTiDBLexer(antlr.NewInputStream(sql))- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: sql,+ }lexer.RemoveErrorListeners()lexer.AddErrorListener(lexerErrorListener)stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)diff --git a/backend/plugin/parser/tidb/tidb_test.go b/backend/plugin/parser/tidb/tidb_test.goindex 86a7907c6c..1c6d04bbe5 100644--- a/backend/plugin/parser/tidb/tidb_test.go+++ b/backend/plugin/parser/tidb/tidb_test.go@@ -115,11 +115,11 @@ func TestMySQLCreateTableSetLine(t *testing.T) {}func TestTiDBParserError(t *testing.T) {- _, err := ParseTiDB("SELECT hello TO world;", "", "")+ _, err := ParseTiDB("SELECT 𝄞𝄞hello TO world;", "", "")require.Error(t, err)syntaxErr, ok := err.(*base.SyntaxError)require.True(t, ok)- require.Equal(t, 1, syntaxErr.Line)- require.Equal(t, 15, syntaxErr.Column)- require.Equal(t, `line 1 column 15 near "TO world;" `, syntaxErr.Message)+ require.Equal(t, int32(0), syntaxErr.Position.GetLine())+ require.Equal(t, int32(22), syntaxErr.Position.GetColumn())+ require.Equal(t, `line 1 column 23 near "TO world;" `, syntaxErr.Message)}diff --git a/backend/plugin/parser/tsql/completion.go b/backend/plugin/parser/tsql/completion.goindex 1d5a9660f9..c0c02feca2 100644--- a/backend/plugin/parser/tsql/completion.go+++ b/backend/plugin/parser/tsql/completion.go@@ -594,7 +594,9 @@ func skipHeadingSQLWithoutSemicolon(statement string, caretLine int, caretOffsetlexer := tsqlparser.NewTSqlLexer(input)stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)lexer.RemoveErrorListeners()- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.AddErrorListener(lexerErrorListener)stream.Fill()diff --git a/backend/plugin/parser/tsql/diagnose.go b/backend/plugin/parser/tsql/diagnose.goindex f80a2448cd..f2065ee281 100644--- a/backend/plugin/parser/tsql/diagnose.go+++ b/backend/plugin/parser/tsql/diagnose.go@@ -20,7 +20,7 @@ func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]badiagnostics := make([]base.Diagnostic, 0)syntaxError := parseTSQLStatement(statement)if syntaxError != nil {- diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(syntaxError))+ diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(syntaxError, statement))}return diagnostics, nil@@ -39,13 +39,15 @@ func parseTSQLStatement(statement string) *base.SyntaxError {p := parser.NewTSqlParser(stream)lexerErrorListener := &base.ParseErrorListener{- BaseLine: 0,+ Statement: statement,+ BaseLine: 0,}lexer.RemoveErrorListeners()lexer.AddErrorListener(lexerErrorListener)parserErrorListener := &base.ParseErrorListener{- BaseLine: 0,+ Statement: statement,+ BaseLine: 0,}p.RemoveErrorListeners()p.AddErrorListener(parserErrorListener)diff --git a/backend/plugin/parser/tsql/split.go b/backend/plugin/parser/tsql/split.goindex 84009a1ebf..5fa4d7a586 100644--- a/backend/plugin/parser/tsql/split.go+++ b/backend/plugin/parser/tsql/split.go@@ -40,11 +40,15 @@ func splitByParser(statement string) ([]base.SingleSQL, error) {// Remove default error listener and add our own error listener.lexer.RemoveErrorListeners()- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.AddErrorListener(lexerErrorListener)p.RemoveErrorListeners()- parserErrorListener := &base.ParseErrorListener{}+ parserErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }p.AddErrorListener(parserErrorListener)p.BuildParseTrees = truediff --git a/backend/plugin/parser/tsql/tsql.go b/backend/plugin/parser/tsql/tsql.goindex 9e1d30b745..f4d090b558 100644--- a/backend/plugin/parser/tsql/tsql.go+++ b/backend/plugin/parser/tsql/tsql.go@@ -26,11 +26,15 @@ func ParseTSQL(statement string) (*ParseResult, error) {// Remove default error listener and add our own error listener.lexer.RemoveErrorListeners()- lexerErrorListener := &base.ParseErrorListener{}+ lexerErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }lexer.AddErrorListener(lexerErrorListener)p.RemoveErrorListeners()- parserErrorListener := &base.ParseErrorListener{}+ parserErrorListener := &base.ParseErrorListener{+ Statement: statement,+ }p.AddErrorListener(parserErrorListener)p.BuildParseTrees = true