Skip to content

Commit ecf7386

Browse files
committed
fix: remove unnecessary TreeDataProvider import and fix formatting
- Remove unused TreeDataProvider import from extension.ts - Fix type annotation to use vscode.TreeDataProvider directly - Run Prettier to fix all formatting issues (23 files) - Update TypeScript any types to unknown for better type safety - Remove unused imports and variables - All quality checks now pass: type-check, lint, format:check, test
1 parent 6564903 commit ecf7386

29 files changed

Lines changed: 895 additions & 545 deletions

docs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ This folder contains comprehensive documentation for the Ash Studio VS Code Exte
6060

6161
The Ash Studio extension uses a **hybrid parser architecture** with:
6262

63-
- **Configuration-driven parser**: Flexible and maintainable parsing approach through module configuration
63+
- **Configuration-driven parser**: Flexible and maintainable parsing approach through module
64+
configuration
6465
- **Services**: Centralized logging, configuration, performance monitoring, and error handling
6566
- **Testing**: Organized unit/integration test structure with 68 comprehensive tests
6667

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default [
99
".vscode-test/**/*",
1010
"dist/**/*",
1111
"node_modules/**/*",
12-
"**/*.min.js"
12+
"**/*.min.js",
1313
],
1414
},
1515
{

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@
126126
"test:config": "mocha 'test/unit/parsers/configurationDriven/*.test.js'",
127127
"test:vscode": "node ./dist/test/runTest.js"
128128
},
129-
"dependencies": {
130-
},
129+
"dependencies": {},
131130
"devDependencies": {
132131
"@types/glob": "^8.1.0",
133132
"@types/mocha": "^10.0.10",

src/ashParserService.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ export class AshParserService {
1515
private _onDidParse = new vscode.EventEmitter<ParseResult>();
1616

1717
// Parser implementation
18-
private parsers: Parser[] = [
19-
ConfigurationDrivenParser.getInstance(),
20-
];
18+
private parsers: Parser[] = [ConfigurationDrivenParser.getInstance()];
2119

2220
public readonly onDidParse = this._onDidParse.event;
2321

src/extension.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function activate(context: vscode.ExtensionContext) {
4848
logger.info("Extension", "Using configuration-driven parser only");
4949

5050
// Initialize the parser service with error handling
51-
let parserService: AshParserService;
51+
let parserService: AshParserService | null = null;
5252
try {
5353
console.log("🔧 Attempting to initialize parser service...");
5454
logger.info("Extension", "Attempting to initialize parser service...");
@@ -72,7 +72,7 @@ export function activate(context: vscode.ExtensionContext) {
7272
`Ash Studio parser initialization failed: ${parserError instanceof Error ? parserError.message : String(parserError)}`
7373
);
7474
// Continue without parser functionality
75-
parserService = null as any;
75+
parserService = null;
7676
}
7777

7878
// Initialize sidebar with error handling
@@ -162,11 +162,12 @@ export function activate(context: vscode.ExtensionContext) {
162162

163163
// Fallback minimal sidebar if parser failed
164164
const fallbackSidebar = {
165-
getTreeItem: (element: any) =>
166-
new vscode.TreeItem(
165+
getTreeItem: () => {
166+
return new vscode.TreeItem(
167167
"Parser Error",
168168
vscode.TreeItemCollapsibleState.None
169-
),
169+
);
170+
},
170171
getChildren: () => {
171172
console.log("🔄 Fallback sidebar getChildren called");
172173
return [{ label: "Parser service unavailable" }];
@@ -179,7 +180,7 @@ export function activate(context: vscode.ExtensionContext) {
179180

180181
console.log("🎛️ Creating fallback tree view...");
181182
const fallbackTreeView = vscode.window.createTreeView("ashSidebar", {
182-
treeDataProvider: fallbackSidebar as any,
183+
treeDataProvider: fallbackSidebar as vscode.TreeDataProvider<unknown>,
183184
showCollapseAll: false,
184185
});
185186

@@ -201,7 +202,10 @@ export function activate(context: vscode.ExtensionContext) {
201202
registerAshQuickPick(context, parserService);
202203
registerAshSectionNavigation(context, parserService);
203204
registerAshCodeLensProvider(context, parserService);
204-
logger.info("Extension", "Navigation features and code lens provider registered successfully");
205+
logger.info(
206+
"Extension",
207+
"Navigation features and code lens provider registered successfully"
208+
);
205209
}
206210
} catch (navigationError) {
207211
logger.error(

src/features/ashCodeLensProvider.ts

Lines changed: 78 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ import { ConfigurationManager } from "../utils/config";
1212
export class AshCodeLensProvider implements vscode.CodeLensProvider {
1313
// Track disposables for cleanup
1414
private disposables: vscode.Disposable[] = [];
15-
15+
1616
constructor(private readonly parserService: AshParserService) {
1717
// Listen for parse events to refresh code lenses when content changes
1818
this.disposables.push(
1919
this.parserService.onDidParse(() => {
2020
this.triggerCodeLensRefresh();
2121
})
2222
);
23-
23+
2424
// Also listen for configuration changes that might affect code lens display
2525
this.disposables.push(
26-
vscode.workspace.onDidChangeConfiguration((event) => {
26+
vscode.workspace.onDidChangeConfiguration(event => {
2727
if (event.affectsConfiguration("ashStudio.enableCodeLens")) {
2828
this.triggerCodeLensRefresh();
2929
}
3030
})
3131
);
3232
}
33-
33+
3434
/**
3535
* Provides CodeLens for the given document
3636
*/
@@ -53,58 +53,69 @@ export class AshCodeLensProvider implements vscode.CodeLensProvider {
5353

5454
// Convert our CodeLensEntry objects to VS Code CodeLens objects
5555
const codeLenses: vscode.CodeLens[] = [];
56-
56+
5757
for (const entry of parseResult.codeLenses) {
5858
// Create a range for the CodeLens
5959
const line = Math.max(0, entry.line - 1); // Convert to 0-based line number
6060
const range = new vscode.Range(
61-
new vscode.Position(line, entry.character),
61+
new vscode.Position(line, entry.character),
6262
new vscode.Position(line, entry.character + 1)
6363
);
64-
64+
6565
// Create the CodeLens with a command that opens the documentation URL
6666
const lens = new vscode.CodeLens(range);
67-
67+
6868
// Debug logging
69-
Logger.getInstance().debug("AshCodeLensProvider", `Creating code lens: ${entry.title} -> ${entry.target}`);
70-
69+
Logger.getInstance().debug(
70+
"AshCodeLensProvider",
71+
`Creating code lens: ${entry.title} -> ${entry.target}`
72+
);
73+
7174
try {
7275
const uri = vscode.Uri.parse(entry.target);
73-
Logger.getInstance().debug("AshCodeLensProvider", `Parsed URI: ${uri.toString()}`);
74-
76+
Logger.getInstance().debug(
77+
"AshCodeLensProvider",
78+
`Parsed URI: ${uri.toString()}`
79+
);
80+
7581
// Use our custom command for better control and logging
7682
lens.command = {
7783
title: entry.title,
7884
command: "ash-studio.openDocumentation",
7985
arguments: [entry.target],
80-
tooltip: `View documentation for ${entry.source}`
86+
tooltip: `View documentation for ${entry.source}`,
8187
};
82-
88+
8389
// Alternative: use the built-in vscode.open command if needed
8490
// lens.command = {
8591
// title: entry.title,
8692
// command: "vscode.open",
8793
// arguments: [uri],
8894
// tooltip: `View documentation for ${entry.source}`
8995
// };
90-
91-
9296
} catch (error) {
93-
Logger.getInstance().error("AshCodeLensProvider", `Failed to parse URI: ${entry.target}`, error);
97+
Logger.getInstance().error(
98+
"AshCodeLensProvider",
99+
`Failed to parse URI: ${entry.target}`,
100+
error
101+
);
94102
// Fallback: create a command that shows an error message
95103
lens.command = {
96104
title: entry.title,
97105
command: "vscode.window.showErrorMessage",
98-
arguments: [`Failed to open documentation: ${entry.target}`]
106+
arguments: [`Failed to open documentation: ${entry.target}`],
99107
};
100108
}
101-
109+
102110
codeLenses.push(lens);
103111
}
104-
112+
105113
return codeLenses;
106114
} catch (error) {
107-
Logger.getInstance().error("AshCodeLensProvider", `Error providing code lenses: ${error}`);
115+
Logger.getInstance().error(
116+
"AshCodeLensProvider",
117+
`Error providing code lenses: ${error}`
118+
);
108119
return null;
109120
}
110121
}
@@ -121,7 +132,7 @@ export class AshCodeLensProvider implements vscode.CodeLensProvider {
121132
* Dispose of resources
122133
*/
123134
dispose(): void {
124-
this.disposables.forEach((d) => d.dispose());
135+
this.disposables.forEach(d => d.dispose());
125136
this.disposables = [];
126137
}
127138
}
@@ -134,7 +145,7 @@ export function registerAshCodeLensProvider(
134145
parserService: AshParserService
135146
): vscode.Disposable {
136147
const provider = new AshCodeLensProvider(parserService);
137-
148+
138149
// Register a test command to verify command execution works
139150
const testCommand = vscode.commands.registerCommand(
140151
"ash-studio.testCodeLens",
@@ -143,58 +154,82 @@ export function registerAshCodeLensProvider(
143154
vscode.window.showInformationMessage(`Code lens clicked! URL: ${url}`);
144155
}
145156
);
146-
157+
147158
// Add the test command to context subscriptions
148159
context.subscriptions.push(testCommand);
149-
160+
150161
// Register a custom command for opening documentation URLs
151162
const openDocsCommand = vscode.commands.registerCommand(
152163
"ash-studio.openDocumentation",
153164
async (url: string) => {
154-
console.log(`[CodeLens Command] ash-studio.openDocumentation called with URL: ${url}`);
155-
Logger.getInstance().info("AshCodeLensProvider", `Command called: opening documentation URL: ${url}`);
156-
165+
console.log(
166+
`[CodeLens Command] ash-studio.openDocumentation called with URL: ${url}`
167+
);
168+
Logger.getInstance().info(
169+
"AshCodeLensProvider",
170+
`Command called: opening documentation URL: ${url}`
171+
);
172+
157173
try {
158174
console.log(`[CodeLens Command] Attempting to open URL: ${url}`);
159175
const uri = vscode.Uri.parse(url);
160176
console.log(`[CodeLens Command] Parsed URI:`, uri.toString());
161-
177+
162178
// Try multiple methods to handle different environments (like Windsurf)
163179
try {
164180
// Method 1: Use the VS Code built-in API (primary method)
165181
await vscode.env.openExternal(uri);
166-
console.log(`[CodeLens Command] Successfully opened URL with openExternal: ${url}`);
182+
console.log(
183+
`[CodeLens Command] Successfully opened URL with openExternal: ${url}`
184+
);
167185
} catch (primaryError) {
168-
console.warn(`[CodeLens Command] openExternal failed, trying alternative: ${primaryError}`);
169-
186+
console.warn(
187+
`[CodeLens Command] openExternal failed, trying alternative: ${primaryError}`
188+
);
189+
170190
// Method 2: Try to use the built-in open command as fallback
171-
await vscode.commands.executeCommand('vscode.open', uri);
172-
console.log(`[CodeLens Command] Successfully opened URL with vscode.open command: ${url}`);
191+
await vscode.commands.executeCommand("vscode.open", uri);
192+
console.log(
193+
`[CodeLens Command] Successfully opened URL with vscode.open command: ${url}`
194+
);
173195
}
174-
196+
175197
// Show a user notification that we attempted to open the URL
176198
// This is useful in Windsurf where the browser might not open visibly
177199
vscode.window.showInformationMessage(
178200
`Documentation URL: ${url} (URL should open in your default browser)`
179201
);
180-
181-
Logger.getInstance().info("AshCodeLensProvider", `Successfully processed URL open request: ${url}`);
202+
203+
Logger.getInstance().info(
204+
"AshCodeLensProvider",
205+
`Successfully processed URL open request: ${url}`
206+
);
182207
} catch (error) {
183208
console.error(`[CodeLens Command] Failed to open URL: ${url}`, error);
184-
Logger.getInstance().error("AshCodeLensProvider", `Failed to open URL: ${url}`, error);
185-
vscode.window.showErrorMessage(`Failed to open documentation: ${url}. Error: ${error instanceof Error ? error.message : String(error)}`);
209+
Logger.getInstance().error(
210+
"AshCodeLensProvider",
211+
`Failed to open URL: ${url}`,
212+
error
213+
);
214+
vscode.window.showErrorMessage(
215+
`Failed to open documentation: ${url}. Error: ${error instanceof Error ? error.message : String(error)}`
216+
);
186217
}
187218
}
188219
);
189-
220+
190221
// Register the provider for Elixir files
191222
const providerDisposable = vscode.languages.registerCodeLensProvider(
192223
{ language: "elixir", scheme: "file" },
193224
provider
194225
);
195-
226+
196227
context.subscriptions.push(openDocsCommand);
197228
context.subscriptions.push(providerDisposable);
198-
199-
return vscode.Disposable.from(testCommand, openDocsCommand, providerDisposable);
229+
230+
return vscode.Disposable.from(
231+
testCommand,
232+
openDocsCommand,
233+
providerDisposable
234+
);
200235
}

src/features/ashQuickPick.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as vscode from "vscode";
22
import { AshParserService } from "../ashParserService";
3-
import { ParsedSection } from "../parsers/parser";
43

54
export function registerAshQuickPick(
65
context: vscode.ExtensionContext,

src/features/ashSectionNavigation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as vscode from "vscode";
22
import { AshParserService } from "../ashParserService";
3-
import { ParsedSection } from "../parsers/parser";
43

54
export function registerAshSectionNavigation(
65
context: vscode.ExtensionContext,
@@ -14,7 +13,7 @@ export function registerAshSectionNavigation(
1413
];
1514

1615
const provider: vscode.DocumentSymbolProvider = {
17-
provideDocumentSymbols(document, token) {
16+
provideDocumentSymbols(document) {
1817
// Use cached result if available, otherwise parse
1918
let parseResult = parser.getCachedResult(document);
2019
if (!parseResult) {

src/features/ashSidebarProvider.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,35 @@ export class AshSidebarProvider
6969
if (!section || !section.details || section.details.length === 0)
7070
return [];
7171

72-
return section.details.map(
73-
(detail: ParsedDetail) => this.createDetailTreeItem(detail)
72+
return section.details.map((detail: ParsedDetail) =>
73+
this.createDetailTreeItem(detail)
7474
);
75-
} else if (element.detail && element.detail.childDetails && element.detail.childDetails.length > 0) {
75+
} else if (
76+
element.detail &&
77+
element.detail.childDetails &&
78+
element.detail.childDetails.length > 0
79+
) {
7680
// Level 2+: Show nested details (recursive handling)
77-
return element.detail.childDetails.map(
78-
(childDetail: ParsedDetail) => this.createDetailTreeItem(childDetail)
81+
return element.detail.childDetails.map((childDetail: ParsedDetail) =>
82+
this.createDetailTreeItem(childDetail)
7983
);
8084
}
8185

8286
return [];
8387
}
84-
88+
8589
/**
8690
* Helper method to create a tree item for a detail, handling nested details recursively
8791
*/
8892
private createDetailTreeItem(detail: ParsedDetail): AshSidebarItem {
8993
const hasChildren = detail.childDetails && detail.childDetails.length > 0;
90-
94+
9195
// Create a label that shows both block type and name (if available)
9296
let label = detail.detail; // Default to just the block type
9397
if (detail.name && detail.name !== detail.detail) {
9498
label = `${detail.detail} ${detail.name}`; // Show both type and name
9599
}
96-
100+
97101
return new AshSidebarItem(
98102
label,
99103
hasChildren

0 commit comments

Comments
 (0)