fix: sub entities should not be considered as nerestCaretEntities
This commit is contained in:
parent
68d04deafc
commit
c889392d0d
@ -12,7 +12,7 @@
|
||||
<script type="module">
|
||||
const { DtSqlParserSemAnalysePlugin } = await import(/* @vite-ignore */import.meta.env.VITE_ENTRY_PATH)
|
||||
const myPlugin = new DtSqlParserSemAnalysePlugin()
|
||||
const sql = 'SELECT a.| AS c'
|
||||
const sql = 'INSERT INTO |'
|
||||
const caretColumn = sql.indexOf('|') + 1
|
||||
const result = myPlugin.parse(sql.replace('|', ''), { lineNumber: 1, columnNumber: caretColumn })
|
||||
console.log(result)
|
||||
|
@ -2,23 +2,25 @@ import { PostgreSqlParser } from 'dt-sql-parser/dist/lib/postgresql/PostgreSqlPa
|
||||
|
||||
export const defaultAlias = {
|
||||
selectstmt: 'selectStatement',
|
||||
target_el: 'target_label'
|
||||
target_el: 'target_label',
|
||||
table_name: 'tableName'
|
||||
}
|
||||
|
||||
export const defaultStmts = [
|
||||
'simple_select',
|
||||
'selectstmt',
|
||||
]
|
||||
|
||||
export const defaultEntities = [
|
||||
'target_el',
|
||||
'colid',
|
||||
'attr_name',
|
||||
'collabel'
|
||||
'collabel',
|
||||
'table_name'
|
||||
]
|
||||
|
||||
export const defaultRules: Record<string, number[]> = {
|
||||
select_target: [
|
||||
PostgreSqlParser.RULE_simple_select,
|
||||
PostgreSqlParser.RULE_selectstmt,
|
||||
PostgreSqlParser.RULE_target_el,
|
||||
],
|
||||
select_target_colid: [
|
||||
@ -35,5 +37,18 @@ export const defaultRules: Record<string, number[]> = {
|
||||
PostgreSqlParser.RULE_target_el,
|
||||
-PostgreSqlParser.RULE_attr_name,
|
||||
PostgreSqlParser.RULE_collabel
|
||||
],
|
||||
select_from_table: [
|
||||
PostgreSqlParser.RULE_selectstmt,
|
||||
PostgreSqlParser.RULE_from_clause,
|
||||
PostgreSqlParser.RULE_table_name
|
||||
],
|
||||
table_name_colid: [
|
||||
PostgreSqlParser.RULE_table_name,
|
||||
PostgreSqlParser.RULE_colid
|
||||
],
|
||||
table_name_attr: [
|
||||
PostgreSqlParser.RULE_table_name,
|
||||
PostgreSqlParser.RULE_attr_name,
|
||||
]
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ export class SQLVisitor extends AbstractParseTreeVisitor<void> implements Postgr
|
||||
if (!beginStmt.relatedEntities[rule]) beginStmt.relatedEntities[rule] = []
|
||||
beginStmt.relatedEntities[rule].push(result)
|
||||
}
|
||||
if (withCaret(ctx)) this.result.nerestCaretEntityList.push(result)
|
||||
if (beginStmt && withCaret(ctx)) this.result.nerestCaretEntityList.push(result)
|
||||
this.entityStack.push(result)
|
||||
isHitRule = true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user