Skip to content

Commit aa3e00d

Browse files
committed
update
1 parent c5a3cde commit aa3e00d

14 files changed

+169
-6
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/controller/EventController.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99

1010
import { eventService } from "../service/EventService";
1111
// 事件的控制器
12+
/* The EventController class has a method called add_event that calls the add_event method on the
13+
eventService class */
1214
class EventContorller {
1315
/**
1416
* 监听事件
1517
*/
18+
/**
19+
* The function `add_event()` is a public function that calls the `add_event()` function in the
20+
* `eventService` service
21+
*/
1622
public add_event() {
1723
eventService.add_event();
1824
}

src/controller/FileButtonController.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import { ConfigurationChangeEvent, Disposable, languages, workspace } from "vscode";
1111
import { fileButtonService } from "../service/FileButtonService";
1212
// 文件按钮的控制器
13+
/* It listens to configuration changes and refreshes the file button service */
1314
class FileButtonController implements Disposable {
1415
private registeredProvider: Disposable | undefined;
1516
private configurationChangeListener: Disposable;

src/controller/LoginController.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { getLeetCodeEndpoint } from "../utils/ConfigUtils";
2323
class LoginContorller {
2424
constructor() {}
2525

26+
/* A login function. */
2627
// 登录操作
2728
public async signIn(): Promise<void> {
2829
const picks: Array<IQuickItemEx<string>> = [];
@@ -165,6 +166,9 @@ class LoginContorller {
165166
}
166167

167168
// 登出
169+
/**
170+
* It signs out the user
171+
*/
168172
public async signOut(): Promise<void> {
169173
try {
170174
await executeService.signOut();
@@ -176,11 +180,18 @@ class LoginContorller {
176180
}
177181

178182
// 获取登录状态
183+
/**
184+
* It returns the login status of the user.
185+
* @returns The login status of the user.
186+
*/
179187
public async getLoginStatus() {
180188
return await statusBarService.getLoginStatus();
181189
}
182190

183191
// 删除所有缓存
192+
/**
193+
* It signs out, removes old cache, switches to the default endpoint, and refreshes the tree data
194+
*/
184195
public async deleteAllCache(): Promise<void> {
185196
await this.signOut();
186197
await executeService.removeOldCache();

src/controller/MainController.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class MainContorller {
5959
}
6060

6161
// 删除缓存
62+
/**
63+
* It deletes the cache.
64+
*/
6265
public async deleteCache() {
6366
await executeService.deleteCache();
6467
}

src/controller/TreeViewController.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ class TreeViewController implements Disposable {
8080
private waitUserContest: boolean;
8181

8282
// 获取当前文件的路径
83+
/**
84+
* It returns the path of the currently active file, or undefined if there is no active file
85+
* @param [uri] - The file path to open.
86+
* @returns A promise that resolves to a string or undefined.
87+
*/
8388
public async getActiveFilePath(uri?: vscode.Uri): Promise<string | undefined> {
8489
let textEditor: vscode.TextEditor | undefined;
8590
if (uri) {
@@ -103,6 +108,13 @@ class TreeViewController implements Disposable {
103108
}
104109

105110
// 提交问题
111+
/**
112+
* It gets the active file path, then submits the solution to the server, and finally refreshes the
113+
* tree view
114+
* @param [uri] - The URI of the file to be submitted. If not provided, the currently active file will
115+
* be submitted.
116+
* @returns A promise that resolves to a string.
117+
*/
106118
public async submitSolution(uri?: vscode.Uri): Promise<void> {
107119
if (!statusBarService.getUser()) {
108120
promptForSignIn();
@@ -127,6 +139,11 @@ class TreeViewController implements Disposable {
127139
}
128140

129141
// 提交测试用例
142+
/**
143+
* It takes the current file, and sends it to the server to be tested
144+
* @param [uri] - The file path of the file to be submitted. If it is not passed, the currently active
145+
* file is submitted.
146+
*/
130147
public async testSolution(uri?: vscode.Uri): Promise<void> {
131148
try {
132149
if (statusBarService.getStatus() === UserStatus.SignedOut) {
@@ -217,6 +234,13 @@ class TreeViewController implements Disposable {
217234
await promptForOpenOutputChannel("提交测试出错了. 请查看控制台信息~", DialogType.error);
218235
}
219236
}
237+
/**
238+
* "Show a file selection dialog, and return the selected file's URI."
239+
*
240+
* The function is async, so it returns a promise
241+
* @param {string} [fsPath] - The path of the file that is currently open in the editor.
242+
* @returns An array of file URIs or undefined.
243+
*/
220244
public async showFileSelectDialog(fsPath?: string): Promise<vscode.Uri[] | undefined> {
221245
const defaultUri: vscode.Uri | undefined = this.getBelongingWorkspaceFolderUri(fsPath);
222246
const options: vscode.OpenDialogOptions = {
@@ -229,6 +253,14 @@ class TreeViewController implements Disposable {
229253
return await vscode.window.showOpenDialog(options);
230254
}
231255

256+
/**
257+
* It gets the active file path, and then calls the executeService.testSolution function to test the
258+
* solution
259+
* @param [uri] - The path of the file to be submitted. If it is not passed, the currently active file
260+
* is submitted.
261+
* @param {boolean} [allCase] - Whether to submit all cases.
262+
* @returns a promise that resolves to void.
263+
*/
232264
public async testSolutionDefault(uri?: vscode.Uri, allCase?: boolean): Promise<void> {
233265
try {
234266
if (statusBarService.getStatus() === UserStatus.SignedOut) {
@@ -251,6 +283,15 @@ class TreeViewController implements Disposable {
251283
}
252284
}
253285

286+
/**
287+
* It gets the active file path, then calls the executeService.testSolution function to test the
288+
* solution
289+
* @param [uri] - The file path of the file to be submitted. If it is not passed in, the currently
290+
* active file is submitted.
291+
* @param {string} [testcase] - The test case to be tested. If it is not specified, the test case will
292+
* be randomly selected.
293+
* @returns a promise that resolves to void.
294+
*/
254295
public async testSolutionArea(uri?: vscode.Uri, testcase?: string): Promise<void> {
255296
try {
256297
if (statusBarService.getStatus() === UserStatus.SignedOut) {
@@ -273,6 +314,13 @@ class TreeViewController implements Disposable {
273314
}
274315
}
275316

317+
/**
318+
* "If the ComSpec environment variable is not set, or if it is set to cmd.exe, then return true."
319+
*
320+
* The ComSpec environment variable is set to the path of the command processor. On Windows, this is
321+
* usually cmd.exe. On Linux, it is usually bash
322+
* @returns A boolean value.
323+
*/
276324
public usingCmd(): boolean {
277325
const comSpec: string | undefined = process.env.ComSpec;
278326
// 'cmd.exe' is used as a fallback if process.env.ComSpec is unavailable.
@@ -286,6 +334,12 @@ class TreeViewController implements Disposable {
286334
return false;
287335
}
288336

337+
/**
338+
* If you're on Windows, and you're using cmd.exe, then you need to escape double quotes with
339+
* backslashes. Otherwise, you don't
340+
* @param {string} test - The test string to be parsed.
341+
* @returns a string.
342+
*/
289343
public parseTestString(test: string): string {
290344
if (systemUtils.useWsl() || !systemUtils.isWindows()) {
291345
if (systemUtils.useVscodeNode()) {
@@ -310,6 +364,10 @@ class TreeViewController implements Disposable {
310364
}
311365
}
312366

367+
/**
368+
* It switches the endpoint of LeetCode, and then signs out and signs in again
369+
* @returns a promise that resolves to a void.
370+
*/
313371
public async switchEndpoint(): Promise<void> {
314372
const isCnEnabled: boolean = getLeetCodeEndpoint() === Endpoint.LeetCodeCN;
315373
const picks: Array<IQuickItemEx<string>> = [];
@@ -350,6 +408,11 @@ class TreeViewController implements Disposable {
350408
}
351409
}
352410

411+
/**
412+
* It shows a quick pick menu with the available sorting strategies, and if the user selects one, it
413+
* updates the sorting strategy and refreshes the tree view
414+
* @returns A promise that resolves to a void.
415+
*/
353416
public async switchSortingStrategy(): Promise<void> {
354417
const currentStrategy: SortingStrategy = getSortingStrategy();
355418
const picks: Array<IQuickItemEx<string>> = [];
@@ -371,6 +434,10 @@ class TreeViewController implements Disposable {
371434
await treeDataService.refresh();
372435
}
373436

437+
/**
438+
* It adds a node to the user's favorites
439+
* @param {NodeModel} node - NodeModel
440+
*/
374441
public async addFavorite(node: NodeModel): Promise<void> {
375442
try {
376443
await executeService.toggleFavorite(node, true);
@@ -383,6 +450,10 @@ class TreeViewController implements Disposable {
383450
}
384451
}
385452

453+
/**
454+
* It removes a node from the user's favorites
455+
* @param {NodeModel} node - The node that is currently selected in the tree.
456+
*/
386457
public async removeFavorite(node: NodeModel): Promise<void> {
387458
try {
388459
await executeService.toggleFavorite(node, false);
@@ -395,6 +466,10 @@ class TreeViewController implements Disposable {
395466
}
396467
}
397468

469+
/**
470+
* It returns a list of problems
471+
* @returns An array of problems.
472+
*/
398473
public async listProblems(): Promise<IProblem[]> {
399474
try {
400475
if (statusBarService.getStatus() === UserStatus.SignedOut) {

src/rpc/actionChain/chainManager.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { storageUtils } from "../utils/storageUtils";
1313
import { commUtils } from "../utils/commUtils";
1414
import { ChainNodeBase } from "./chainNodeBase";
1515

16+
/* It's a class that manages a chain of plugins */
1617
export class ChainManager {
1718
id;
1819
name;
@@ -25,10 +26,19 @@ export class ChainManager {
2526

2627
constructor() {}
2728

29+
/**
30+
* Return the head of the chain.
31+
* @returns The head of the chain.
32+
*/
2833
public getChainHead(): ChainNodeBase {
2934
return this.head;
3035
}
3136

37+
/**
38+
* It loads all the plugins in the directory and initializes them.
39+
* @param {ChainNodeBase | undefined} head - The first node in the chain of responsibility.
40+
* @returns The return value is a boolean.
41+
*/
3242
public init(head: ChainNodeBase | undefined): Object | undefined {
3343
if (head) {
3444
this.head = head;
@@ -72,6 +82,9 @@ export class ChainManager {
7282
return true;
7383
}
7484

85+
/**
86+
* For each plugin in the plugins array, call the save function.
87+
*/
7588
public save_all(): void {
7689
for (let p of this.plugins) {
7790
p.save();

src/rpc/actionChain/chainNode/cache.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { storageUtils } from "../../utils/storageUtils";
1515
import { commUtils } from "../../utils/commUtils";
1616
import { sessionUtils } from "../../utils/sessionUtils";
1717

18+
/* It's a plugin that caches the data it gets from the next plugin in the chain */
1819
class CachePlugin extends ChainNodeBase {
1920
id = 50;
2021
name = "cache";
@@ -23,6 +24,7 @@ class CachePlugin extends ChainNodeBase {
2324
super();
2425
}
2526

27+
/* Checking if the translation config has changed. If it has, it clears the cache. */
2628
clearCacheIfTchanged = (needTranslation) => {
2729
const translationConfig = storageUtils.getCache(commUtils.KEYS.translation);
2830
if (!translationConfig || translationConfig["useEndpointTranslation"] != needTranslation) {
@@ -33,6 +35,8 @@ class CachePlugin extends ChainNodeBase {
3335
}
3436
};
3537

38+
/* A method that is used to get problems from the cache. If the cache is empty, it will get the
39+
problems from the next layer. */
3640
public getProblems = (needTranslation, cb) => {
3741
this.clearCacheIfTchanged(needTranslation);
3842
const problems = storageUtils.getCache(commUtils.KEYS.problems);
@@ -46,9 +50,9 @@ class CachePlugin extends ChainNodeBase {
4650
});
4751
};
4852

49-
/**
50-
* getRatingOnline
51-
*/
53+
/* A method that is used to get problems from the cache. If the cache is empty, it will get the
54+
problems from the next layer. */
55+
5256
public getRatingOnline = (cb) => {
5357
const cacheRantingData = storageUtils.getCache(commUtils.KEYS.ranting_path);
5458
if (cacheRantingData) {
@@ -67,6 +71,7 @@ class CachePlugin extends ChainNodeBase {
6771
});
6872
};
6973

74+
/* A cache layer for the getProblem function. */
7075
public getProblem = (problem, needTranslation, cb) => {
7176
this.clearCacheIfTchanged(needTranslation);
7277
const k = commUtils.KEYS.problem(problem);
@@ -95,6 +100,7 @@ class CachePlugin extends ChainNodeBase {
95100
return storageUtils.setCache(commUtils.KEYS.problem(problem), _problem);
96101
};
97102

103+
/* Updating the problem in the cache. */
98104
updateProblem = (problem, kv) => {
99105
const problems = storageUtils.getCache(commUtils.KEYS.problems);
100106
if (!problems) return false;
@@ -106,6 +112,7 @@ class CachePlugin extends ChainNodeBase {
106112
return storageUtils.setCache(commUtils.KEYS.problems, problems);
107113
};
108114

115+
/* Logging out the user and then logging in the user. */
109116
login = (user, cb) => {
110117
this.logout(user, false);
111118
this.next.login(user, function (e, user) {
@@ -115,10 +122,10 @@ class CachePlugin extends ChainNodeBase {
115122
});
116123
};
117124

125+
/* Logging out the user and then logging in the user. */
118126
logout = (user, purge) => {
119127
if (!user) user = sessionUtils.getUser();
120128
if (purge) sessionUtils.deleteUser();
121-
// NOTE: need invalidate any user related cache
122129
sessionUtils.deleteCodingSession();
123130
return user;
124131
};

0 commit comments

Comments
 (0)