Skip to content

Commit

Permalink
docs: Add missing documentation comments to multiple utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
yunpeng committed May 19, 2024
1 parent d7e7647 commit bf1e60e
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 9 deletions.
21 changes: 21 additions & 0 deletions .hintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": [
"development"
],
"hints": {
"axe/text-alternatives": [
"default",
{
"image-alt": "off"
}
],
"disown-opener": "off",
"axe/forms": [
"default",
{
"label": "off"
}
],
"typescript-config/strict": "off"
}
}
20 changes: 14 additions & 6 deletions pre-download-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,25 @@ for (const target of targets) {
const downloadUrl = `https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-${
target === "win32-arm64" ? "win32-ia32" : target
}.tar.gz`;
execSync(`curl -L -o ${targetDir}/build.tar.gz ${downloadUrl}`);
// 检查下载文件是否存在
const filePath = `${targetDir}/build.tar.gz`;
if (fs.existsSync(filePath)) {
console.log(`[info] File already exists: ${filePath}`);
} else {
// 如果文件不存在,下载文件
console.log(`[info] Downloading ${target}...`);
execSync(`curl -L -o ${targetDir}/build.tar.gz ${downloadUrl}`);
}

Check warning on line 56 in pre-download-build.js

View check run for this annotation

Codecov / codecov/patch

pre-download-build.js#L48-L56

Added lines #L48 - L56 were not covered by tests
execSync(`cd ${targetDir} && tar -xvzf build.tar.gz`);
fs.copyFileSync(
`${targetDir}/build/Release/node_sqlite3.node`,
`${targetDir}/node_sqlite3.node`,
);
fs.unlinkSync(`${targetDir}/build.tar.gz`);
fs.rmSync(`${targetDir}/build`, {
recursive: true,
force: true,
});
// fs.unlinkSync(`${targetDir}/build.tar.gz`);
// fs.rmSync(`${targetDir}/build`, {
// recursive: true,
// force: true,
// });

Check warning on line 66 in pre-download-build.js

View check run for this annotation

Codecov / codecov/patch

pre-download-build.js#L62-L66

Added lines #L62 - L66 were not covered by tests
}

console.log("[info] Downloading prebuilt lancedb...");
Expand Down
20 changes: 20 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,39 @@ import * as vscode from "vscode";

let _context: vscode.ExtensionContext | undefined;

/**
* 设置扩展上下文
*
* @param context 扩展上下文对象
*/

Check warning on line 9 in src/context.ts

View check run for this annotation

Codecov / codecov/patch

src/context.ts#L5-L9

Added lines #L5 - L9 were not covered by tests
export function setExtensionContext(context: vscode.ExtensionContext) {
_context = context;
}

/**
* 获取扩展程序的URI。
*
* @returns 返回扩展程序的URI。
*/

Check warning on line 18 in src/context.ts

View check run for this annotation

Codecov / codecov/patch

src/context.ts#L14-L18

Added lines #L14 - L18 were not covered by tests
export function getExtensionUri() {
return _context?.extensionUri!;
}


/**
* 获取扩展上下文对象
*
* @returns 扩展上下文对象
*/

Check warning on line 28 in src/context.ts

View check run for this annotation

Codecov / codecov/patch

src/context.ts#L24-L28

Added lines #L24 - L28 were not covered by tests
export function getExtensionContext() {
return _context!;
}

/**
* 移除扩展上下文
*
* 将扩展上下文 `_context` 设置为 `undefined`,以清除扩展上下文信息。
*/

Check warning on line 37 in src/context.ts

View check run for this annotation

Codecov / codecov/patch

src/context.ts#L33-L37

