-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: ygqygq2 <[email protected]>
- Loading branch information
Showing
5 changed files
with
61 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import YAML from 'yaml'; | ||
// import * as vscode from 'vscode'; | ||
import { CUSTOM_CONFIG_FILE_NAME } from '@/constants'; | ||
import { ConfigYaml } from '@/typings/types'; | ||
import { getActiveDocumentWorkspace } from '@/utils/vscode-utils'; | ||
|
||
export class ConfigReader { | ||
private static instance: ConfigReader; | ||
private configYaml: ConfigYaml; | ||
|
||
private constructor() { | ||
this.configYaml = this.getConfigYaml() as unknown as ConfigYaml; | ||
} | ||
|
||
public static getInstance(): ConfigReader { | ||
return ConfigReader?.instance || new ConfigReader(); | ||
} | ||
|
||
public getConfigYaml = async (): Promise<ConfigYaml | undefined> => { | ||
const activeWorkspace = await getActiveDocumentWorkspace(); | ||
if (!activeWorkspace) { | ||
return; | ||
} | ||
|
||
const configPath = path.join(activeWorkspace.uri.fsPath, '.vscode', CUSTOM_CONFIG_FILE_NAME); | ||
if (!fs.existsSync(configPath)) { | ||
return; | ||
} | ||
|
||
// 读取 yaml 配置 | ||
const configContent = fs.readFileSync(configPath, 'utf8'); | ||
const config: ConfigYaml = YAML.parse(configContent); | ||
const defaultConfig: ConfigYaml = { | ||
providers: [], | ||
}; | ||
return { ...defaultConfig, ...config }; | ||
}; | ||
|
||
public getAllLanguages = (): string[] => { | ||
return this.configYaml?.providers.flatMap((provider) => provider.languages) || []; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export class FileMatcher {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters