@@ -390,16 +390,25 @@ export class HoverAdapter<T extends BaseSQLWorker> implements languages.HoverPro
390390 } )
391391 . then ( ( entities ) => {
392392 if ( ! entities || ! entities . length ) return null ;
393+ let isAlias = false ;
393394 const curEntity = entities . find ( ( entity : EntityContext ) => {
394395 const p = entity . position ;
396+ const alias = entity . _alias ;
397+ isAlias = ! ! (
398+ alias &&
399+ alias . startColumn <= position . column &&
400+ alias . endColumn >= position . column &&
401+ alias . line === position . lineNumber
402+ ) ;
395403 return (
396- p . startColumn <= position . column &&
397- p . endColumn >= position . column &&
398- p . line === position . lineNumber
404+ ( p . startColumn <= position . column &&
405+ p . endColumn >= position . column &&
406+ p . line === position . lineNumber ) ||
407+ isAlias
399408 ) ;
400409 } ) ;
401410 if ( ! curEntity ) return null ;
402- const tableCreate = curEntity ? findTableCreateEntity ( curEntity , entities ) : null ;
411+ const tableCreate = findTableCreateEntity ( curEntity , entities ) ;
403412 const columns = tableCreate ? toColumnsInfo ( tableCreate ) || [ ] : [ ] ;
404413 const columnsDesc = columns . reduce ( ( res , cur ) => {
405414 const { column, type, comment, alias } = cur ;
@@ -410,20 +419,30 @@ export class HoverAdapter<T extends BaseSQLWorker> implements languages.HoverPro
410419 } ${ alias ? ` *${ alias } *` : '' } \n`
411420 ) ;
412421 } , '' ) ;
413- const pos = curEntity . position ;
414- const range = new monaco . Range ( pos . line , pos . startColumn , pos . line , pos . endColumn ) ;
422+ const tableText = isAlias
423+ ? ( curEntity . _alias ?. text ?? curEntity . text )
424+ : curEntity . text ;
425+ let range : monaco . Range ;
426+ if ( isAlias && curEntity . _alias ) {
427+ range = new monaco . Range (
428+ curEntity . _alias . line ,
429+ curEntity . _alias . startColumn ,
430+ curEntity . _alias . line ,
431+ curEntity . _alias . endColumn
432+ ) ;
433+ } else {
434+ const p = curEntity . position ;
435+ range = new monaco . Range ( p . line , p . startColumn , p . line , p . endColumn ) ;
436+ }
415437 const contents : monaco . IMarkdownString [ ] = [
416- { value : `**${ curEntity . text } **` } ,
438+ { value : `**${ tableText } **` } ,
417439 { value : columnsDesc }
418440 ] ;
419441 return { contents, range } ;
420442 } ) ;
421443 }
422444}
423445
424- export function isTableCreateEntity ( en : EntityContext ) : en is CommonEntityContext {
425- return en . entityContextType === EntityContextType . TABLE_CREATE ;
426- }
427446/**
428447 * According to the table name or table entity field, get the corresponding create table information
429448 */
@@ -439,10 +458,14 @@ export function findTableCreateEntity(
439458 }
440459
441460 const tableName : string = typeof tableEntity === 'string' ? tableEntity : tableEntity . text ;
461+ function removeQuotes ( str : string ) : string {
462+ return str . replace ( / ^ [ ' " ` “ ” ‘ ’ « » ] | [ ' " ` “ ” ‘ ’ « » ] $ / g, '' ) ;
463+ }
442464 return (
443465 allEntities . find (
444466 ( en ) : en is CommonEntityContext =>
445- en . entityContextType === EntityContextType . TABLE_CREATE && en . text === tableName
467+ en . entityContextType === EntityContextType . TABLE_CREATE &&
468+ removeQuotes ( en . text ) === removeQuotes ( tableName )
446469 ) ?? null
447470 ) ;
448471}
@@ -451,9 +474,12 @@ export function findTableCreateEntity(
451474 * Transform table create entity to columns info
452475 */
453476export function toColumnsInfo ( tableEntity : CommonEntityContext ) : ColumnInfo [ ] | null {
454- if ( ! tableEntity ) return null ;
455- if ( tableEntity . entityContextType !== EntityContextType . TABLE_CREATE ) return null ;
456- if ( ! tableEntity . columns ?. length ) return null ;
477+ if (
478+ ! tableEntity ||
479+ tableEntity . entityContextType !== EntityContextType . TABLE_CREATE ||
480+ ! tableEntity . columns ?. length
481+ )
482+ return null ;
457483 const columnsInfo : ColumnInfo [ ] = [ ] ;
458484 tableEntity . columns . forEach ( ( col : ColumnEntityContext ) => {
459485 columnsInfo . push ( {
0 commit comments