Skip to content

Commit ad823c2

Browse files
committed
Refactor CodeLens provider to be stateless/event-driven; add --type to Mix diagram command if present
1 parent caa1666 commit ad823c2

5 files changed

Lines changed: 53 additions & 86 deletions

File tree

.github/chatmodes/plan.chatmode.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ checklists.
4646

4747
## Output Format:
4848

49-
Copilot will respond with two distinct Markdown checklists:
49+
Copilot will respond with two distinct Markdown checklists.
50+
**After generating the plan, please save the Checklists to a new markdown file in the project's root
51+
directory.**
5052

5153
### **1. Research Completion Checklist**
5254

package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
{
3636
"command": "ash-studio.showDiagram",
3737
"title": "Show Ash Diagram"
38-
},
39-
{
40-
"command": "ash-studio.openDocumentation",
41-
"title": "Open Ash Documentation"
4238
}
4339
],
4440
"languages": [],

src/extension.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,6 @@ export function activate(context: vscode.ExtensionContext) {
115115
)
116116
);
117117

118-
context.subscriptions.push(
119-
vscode.commands.registerCommand(
120-
"ash-studio.openDocumentation",
121-
(url: string) => {
122-
vscode.env.openExternal(vscode.Uri.parse(url));
123-
}
124-
)
125-
);
126-
127118
logger.info("Extension", "...complete");
128119
} catch (error) {
129120
logger.error("Extension", "Extension activation failed", error);

src/features/ashCodeLensProvider.ts

Lines changed: 47 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,53 @@ export class AshCodeLensProvider implements vscode.CodeLensProvider {
1313
// Track disposables for cleanup
1414
private disposables: vscode.Disposable[] = [];
1515

16-
// Cache the latest parse result
17-
private latestParseResult: ReturnType<
18-
AshParserService["documentActivated"]
19-
> | null = null;
16+
// Internal code lens list, always reflects the latest parse event
17+
private codeLenses: vscode.CodeLens[] = [];
2018

2119
constructor(private readonly parserService: AshParserService) {
22-
// Listen for parse events to refresh code lenses and update cache
20+
// Listen for parse events to update code lenses and trigger refresh
2321
this.disposables.push(
2422
this.parserService.onDidParse(result => {
25-
this.latestParseResult = result;
23+
this.codeLenses = [];
24+
for (const entry of result.codeLenses) {
25+
// Create a range for the CodeLens
26+
const line = Math.max(0, entry.line - 1); // Convert to 0-based line number
27+
const range = new vscode.Range(
28+
new vscode.Position(line, entry.character),
29+
new vscode.Position(line, entry.character + 1)
30+
);
31+
32+
// Create the CodeLens with a command that opens the documentation URL
33+
const lens = new vscode.CodeLens(range);
34+
35+
// Debug logging
36+
Logger.getInstance().debug(
37+
"AshCodeLensProvider",
38+
`Creating code lens: ${entry.title} -> ${entry.target}`
39+
);
40+
41+
// Assign command directly from entry
42+
if (entry.command === "ash-studio.showDiagram") {
43+
lens.command = {
44+
title: entry.title,
45+
command: entry.command,
46+
arguments: [
47+
vscode.window.activeTextEditor?.document.uri.fsPath ?? "",
48+
entry,
49+
],
50+
tooltip: `View diagram for ${entry.source}`,
51+
};
52+
} else {
53+
const logger = Logger.getInstance();
54+
logger.error(
55+
"Code Lens Provider",
56+
`Unknown Command ${entry.command}`
57+
);
58+
vscode.window.showErrorMessage(`Unknown Command ${entry.command}`);
59+
}
60+
61+
this.codeLenses.push(lens);
62+
}
2663
this.triggerCodeLensRefresh();
2764
})
2865
);
@@ -38,75 +75,13 @@ export class AshCodeLensProvider implements vscode.CodeLensProvider {
3875
}
3976

4077
/**
41-
* Provides CodeLens for the given document
78+
* Provides CodeLens for Ash DSL files
4279
*/
43-
async provideCodeLenses(
44-
document: vscode.TextDocument,
45-
_token: vscode.CancellationToken
46-
): Promise<vscode.CodeLens[] | null> {
80+
async provideCodeLenses(): Promise<vscode.CodeLens[]> {
4781
if (!ConfigurationManager.getInstance().get("enableCodeLens")) {
48-
return null;
49-
}
50-
try {
51-
if (!this.latestParseResult) {
52-
return null;
53-
}
54-
// Convert our CodeLensEntry objects to VS Code CodeLens objects
55-
const codeLenses: vscode.CodeLens[] = [];
56-
for (const entry of this.latestParseResult.codeLenses) {
57-
// Create a range for the CodeLens
58-
const line = Math.max(0, entry.line - 1); // Convert to 0-based line number
59-
const range = new vscode.Range(
60-
new vscode.Position(line, entry.character),
61-
new vscode.Position(line, entry.character + 1)
62-
);
63-
64-
// Create the CodeLens with a command that opens the documentation URL
65-
const lens = new vscode.CodeLens(range);
66-
67-
// Debug logging
68-
Logger.getInstance().debug(
69-
"AshCodeLensProvider",
70-
`Creating code lens: ${entry.title} -> ${entry.target}`
71-
);
72-
73-
// Assign command directly from entry
74-
if (entry.command === "ash-studio.showDiagram") {
75-
lens.command = {
76-
title: entry.title,
77-
command: entry.command,
78-
arguments: [document.uri.fsPath, entry],
79-
tooltip: `View diagram for ${entry.source}`,
80-
};
81-
} else if (entry.command === "ash-studio.openDocumentation") {
82-
lens.command = {
83-
title: entry.title,
84-
command: entry.command,
85-
arguments: [entry.target],
86-
tooltip: `View documentation for ${entry.source}`,
87-
};
88-
} else {
89-
const logger = Logger.getInstance();
90-
logger.error(
91-
"Code Lens Provicer",
92-
`Unknown Command ${entry.command}`
93-
);
94-
vscode.window.showErrorMessage(`Unknown Command ${entry.command}`);
95-
}
96-
97-
codeLenses.push(lens);
98-
}
99-
100-
// Remove manual diagram CodeLens logic; all CodeLenses now come from parseResult.codeLenses
101-
102-
return codeLenses;
103-
} catch (error) {
104-
Logger.getInstance().error(
105-
"AshCodeLensProvider",
106-
`Error providing code lenses: ${error}`
107-
);
108-
return null;
82+
return [];
10983
}
84+
return this.codeLenses;
11085
}
11186

11287
/**

src/utils/diagramMixUtils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export async function generateDiagramWithMix(
3838
"--format",
3939
format,
4040
];
41+
if (diagramSpec.type) {
42+
args.push("--type", diagramSpec.type);
43+
}
4144
const mix = spawn("mix", args, { cwd });
4245
let stderr = "";
4346
let stdout = "";

0 commit comments

Comments
 (0)