Skip to content

Commit e69d187

Browse files
Fix subquery hover
1 parent 4ce66ac commit e69d187

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

internal/handler/hover.go

+15
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ func (e *hoverEnvironment) getSubQueryView(name string) (*parseutil.SubQueryInfo
169169
return nil, false
170170
}
171171

172+
func (e *hoverEnvironment) getSubQueryViewOne() (*parseutil.SubQueryInfo, bool) {
173+
if len(e.subQueries) == 1 {
174+
return e.subQueries[0], true
175+
}
176+
return nil, false
177+
}
178+
172179
func (e *hoverEnvironment) isSubQuery(name string) bool {
173180
_, ok := e.getSubQueryView(name)
174181
return ok
@@ -246,6 +253,14 @@ func hoverContentFromIdent(ctx *hoverContext, identName string, dbCache *databas
246253
return tableHoverInfo(tableName, cols)
247254
}
248255
}
256+
if hoverTypeIs(ctx.types, hoverTypeSubQueryColumn) {
257+
columnName := identName
258+
subQueryView, ok := hoverEnv.getSubQueryViewOne()
259+
if !ok {
260+
return nil
261+
}
262+
return subqueryColumnHoverInfo(columnName, subQueryView, dbCache)
263+
}
249264
return nil
250265
}
251266

internal/handler/hover_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,20 @@ func TestHover(t *testing.T) {
173173
line: 0,
174174
col: 21,
175175
},
176+
{
177+
name: "select subquery ident parent head",
178+
input: "SELECT ID, Name FROM (SELECT ci.ID, ci.Name, ci.CountryCode, ci.District, ci.Population FROM city AS ci) as it",
179+
output: "ID subquery column",
180+
line: 0,
181+
col: 8,
182+
},
183+
{
184+
name: "select subquery ident parent head",
185+
input: "SELECT ID, Name FROM (SELECT ci.ID, ci.Name, ci.CountryCode, ci.District, ci.Population FROM city AS ci) as it",
186+
output: "Name subquery column",
187+
line: 0,
188+
col: 15,
189+
},
176190
{
177191
name: "select subquery member ident parent head",
178192
input: "SELECT it.ID, it.Name FROM (SELECT ci.ID, ci.Name, ci.CountryCode, ci.District, ci.Population FROM city AS ci) as it",

0 commit comments

Comments
 (0)