Added lines #L33 - L37 were not covered by tests
export function removeExtensionContext() {
_context = undefined;
}
138 changes: 135 additions & 3 deletions src/editor/editor-api/VSCodeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,98 @@ import { defaultIgnoreFile } from "../util/ignore";
export class VSCodeAction implements IdeAction {
git: GitAction = new GitAction();

/**
* 执行命令
*
* @param command 命令字符串
* @returns Promise<void> 无返回值
*/

Check warning on line 18 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L13-L18

Added lines #L13 - L18 were not covered by tests
async runCommand(command: string): Promise<void> {
// 如果有已打开的终端

Check warning on line 20 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L20

Added line #L20 was not covered by tests
if (vscode.window.terminals.length) {
// 显示第一个终端

Check warning on line 22 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L22

Added line #L22 was not covered by tests
vscode.window.terminals[0].show();
// 在终端中发送命令

Check warning on line 24 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L24

Added line #L24 was not covered by tests
vscode.window.terminals[0].sendText(command, false);
} else {
// 创建一个新的终端

Check warning on line 27 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L27

Added line #L27 was not covered by tests
const terminal = vscode.window.createTerminal();
// 显示新创建的终端

Check warning on line 29 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L29

Added line #L29 was not covered by tests
terminal.show();
// 在新创建的终端中发送命令

Check warning on line 31 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L31

Added line #L31 was not covered by tests
terminal.sendText(command, false);
}
}

// getTerminalContents: [undefined, string];
/**
* 获取终端内容
*
* @param commands 要选择的命令数量,默认为-1,表示选择所有内容
* @returns 返回终端内容的Promise对象
*/

Check warning on line 42 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L37-L42

Added lines #L37 - L42 were not covered by tests
async getTerminalContents(commands: number = -1): Promise<string> {
// 读取剪贴板的内容到临时变量tempCopyBuffer

Check warning on line 44 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L44

Added line #L44 was not covered by tests
const tempCopyBuffer = await vscode.env.clipboard.readText();

// 如果commands小于0

Check warning on line 47 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L46-L47

Added lines #L46 - L47 were not covered by tests
if (commands < 0) {
// 执行命令选择终端中的所有内容

Check warning on line 49 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L49

Added line #L49 was not covered by tests
await vscode.commands.executeCommand(
"workbench.editor-api.terminal.selectAll"
);
} else {
// 遍历执行命令选择上一个命令的内容,循环次数为commands

Check warning on line 54 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L54

Added line #L54 was not covered by tests
for (let i = 0; i < commands; i++) {
await vscode.commands.executeCommand(
"workbench.editor-api.terminal.selectToPreviousCommand"
);
}
}

// 执行命令复制选中的终端内容

Check warning on line 62 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L61-L62

Added lines #L61 - L62 were not covered by tests
await vscode.commands.executeCommand(
"workbench.editor-api.terminal.copySelection"
);

// 执行命令清除选中的终端内容

Check warning on line 67 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L66-L67

Added lines #L66 - L67 were not covered by tests
await vscode.commands.executeCommand(
"workbench.editor-api.terminal.clearSelection"
);

// 读取剪贴板的内容到terminalContents变量

Check warning on line 72 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L71-L72

Added lines #L71 - L72 were not covered by tests
const terminalContents = await vscode.env.clipboard.readText();

// 将临时变量tempCopyBuffer的内容写回剪贴板

Check warning on line 75 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L74-L75

Added lines #L74 - L75 were not covered by tests
await vscode.env.clipboard.writeText(tempCopyBuffer);

// 如果临时变量tempCopyBuffer与终端内容terminalContents相同

Check warning on line 78 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L78

Added line #L78 was not covered by tests
if (tempCopyBuffer === terminalContents) {
// This means there is no terminal open to select text from
// 这意味着没有打开的终端可以从中选择文本

Check warning on line 80 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L80

Added line #L80 was not covered by tests
return "";
}

// 返回终端内容

Check warning on line 84 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L83-L84

Added lines #L83 - L84 were not covered by tests
return terminalContents;
}

/**
* 获取工作区目录列表
*
* @returns 返回工作区目录的路径数组,若获取失败则返回空数组
*/

Check warning on line 92 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L88-L92

Added lines #L88 - L92 were not covered by tests
getWorkspaceDirectories(): string[] {
return (vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath) || []);
}

private static MAX_BYTES = 100000;

/**
* 获取文件路径的绝对路径
*
* @param filepath 文件路径
* @returns 返回绝对路径字符串
*/

Check warning on line 104 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L99-L104

