Skip to content

Commit 8a10fc8

Browse files
authored
Merge pull request #24 from ran-codes/feature/23-file-type-detection
Feature/23 file type detection
2 parents 18f0084 + 9d71fb5 commit 8a10fc8

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/documentSymbolProvider.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
21
import * as vscode from 'vscode';
32
import { findSections, SectionMatch } from './utils/findSections';
43

4+
// 1. Document Symbol Provider Class ----
55
/**
66
* Document Symbol Provider for code organizer
77
* Detects comment sections with pattern: # Section Name ----
88
*/
99
export class CodeOrganizerDocumentSymbolProvider implements vscode.DocumentSymbolProvider {
1010

11+
//// 1.1 Child Symbol Processing ----
1112
/**
1213
* Helper method to add child symbols to a parent symbol (recursive)
1314
*/
@@ -18,14 +19,18 @@ export class CodeOrganizerDocumentSymbolProvider implements vscode.DocumentSymbo
1819
document: vscode.TextDocument,
1920
processedIds: Set<string> = new Set()
2021
): void {
22+
23+
////// 1.1.1 Recursion Prevention ----
2124
// Prevent infinite recursion by tracking processed parent unique IDs
2225
if (processedIds.has(parentMatch.uniqueId)) {
2326
return;
2427
}
2528
processedIds.add(parentMatch.uniqueId);
2629

30+
////// 1.1.2 Child Filtering ----
2731
const children = allMatches.filter(item => item.parentName === parentMatch.uniqueId);
2832

33+
////// 1.1.3 Child Symbol Creation ----
2934
if (children.length > 0) {
3035
for (let j = 0; j < children.length; j++) {
3136
const child = children[j];
@@ -43,7 +48,6 @@ export class CodeOrganizerDocumentSymbolProvider implements vscode.DocumentSymbo
4348
vscode.SymbolKind.Module, range, range
4449
);
4550

46-
4751
// Recursively add children to this child symbol with updated processed set
4852
this.addChildSymbols(childSymbol, child, allMatches, document, new Set(processedIds));
4953

@@ -52,6 +56,7 @@ export class CodeOrganizerDocumentSymbolProvider implements vscode.DocumentSymbo
5256
}
5357
}
5458

59+
//// 1.2 Main Symbol Provider Method ----
5560
/**
5661
* Main method called by VS Code when it needs symbols for a file
5762
*/
@@ -60,14 +65,13 @@ export class CodeOrganizerDocumentSymbolProvider implements vscode.DocumentSymbo
6065
token: vscode.CancellationToken
6166
): vscode.DocumentSymbol[] {
6267

63-
64-
// Setup
68+
////// 1.2.1 Document Processing ----
6569
const text = document.getText();
66-
const all_matches: SectionMatch[] = findSections(text);
70+
const languageId = document.languageId;
71+
const all_matches: SectionMatch[] = findSections(text, languageId);
6772
const matches = all_matches.filter((item: SectionMatch) => item.depth === 1);
6873

69-
70-
// Generate symbols
74+
////// 1.2.2 Symbol Generation ----
7175
const symbols: vscode.DocumentSymbol[] = [];
7276
for (let i = 0; i < matches.length; i++) {
7377
const match = matches[i];

src/utils/findSections.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export interface SectionMatch {
1313
* Find all section matches in text
1414
* Supports multiple comment syntaxes: #, //, --
1515
*/
16-
export function findSections(text: string): SectionMatch[] {
16+
export function findSections(text: string, languageId?: string): SectionMatch[] {
17+
// console.log(`[Code Organizer > findSections] Processing file type: ${languageId}`);
1718
const matches: SectionMatch[] = [];
1819

1920
//// 2.1 Pattern Definitions ----

0 commit comments

Comments
 (0)