1- // SPDX-License-Identifier: MIT
2- // Copyright © 2025 TON Studio
3- import * as path from "node:path"
4- import { glob } from "glob"
5- import { index } from "@server/languages/func/indexes"
61import { fileURLToPath } from "node:url"
7- import { filePathToUri , findFuncFile } from "@server/files"
2+ import { glob } from "glob"
3+ import * as path from "node:path"
4+ import { filePathToUri } from "@server/files"
85
9- export enum FuncIndexingRootKind {
6+ export enum IndexingRootKind {
107 Stdlib = "stdlib" ,
118 Workspace = "workspace" ,
129}
1310
14- export class FuncIndexingRoot {
15- public constructor (
11+ export abstract class IndexingRoot {
12+ protected constructor (
1613 public root : string ,
17- public kind : FuncIndexingRootKind ,
14+ public extensions : string [ ] ,
15+ public kind : IndexingRootKind ,
1816 ) { }
1917
2018 public async index ( ) : Promise < void > {
2119 const ignore =
22- this . kind === FuncIndexingRootKind . Stdlib
20+ this . kind === IndexingRootKind . Stdlib
2321 ? [ ]
2422 : [
2523 ".git/**" ,
@@ -30,7 +28,11 @@ export class FuncIndexingRoot {
3028 ]
3129
3230 const rootDir = fileURLToPath ( this . root )
33- const files = await glob ( "**/*.{fc,func}" , {
31+
32+ const globPattern =
33+ this . extensions . length === 1 ? this . extensions [ 0 ] : `{${ this . extensions . join ( "," ) } }`
34+
35+ const files = await glob ( `**/*.${ globPattern } ` , {
3436 cwd : rootDir ,
3537 ignore : ignore ,
3638 } )
@@ -41,8 +43,9 @@ export class FuncIndexingRoot {
4143 console . info ( "Indexing:" , filePath )
4244 const absPath = path . join ( rootDir , filePath )
4345 const uri = filePathToUri ( absPath )
44- const file = await findFuncFile ( uri )
45- index . addFile ( uri , file , false )
46+ await this . onFile ( uri )
4647 }
4748 }
49+
50+ protected abstract onFile ( uri : string ) : Promise < void >
4851}
0 commit comments