Skip to content

Commit

Permalink
perf: 如果只有一个工作空间,直接使用
Browse files Browse the repository at this point in the history
Co-authored-by: ygqygq2 <[email protected]>
  • Loading branch information
ygqygq2 committed Mar 4, 2024
1 parent a5f2694 commit 0c604df
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

All notable changes to the "turbo-file-header" extension will be documented in this file.

# [0.0.2]

## 功能优化 🚀

- perf: 只有一个工作空间时直接使用,不需要用户选择
- chore: 默认设置统一

# [0.0.1]

## 新增功能 🌱

* feat: 快捷键 `ctrl + alt + h` 更新/插入文件头信息
* feat: 生成自定义模板配置,支持自定义模板
* feat: 注释内容高亮
- feat: 快捷键 `ctrl + alt + h` 更新/插入文件头信息
- feat: 生成自定义模板配置,支持自定义模板
- feat: 注释内容高亮
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "turbo-file-header",
"displayName": "Turbo File Header",
"description": "Sets file header information globally or for a project.",
"version": "0.0.1",
"version": "0.0.2",
"icon": "resources/icons/icon.png",
"repository": {
"type": "git",
Expand Down Expand Up @@ -80,12 +80,12 @@
},
"TurboFileHeader.autoInsertOnCreateFile": {
"type": "boolean",
"default": true,
"default": false,
"description": "Auto insert fileheader when create file"
},
"TurboFileHeader.autoUpdateOnSave": {
"type": "boolean",
"default": true,
"default": false,
"description": "Auto update fileheader when save file"
},
"TurboFileHeader.disableFields": {
Expand Down
44 changes: 44 additions & 0 deletions src/configuration/ConfigReader.ts
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) || [];
};
}
1 change: 1 addition & 0 deletions src/extension-operate/FileMatcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class FileMatcher {}
4 changes: 3 additions & 1 deletion src/utils/vscode-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export async function getActiveDocumentWorkspace(): Promise<vscode.WorkspaceFold
activeWorkspace = vscode.workspace.getWorkspaceFolder(activeDocumentUri);
} else {
const workspaces = vscode.workspace.workspaceFolders;
if (workspaces && workspaces.length > 0) {
if (workspaces && workspaces.length === 1) {
activeWorkspace = workspaces[0];
} else if (workspaces && workspaces.length > 0) {
const picked = await vscode.window.showQuickPick(
workspaces.map((workspace) => ({ label: workspace.name, workspace })),
{ title: 'Select which workspace for add custom fileheader template' },
Expand Down

0 comments on commit 0c604df

Please sign in to comment.