Added lines #L99 - L104 were not covered by tests
getAbsolutePath(filepath: string): string {
const workspaceDirectories = this.getWorkspaceDirectories();
if (!path.isAbsolute(filepath) && workspaceDirectories.length === 1) {
Expand All @@ -66,50 +111,81 @@ export class VSCodeAction implements IdeAction {
}
}

/**
* 异步读取文件内容
*
* @param filepath 文件路径
* @returns 返回文件内容的Promise对象
*/

Check warning on line 119 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L114-L119

Added lines #L114 - L119 were not covered by tests
async readFile(filepath: string): Promise<string> {
try {
// 获取文件的绝对路径

Check warning on line 122 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L122

Added line #L122 was not covered by tests
filepath = this.getAbsolutePath(filepath);
// 将文件路径转换为 URI

Check warning on line 124 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L124

Added line #L124 was not covered by tests
const uri = this.uriFromFilePath(filepath);

// Check first whether it's an open document
// 首先检查是否是已打开的文档

Check warning on line 127 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L127

Added line #L127 was not covered by tests
const openTextDocument = vscode.workspace.textDocuments.find(
(doc) => doc.uri.fsPath === uri.fsPath,
);
if (openTextDocument !== undefined) {
// 如果是已打开的文档,直接返回文档内容

Check warning on line 132 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L132

Added line #L132 was not covered by tests
return openTextDocument.getText();
}

// 获取文件状态信息

Check warning on line 136 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L136

Added line #L136 was not covered by tests
const fileStats = await vscode.workspace.fs.stat(
this.uriFromFilePath(filepath),
);
// 如果文件大小超过最大限制,返回空字符串

Check warning on line 140 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L140

Added line #L140 was not covered by tests
if (fileStats.size > 10 * VSCodeAction.MAX_BYTES) {
return "";
}

// 读取文件内容

Check warning on line 145 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L145

Added line #L145 was not covered by tests
const bytes = await vscode.workspace.fs.readFile(uri);

// Truncate the buffer to the first MAX_BYTES
// 截取缓冲区的前 MAX_BYTES 字节

Check warning on line 148 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L148

Added line #L148 was not covered by tests
const truncatedBytes = bytes.slice(0, VSCodeAction.MAX_BYTES);
// 将字节解码为字符串

Check warning on line 150 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L150

Added line #L150 was not covered by tests
const contents = new TextDecoder().decode(truncatedBytes);
// 返回文件内容

Check warning on line 152 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L152

Added line #L152 was not covered by tests
return contents;
} catch {
// 如果发生异常,返回空字符串

Check warning on line 155 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L155

Added line #L155 was not covered by tests
return "";
}
}

/**
* 根据文件路径获取vscode.Uri对象
*
* @param filepath 文件路径
* @returns 返回一个vscode.Uri对象
*/

Check warning on line 165 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L160-L165

Added lines #L160 - L165 were not covered by tests
uriFromFilePath(filepath: string): vscode.Uri {
// 如果当前环境是远程环境

Check warning on line 167 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L167

Added line #L167 was not covered by tests
if (vscode.env.remoteName) {
// 如果当前环境是Windows本地环境但不是远程环境

Check warning on line 169 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L169

Added line #L169 was not covered by tests
if (this.isWindowsLocalButNotRemote()) {
// 将文件路径从Windows格式转换为POSIX格式

Check warning on line 171 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L171

Added line #L171 was not covered by tests
filepath = this.windowsToPosix(filepath);
}
// 根据远程环境名称和文件路径构造VSCode的URI对象

Check warning on line 174 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L174

Added line #L174 was not covered by tests
return vscode.Uri.parse(
`vscode-remote://${vscode.env.remoteName}${filepath}`,
);
} else {
// 如果当前环境不是远程环境,则构造本地文件的VSCode URI对象

Check warning on line 179 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L179

Added line #L179 was not covered by tests
return vscode.Uri.file(filepath);
}
}

/**
* 判断当前环境是否为 Windows 本地环境且非远程环境。
*
* @returns 返回一个布尔值,表示当前环境是否为 Windows 本地环境且非远程环境。
*/

Check warning on line 188 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L184-L188

Added lines #L184 - L188 were not covered by tests
isWindowsLocalButNotRemote(): boolean {
return (
vscode.env.remoteName !== undefined &&
Expand All @@ -120,6 +196,11 @@ export class VSCodeAction implements IdeAction {
);
}

/**
* 获取路径分隔符
*
* @returns 如果当前环境是本地Windows环境但不是远程Windows环境,返回 "/";否则返回 path.sep
*/

Check warning on line 203 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L199-L203

Added lines #L199 - L203 were not covered by tests
getPathSep(): string {
return this.isWindowsLocalButNotRemote() ? "/" : path.sep;
}
Expand All @@ -133,10 +214,22 @@ export class VSCodeAction implements IdeAction {
return posixPath;
}

/**
* 获取指定目录下的分支信息
*
* @param dir 指定的目录路径
* @returns 返回分支信息的字符串
*/

Check warning on line 222 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L217-L222

Added lines #L217 - L222 were not covered by tests
async getBranch(dir: string): Promise<string> {
return this.getBranchForUri(vscode.Uri.file(dir));
}

/**
* 根据目录URI获取分支名
*
* @param forDirectory 目录URI
* @returns 分支名,如果获取失败则返回"NONE"
*/

Check warning on line 232 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L227-L232

Added lines #L227 - L232 were not covered by tests
async getBranchForUri(forDirectory: vscode.Uri) {
let repo = await this.git.getRepo(forDirectory);
if (repo?.state?.HEAD?.name === undefined) {
Expand All @@ -153,32 +246,65 @@ export class VSCodeAction implements IdeAction {
return repo?.state?.HEAD?.name || "NONE";
}

/**
* 获取指定目录下所有文件的最后修改时间
*
* @param directory 目录路径
* @returns 返回文件路径到最后修改时间的映射对象
*/

Check warning on line 254 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L249-L254

Added lines #L249 - L254 were not covered by tests
async getStats(directory: string): Promise<{ [path: string]: number }> {
// 获取工作区第一个文件夹的 URI scheme

Check warning on line 256 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L256

Added line #L256 was not covered by tests
const scheme = vscode.workspace.workspaceFolders?.[0].uri.scheme;

// 列出目录中的文件列表

Check warning on line 259 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L258-L259

Added lines #L258 - L259 were not covered by tests
const files = await this.listWorkspaceContents(directory);

// 创建一个对象,用于存储每个文件的最后修改时间

Check warning on line 262 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L261-L262

Added lines #L261 - L262 were not covered by tests
const pathToLastModified: { [path: string]: number } = {};

Check warning on line 264 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L264

Added line #L264 was not covered by tests
await Promise.all(
files.map(async (file) => {
// 获取文件的统计信息

Check warning on line 267 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L267

Added line #L267 was not covered by tests
let stat = await vscode.workspace.fs.stat(this.uriFromFilePath(file));
// 将文件路径和最后修改时间存入对象中

Check warning on line 269 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L269

Added line #L269 was not covered by tests
pathToLastModified[file] = stat.mtime;
}),
);

// 返回包含文件最后修改时间的对象

Check warning on line 274 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L274

Added line #L274 was not covered by tests
return pathToLastModified;
}

/**
* 列出工作区的内容
*
* @param directory 目录路径,可选
* @returns 返回工作区内容的文件路径数组
*/

Check warning on line 283 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L278-L283

Added lines #L278 - L283 were not covered by tests
async listWorkspaceContents(directory?: string): Promise<string[]> {
// 如果提供了目录参数

Check warning on line 285 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L285

Added line #L285 was not covered by tests
if (directory) {
// 调用获取目录内容的函数,并返回结果

Check warning on line 287 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L287

Added line #L287 was not covered by tests
return await this.getDirectoryContents(directory, true);
} else {
// 获取工作区所有目录

Check warning on line 290 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L290

Added line #L290 was not covered by tests
const contents = await Promise.all(
this.getWorkspaceDirectories()
// 对每个目录调用获取目录内容的函数,并返回结果的数组

Check warning on line 293 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L293

Added line #L293 was not covered by tests
.map((dir) => this.getDirectoryContents(dir, true)),
);
// 将所有目录的内容合并成一个数组并返回

Check warning on line 296 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L296

Added line #L296 was not covered by tests
return contents.flat();
}
}

/**
* 异步获取目录内容
*
* @param directory 目录路径
* @param recursive 是否递归搜索子目录
* @returns 目录内容(文件路径数组)
*/

Check warning on line 307 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L301-L307

Added lines #L301 - L307 were not covered by tests
async getDirectoryContents(
directory: string,
recursive: boolean,
Expand Down Expand Up @@ -213,6 +339,12 @@ export class VSCodeAction implements IdeAction {
return allFiles;
}

/**
* 获取仓库名称
*
* @param dir 仓库目录
* @returns 仓库名称,若无法获取则返回 undefined
*/

Check warning on line 347 in src/editor/editor-api/VSCodeAction.ts

View check run for this annotation

Codecov / codecov/patch

src/editor/editor-api/VSCodeAction.ts#L342-L347

Added lines #L342 - L347 were not covered by tests
getRepoName(dir: string): Promise<string | undefined> {
return this.git.getRepoName(vscode.Uri.file(dir));
}
Expand Down
Loading

0 comments on commit bf1e60e

Please sign in to comment.