Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdfbdd18

Browse files
committed
change the usage of outputchannel
1 parentb7e3f22 commitdfbdd18

File tree

12 files changed

+59
-97
lines changed

12 files changed

+59
-97
lines changed

‎README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Solve LeetCode problems in VS Code.
3333

3434
##Known Issues:
3535
- This extension will infer the current target problem according to the active editing file. Please do not change the file name.
36+
- Currently, only unlocked problems will be listed.
3637

3738
##Release Notes
3839

@@ -72,6 +73,7 @@ This extension is based on [@skygragon](https://github.com/skygragon)'s [leetcod
7273

7374
##已知问题
7475
- 本插件会根据文件名称推测当前的目标题目,因此建议不要改变文件名。
76+
- 本插件目前仅会显示左右已解锁的问题。
7577

7678
##更新日志
7779

‎src/commands/list.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22

3+
import*asvscodefrom"vscode";
34
import{leetCodeManager}from"../leetCodeManager";
45
import{leetCodeBinaryPath}from"../shared";
56
import{UserStatus}from"../shared";
@@ -14,12 +15,12 @@ export interface IProblem {
1415
passRate:string;
1516
}
1617

17-
exportasyncfunctionlistProblems():Promise<IProblem[]>{
18+
exportasyncfunctionlistProblems(channel:vscode.OutputChannel):Promise<IProblem[]>{
1819
try{
1920
if(leetCodeManager.getStatus()===UserStatus.SignedOut){
2021
return[];
2122
}
22-
constresult:string=awaitexecuteCommand("node",[leetCodeBinaryPath,"list","-q","L"]);
23+
constresult:string=awaitexecuteCommand(channel,"node",[leetCodeBinaryPath,"list","-q","L"]);
2324
constproblems:IProblem[]=[];
2425
constlines:string[]=result.split("\n");
2526
constreg:RegExp=/(.?)\s*\[\s*(\d*)\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+%)\)/;
@@ -37,7 +38,7 @@ export async function listProblems(): Promise<IProblem[]> {
3738
}
3839
returnproblems.reverse();
3940
}catch(error){
40-
awaitpromptForOpenOutputChannel("Failed to list problems. Please open the output channel for details",DialogType.error);
41+
awaitpromptForOpenOutputChannel("Failed to list problems. Please open the output channel for details",DialogType.error,channel);
4142
return[];
4243
}
4344

‎src/commands/session.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import { IQuickItemEx, leetCodeBinaryPath } from "../shared";
66
import*ascpfrom"../utils/cpUtils";
77
import{DialogType,promptForOpenOutputChannel,promptForSignIn}from"../utils/uiUtils";
88

9-
exportasyncfunctiongetSessionList():Promise<ISession[]>{
9+
exportasyncfunctiongetSessionList(channel:vscode.OutputChannel):Promise<ISession[]>{
1010
constsignInStatus=leetCodeManager.getUser();
1111
if(!signInStatus){
1212
promptForSignIn();
1313
return[];
1414
}
15-
constresult:string=awaitcp.executeCommand("node",[leetCodeBinaryPath,"session"]);
15+
constresult:string=awaitcp.executeCommand(channel,"node",[leetCodeBinaryPath,"session"]);
1616
constlines:string[]=result.split("\n");
1717
constsessions:ISession[]=[];
1818
constreg:RegExp=/(.?)\s*(\d+)\s+(.*)\s+(\d+\(\s*\d+\.\d+%\))\s+(\d+\(\s*\d+\.\d+%\))/;
@@ -31,8 +31,8 @@ export async function getSessionList(): Promise<ISession[]> {
3131
returnsessions;
3232
}
3333

34-
exportasyncfunctionselectSession():Promise<void>{
35-
constchoice:IQuickItemEx<string>|undefined=awaitvscode.window.showQuickPick(parseSessionsToPicks(getSessionList()));
34+
exportasyncfunctionselectSession(channel:vscode.OutputChannel):Promise<void>{
35+
constchoice:IQuickItemEx<string>|undefined=awaitvscode.window.showQuickPick(parseSessionsToPicks(getSessionList(channel)));
3636
if(!choice||choice.description==="Active"){
3737
return;
3838
}
@@ -41,11 +41,11 @@ export async function selectSession(): Promise<void> {
4141
return;
4242
}
4343
try{
44-
awaitcp.executeCommand("node",[leetCodeBinaryPath,"session","-e",choice.value]);
44+
awaitcp.executeCommand(channel,"node",[leetCodeBinaryPath,"session","-e",choice.value]);
4545
vscode.window.showInformationMessage(`Successfully switched to session '${choice.label}'.`);
4646
awaitvscode.commands.executeCommand("leetcode.refreshExplorer");
4747
}catch(error){
48-
awaitpromptForOpenOutputChannel("Failed to switch session. Please open the output channel for details",DialogType.error);
48+
awaitpromptForOpenOutputChannel("Failed to switch session. Please open the output channel for details",DialogType.error,channel);
4949
}
5050
}
5151

@@ -67,7 +67,7 @@ async function parseSessionsToPicks(p: Promise<ISession[]>): Promise<Array<IQuic
6767
});
6868
}
6969

70-
exportasyncfunctioncreateSession():Promise<void>{
70+
exportasyncfunctioncreateSession(channel:vscode.OutputChannel):Promise<void>{
7171
constsession:string|undefined=awaitvscode.window.showInputBox({
7272
prompt:"Enter the new session name.",
7373
validateInput:(s:string)=>s.trim() ?undefined :"Session name must not be empty",
@@ -76,10 +76,10 @@ export async function createSession(): Promise<void> {
7676
return;
7777
}
7878
try{
79-
awaitcp.executeCommand("node",[leetCodeBinaryPath,"session","-c",session]);
79+
awaitcp.executeCommand(channel,"node",[leetCodeBinaryPath,"session","-c",session]);
8080
vscode.window.showInformationMessage("New session created, you can switch to it by clicking the status bar.");
8181
}catch(error){
82-
awaitpromptForOpenOutputChannel("Failed to create session. Please open the output channel for details",DialogType.error);
82+
awaitpromptForOpenOutputChannel("Failed to create session. Please open the output channel for details",DialogType.error,channel);
8383
}
8484
}
8585

‎src/commands/show.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ import { DialogType, promptForOpenOutputChannel, promptForSignIn } from "../util
1010
import{selectWorkspaceFolder}from"../utils/workspaceUtils";
1111
import*aslistfrom"./list";
1212

13-
exportasyncfunctionshowProblem(node?:LeetCodeNode):Promise<void>{
13+
exportasyncfunctionshowProblem(channel:vscode.OutputChannel,node?:LeetCodeNode):Promise<void>{
1414
if(!node){
1515
return;
1616
}
17-
awaitshowProblemInternal(node.id);
17+
awaitshowProblemInternal(channel,node.id);
1818
}
1919

20-
exportasyncfunctionsearchProblem():Promise<void>{
20+
exportasyncfunctionsearchProblem(channel:vscode.OutputChannel):Promise<void>{
2121
if(!leetCodeManager.getUser()){
2222
promptForSignIn();
2323
return;
2424
}
2525
constchoice:IQuickItemEx<string>|undefined=awaitvscode.window.showQuickPick(
26-
parseProblemsToPicks(list.listProblems()),
26+
parseProblemsToPicks(list.listProblems(channel)),
2727
{
2828
matchOnDetail:true,
2929
placeHolder:"Select one problem",
@@ -32,18 +32,18 @@ export async function searchProblem(): Promise<void> {
3232
if(!choice){
3333
return;
3434
}
35-
awaitshowProblemInternal(choice.value);
35+
awaitshowProblemInternal(channel,choice.value);
3636
}
3737

38-
asyncfunctionshowProblemInternal(id:string):Promise<void>{
38+
asyncfunctionshowProblemInternal(channel:vscode.OutputChannel,id:string):Promise<void>{
3939
try{
4040
constlanguage:string|undefined=awaitvscode.window.showQuickPick(languages,{placeHolder:"Select the language you want to use"});
4141
if(!language){
4242
return;
4343
}
4444
constoutdir:string=awaitselectWorkspaceFolder();
4545
awaitfse.ensureDir(outdir);
46-
constresult:string=awaitexecuteCommand("node",[leetCodeBinaryPath,"show",id,"-gx","-l",language,"-o",outdir]);
46+
constresult:string=awaitexecuteCommand(channel,"node",[leetCodeBinaryPath,"show",id,"-gx","-l",language,"-o",outdir]);
4747
constreg:RegExp=/\*SourceCode:\s*(.*)/;
4848
constmatch:RegExpMatchArray|null=result.match(reg);
4949
if(match&&match.length>=2){
@@ -52,7 +52,7 @@ async function showProblemInternal(id: string): Promise<void> {
5252
thrownewError("Failed to fetch the problem information");
5353
}
5454
}catch(error){
55-
awaitpromptForOpenOutputChannel("Failed to fetch the problem information. Please open the output channel for details",DialogType.error);
55+
awaitpromptForOpenOutputChannel("Failed to fetch the problem information. Please open the output channel for details",DialogType.error,channel);
5656
}
5757
}
5858

‎src/commands/submit.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { leetCodeBinaryPath } from "../shared";
99
import{executeCommand}from"../utils/cpUtils";
1010
import{DialogType,promptForOpenOutputChannel,promptForSignIn}from"../utils/uiUtils";
1111

12-
exportasyncfunctionsubmitSolution():Promise<void>{
12+
exportasyncfunctionsubmitSolution(channel:vscode.OutputChannel):Promise<void>{
1313
if(!leetCodeManager.getUser()){
1414
promptForSignIn();
1515
return;
@@ -24,12 +24,12 @@ export async function submitSolution(): Promise<void> {
2424
}
2525
constfilePath:string=textEditor.document.uri.fsPath;
2626
try{
27-
constresult:string=awaitexecuteCommand("node",[leetCodeBinaryPath,"submit",filePath]);
27+
constresult:string=awaitexecuteCommand(channel,"node",[leetCodeBinaryPath,"submit",filePath]);
2828
constresultPath:string=path.join(os.homedir(),".leetcode","Result");
2929
awaitfse.ensureFile(resultPath);
3030
awaitfse.writeFile(resultPath,result);
3131
awaitvscode.window.showTextDocument(vscode.Uri.file(resultPath));
3232
}catch(error){
33-
awaitpromptForOpenOutputChannel("Failed to submit the solution. Please open the output channel for details",DialogType.error);
33+
awaitpromptForOpenOutputChannel("Failed to submit the solution. Please open the output channel for details",DialogType.error,channel);
3434
}
3535
}

‎src/extension.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,29 @@ import * as vscode from "vscode";
44
import*assessionfrom"./commands/session";
55
import*asshowfrom"./commands/show";
66
import*assubmitfrom"./commands/submit";
7-
import{leetcodeChannel}from"./leetCodeChannel";
87
import{LeetCodeNode,LeetCodeTreeDataProvider}from"./leetCodeExplorer";
98
import{leetCodeManager}from"./leetCodeManager";
109
import{leetCodeStatusBarItem}from"./leetCodeStatusBarItem";
1110
import{isNodeInstalled}from"./utils/nodeUtils";
1211

1312
exportasyncfunctionactivate(context:vscode.ExtensionContext){
14-
if(!awaitisNodeInstalled()){
13+
constchannel:vscode.OutputChannel=vscode.window.createOutputChannel("LeetCode");
14+
if(!awaitisNodeInstalled(channel)){
1515
return;
1616
}
17-
18-
leetCodeManager.getLoginStatus();
19-
constleetCodeTreeDataProvider:LeetCodeTreeDataProvider=newLeetCodeTreeDataProvider(context);
17+
leetCodeManager.getLoginStatus(channel);
18+
constleetCodeTreeDataProvider:LeetCodeTreeDataProvider=newLeetCodeTreeDataProvider(context,channel);
2019

2120
context.subscriptions.push(
2221
vscode.window.registerTreeDataProvider("leetCodeExplorer",leetCodeTreeDataProvider),
23-
vscode.commands.registerCommand("leetcode.signin",()=>leetCodeManager.signIn()),
24-
vscode.commands.registerCommand("leetcode.signout",()=>leetCodeManager.signOut()),
25-
vscode.commands.registerCommand("leetcode.selectSessions",()=>session.selectSession()),
26-
vscode.commands.registerCommand("leetcode.createSession",()=>session.createSession()),
27-
vscode.commands.registerCommand("leetcode.showProblem",(node:LeetCodeNode)=>show.showProblem(node)),
28-
vscode.commands.registerCommand("leetcode.searchProblem",()=>show.searchProblem()),
22+
vscode.commands.registerCommand("leetcode.signin",()=>leetCodeManager.signIn(channel)),
23+
vscode.commands.registerCommand("leetcode.signout",()=>leetCodeManager.signOut(channel)),
24+
vscode.commands.registerCommand("leetcode.selectSessions",()=>session.selectSession(channel)),
25+
vscode.commands.registerCommand("leetcode.createSession",()=>session.createSession(channel)),
26+
vscode.commands.registerCommand("leetcode.showProblem",(node:LeetCodeNode)=>show.showProblem(channel,node)),
27+
vscode.commands.registerCommand("leetcode.searchProblem",()=>show.searchProblem(channel)),
2928
vscode.commands.registerCommand("leetcode.refreshExplorer",()=>leetCodeTreeDataProvider.refresh()),
30-
vscode.commands.registerCommand("leetcode.submitSolution",()=>submit.submitSolution()),
29+
vscode.commands.registerCommand("leetcode.submitSolution",()=>submit.submitSolution(channel)),
3130
);
3231

3332
leetCodeManager.on("statusChanged",()=>{
@@ -37,6 +36,5 @@ export async function activate(context: vscode.ExtensionContext) {
3736
}
3837

3938
exportfunctiondeactivate(){
40-
leetcodeChannel.dispose();
4139
leetCodeStatusBarItem.dispose();
4240
}

‎src/leetCodeChannel.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

‎src/leetCodeExplorer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
3838
// tslint:disable-next-line:member-ordering
3939
publicreadonlyonDidChangeTreeData:vscode.Event<any>=this.onDidChangeTreeDataEvent.event;
4040

41-
constructor(privatecontext:vscode.ExtensionContext){}
41+
constructor(privatecontext:vscode.ExtensionContext,privatechannel:vscode.OutputChannel){}
4242

4343
publicasyncrefresh():Promise<void>{
4444
this.treeData.clear();
@@ -97,7 +97,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
9797
}
9898

9999
privateasyncgetProblemData():Promise<void>{
100-
constallProblems:list.IProblem[]=awaitlist.listProblems();
100+
constallProblems:list.IProblem[]=awaitlist.listProblems(this.channel);
101101
for(constproblemofallProblems){
102102
constproblems:list.IProblem[]|undefined=this.treeData.get(problem.difficulty);
103103
if(problems){

‎src/leetCodeManager.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
import*ascpfrom"child_process";
44
import{EventEmitter}from"events";
55
import*asvscodefrom"vscode";
6-
import{leetcodeChannel}from"./leetCodeChannel";
76
import{UserStatus}from"./shared";
87
import{leetCodeBinaryPath}from"./shared";
98
import{executeCommand}from"./utils/cpUtils";
109
import{DialogType,promptForOpenOutputChannel}from"./utils/uiUtils";
1110

1211
exportinterfaceILeetCodeManagerextendsEventEmitter{
13-
getLoginStatus():void;
12+
getLoginStatus(channel:vscode.OutputChannel):void;
1413
getStatus():UserStatus;
1514
getUser():string|undefined;
16-
signIn():void;
17-
signOut():void;
15+
signIn(channel:vscode.OutputChannel):void;
16+
signOut(channel:vscode.OutputChannel):void;
1817
}
1918

2019
classLeetCodeManagerextendsEventEmitterimplementsILeetCodeManager{
@@ -27,9 +26,9 @@ class LeetCodeManager extends EventEmitter implements ILeetCodeManager {
2726
this.userStatus=UserStatus.SignedOut;
2827
}
2928

30-
publicasyncgetLoginStatus():Promise<void>{
29+
publicasyncgetLoginStatus(channel:vscode.OutputChannel):Promise<void>{
3130
try{
32-
constresult=awaitexecuteCommand("node",[leetCodeBinaryPath,"user"]);
31+
constresult=awaitexecuteCommand(channel,"node",[leetCodeBinaryPath,"user"]);
3332
this.currentUser=result.slice("You are now login as".length).trim();
3433
this.userStatus=UserStatus.SignedIn;
3534
}catch(error){
@@ -40,18 +39,18 @@ class LeetCodeManager extends EventEmitter implements ILeetCodeManager {
4039
}
4140
}
4241

43-
publicasyncsignIn():Promise<void>{
42+
publicasyncsignIn(channel:vscode.OutputChannel):Promise<void>{
4443
try{
4544
constuserName:string|undefined=awaitnewPromise(async(resolve:(res:string|undefined)=>void,reject:(e:Error)=>void):Promise<void>=>{
4645
letresult:string="";
4746
constchildProc:cp.ChildProcess=cp.spawn("node",[leetCodeBinaryPath,"user","-l"]);
4847
childProc.stdout.on("data",(data:string|Buffer)=>{
4948
data=data.toString();
5049
result=result.concat(data);
51-
leetcodeChannel.append(data);
50+
channel.append(data);
5251
});
5352

54-
childProc.stderr.on("data",(data:string|Buffer)=>leetcodeChannel.append(data.toString()));
53+
childProc.stderr.on("data",(data:string|Buffer)=>channel.append(data.toString()));
5554

5655
childProc.on("error",reject);
5756
constname:string|undefined=awaitvscode.window.showInputBox({
@@ -90,20 +89,20 @@ class LeetCodeManager extends EventEmitter implements ILeetCodeManager {
9089
this.emit("statusChanged");
9190
}
9291
}catch(error){
93-
promptForOpenOutputChannel("Failed to sign in. Please open the output channel for details",DialogType.error);
92+
promptForOpenOutputChannel("Failed to sign in. Please open the output channel for details",DialogType.error,channel);
9493
}
9594

9695
}
9796

98-
publicasyncsignOut():Promise<void>{
97+
publicasyncsignOut(channel:vscode.OutputChannel):Promise<void>{
9998
try{
100-
awaitexecuteCommand("node",[leetCodeBinaryPath,"user","-L"]);
99+
awaitexecuteCommand(channel,"node",[leetCodeBinaryPath,"user","-L"]);
101100
vscode.window.showInformationMessage("Successfully signed out.");
102101
this.currentUser=undefined;
103102
this.userStatus=UserStatus.SignedOut;
104103
this.emit("statusChanged");
105104
}catch(error){
106-
promptForOpenOutputChannel("Failed to sign out. Please open the output channel for details",DialogType.error);
105+
promptForOpenOutputChannel("Failed to sign out. Please open the output channel for details",DialogType.error,channel);
107106
}
108107
}
109108

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp