-
Notifications
You must be signed in to change notification settings - Fork 96
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
Sweep: Hovering on a macro should show more details like description and arguments #1179
Sweep: Hovering on a macro should show more details like description and arguments #1179
Conversation
Rollback Files For Sweep
This is an automated message generated by Sweep AI. |
src/manifest/parsers/macroParser.ts
Outdated
let description = ""; | ||
let args = []; | ||
|
||
// Parse macro description | ||
for (let i = index - 1; i >= 0; i--) { | ||
const line = macroFileLines[i].trim(); | ||
if (line.startsWith("/*") || line.startsWith('"""')) { | ||
description = line.slice(2, -2).trim(); | ||
break; | ||
} | ||
} | ||
|
||
// Parse macro arguments | ||
const argsMatch = currentLine.match(/\((.*)\)/); | ||
if (argsMatch) { | ||
args = argsMatch[1].split(",").map(arg => arg.trim()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of this change, you could get description and arguments from macro
in line no 37
Sweep: PR ReviewAuthors of pull request: @saravmajestic, @sweep-ai[bot] This pull request added hover functionality for macros in the DBT SQL editor. The A new The A new function Finally, the
|
export interface MacroMetaData { | |
path: string | undefined; // in dbt cloud, packages are not downloaded locally | |
line: number; | |
character: number; | |
uniqueId: string; | |
description?: string; | |
arguments?: { name: string; type: string; description: string }[]; | |
name: string; | |
depends_on: DependsOn; |
View Diff
src/hover_provider/index.ts
- The
macroHoverProvider
is registered twice as a hover provider for theDBTPowerUserExtension.DBT_SQL_SELECTOR
, which could lead to duplicate hover information being provided.
vscode-dbt-power-user/src/hover_provider/index.ts
Lines 29 to 34 in 9c5a7a4
this.disposables.push( | |
languages.registerHoverProvider( | |
DBTPowerUserExtension.DBT_SQL_SELECTOR, | |
this.macroHoverProvider, | |
), | |
); |
View Diff
src/hover_provider/macroHoverProvider.ts
- The
provideHover
method does not handle potential exceptions fromthis.queryManifestService.getEventByDocument(document.uri)
, which could cause the hover functionality to fail silently. - The
provideHover
method does not handle the case wheredocument.getWordRangeAtPosition(position)
returnsundefined
, which could lead to a runtime error. - Sweep has identified a redundant function: The new function is redundant because its functionality is already implemented in the
dispose
methods of theDefinitionProviders
,WebviewViewProviders
,AutocompletionProviders
, andTreeviewProviders
classes. - Sweep has identified a redundant function: The new function is redundant because its functionality is already fully implemented in the
provideHover
method of theMacroHoverProvider
class inmacroHoverProvider.ts
.
vscode-dbt-power-user/src/hover_provider/macroHoverProvider.ts
Lines 45 to 47 in 9c5a7a4
token: CancellationToken, | |
): ProviderResult<Hover> { | |
const hoverText = document.getText( |
View Diff
vscode-dbt-power-user/src/hover_provider/macroHoverProvider.ts
Lines 40 to 42 in 9c5a7a4
} | |
provideHover( |
View Diff
vscode-dbt-power-user/src/hover_provider/macroHoverProvider.ts
Lines 26 to 33 in 9c5a7a4
constructor( | |
private telemetry: TelemetryService, | |
private dbtTerminal: DBTTerminal, | |
private queryManifestService: QueryManifestService, | |
) {} | |
dispose() { |
View Diff
vscode-dbt-power-user/src/hover_provider/macroHoverProvider.ts
Lines 35 to 60 in 9c5a7a4
const x = this.disposables.pop(); | |
if (x) { | |
x.dispose(); | |
} | |
} | |
} | |
provideHover( | |
document: TextDocument, | |
position: Position, | |
token: CancellationToken, | |
): ProviderResult<Hover> { | |
const hoverText = document.getText( | |
document.getWordRangeAtPosition(position), | |
); | |
this.dbtTerminal.debug("MacroHoverProvider", `checking: ${hoverText}`); | |
const eventResult = this.queryManifestService.getEventByDocument( | |
document.uri, | |
); | |
if (!eventResult) { | |
return; | |
} | |
const { macroMetaMap, nodeMetaMap } = eventResult; | |
const macroMeta = macroMetaMap.get(hoverText); | |
if (!macroMeta) { |
View Diff
src/hover_provider/utils.ts
- Sweep has identified a redundant function: The new function
generateMacroHoverMarkdown
is redundant as its functionality is already covered bygenerateHoverMarkdownString
with minor modifications.
vscode-dbt-power-user/src/hover_provider/utils.ts
Lines 42 to 74 in 9c5a7a4
} | |
export const generateMacroHoverMarkdown = ( | |
node: MacroMetaData, | |
referencedBy: (MacroMetaData | NodeMetaData)[], | |
event: ManifestCacheProjectAddedEvent, | |
) => { | |
const content = new MarkdownString(); | |
content.supportHtml = true; | |
content.isTrusted = true; | |
content.appendMarkdown( | |
`<span style="color:#347890;">(Macro) </span><span><strong>${node.name}</strong></span>`, | |
); | |
if (node.description !== "") { | |
content.appendMarkdown(`</br><span>${node.description}</span>`); | |
} | |
addSeparator(content); | |
node.arguments?.forEach((macroArg) => { | |
content.appendMarkdown( | |
`<span style="color:#347890;">(argument) </span><span>${macroArg.name} </span>`, | |
); | |
if (macroArg.type !== null) { | |
content.appendMarkdown( | |
`<span>- ${macroArg.type.toLowerCase()}</span>`, | |
); | |
} | |
if (macroArg.description !== "") { | |
content.appendMarkdown( | |
`<br/><span><em>${macroArg.description}</em></span>`, | |
); | |
} | |
content.appendMarkdown("</br>"); | |
}); |
View Diff
src/manifest/parsers/macroParser.ts
- If
macro.description
ormacro.arguments
are undefined or null, it could lead to incomplete metadata being stored inmacroMetaMap
.
vscode-dbt-power-user/src/manifest/parsers/macroParser.ts
Lines 69 to 70 in 9c5a7a4
description: macro.description, | |
arguments: macro.arguments, |
View Diff
#1182) * Sweep: Hovering on a macro should show more details like description and arguments (#1179) * feat: Updated 3 files * fix: macro hover provider * fix: popup ui --------- Co-authored-by: sweep-ai[bot] <128439645+sweep-ai[bot]@users.noreply.github.com> Co-authored-by: saravmajestic <sarav.majestic@gmail.com> * Remove unused 'type' param from model lookup * fix: right path for compiled/run files --------- Co-authored-by: sweep-ai[bot] <128439645+sweep-ai[bot]@users.noreply.github.com> Co-authored-by: saravmajestic <sarav.majestic@gmail.com> Co-authored-by: anandgupta42 <93243293+anandgupta42@users.noreply.github.com>
Description
This pull request introduces enhancements to the hover functionality in the extension, specifically targeting macros. It adds the ability to display detailed information such as the macro's description and its arguments when a user hovers over a macro reference in the code. This popup will show information like referenced by and depends on with right nodes. On clicking the node, user will be taken to the right file in vscode editor
Summary
MacroHoverProvider
class to handle hover events for macros, displaying a hover card with the macro's description and arguments.MacroHoverProvider
into theHoverProviders
class to register it alongside existing hover providers.MacroParser
to extract and store additional metadata about macros, including their descriptions and arguments, during the parsing process.generateMacroHoverMarkdown
(not shown in the diffs but referenced in the code) to format the hover content as Markdown.Fixes #1178.
Demo: https://www.loom.com/share/c5d5554f615d48229444f29afdf14357?sid=9e14d668-cefd-47e2-9fcc-ea9c2138e457
💡 To get Sweep to edit this pull request, you can:
This is an automated message generated by Sweep AI.