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

Commitac20b6c

Browse files
committed
using a global output channel to avoid passing outputchannel through functions
1 parent6e920d5 commitac20b6c

File tree

12 files changed

+102
-66
lines changed

12 files changed

+102
-66
lines changed

‎src/commands/list.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ export interface IProblem {
1616
passRate:string;
1717
}
1818

19-
exportasyncfunctionlistProblems(channel:vscode.OutputChannel):Promise<IProblem[]>{
19+
exportasyncfunctionlistProblems():Promise<IProblem[]>{
2020
try{
2121
if(leetCodeManager.getStatus()===UserStatus.SignedOut){
2222
return[];
2323
}
2424
constleetCodeConfig:vscode.WorkspaceConfiguration=vscode.workspace.getConfiguration("leetcode");
2525
constshowLocked:boolean|undefined=leetCodeConfig.get<boolean>("showLocked");
26-
constresult:string=awaitexecuteCommand(channel,"node",showLocked ?[leetCodeBinaryPath,"list"] :[leetCodeBinaryPath,"list","-q","L"]);
26+
constresult:string=awaitexecuteCommand("node",showLocked ?[leetCodeBinaryPath,"list"] :[leetCodeBinaryPath,"list","-q","L"]);
2727
constproblems:IProblem[]=[];
2828
constlines:string[]=result.split("\n");
2929
constreg:RegExp=/^(.)\s(.{1,2})\s(.)\s\[\s*(\d*)\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+%)\)/;
@@ -43,7 +43,7 @@ export async function listProblems(channel: vscode.OutputChannel): Promise<IProb
4343
}
4444
returnproblems.reverse();
4545
}catch(error){
46-
awaitpromptForOpenOutputChannel("Failed to list problems. Please open the output channel for details.",DialogType.error,channel);
46+
awaitpromptForOpenOutputChannel("Failed to list problems. Please open the output channel for details.",DialogType.error);
4747
return[];
4848
}
4949
}

‎src/commands/session.ts

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

9-
exportasyncfunctiongetSessionList(channel:vscode.OutputChannel):Promise<ISession[]>{
9+
exportasyncfunctiongetSessionList():Promise<ISession[]>{
1010
constsignInStatus:string|undefined=leetCodeManager.getUser();
1111
if(!signInStatus){
1212
promptForSignIn();
1313
return[];
1414
}
15-
constresult:string=awaitexecuteCommand(channel,"node",[leetCodeBinaryPath,"session"]);
15+
constresult:string=awaitexecuteCommand("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(channel: vscode.OutputChannel): Promise<ISe
3131
returnsessions;
3232
}
3333

34-
exportasyncfunctionselectSession(channel:vscode.OutputChannel):Promise<void>{
35-
constchoice:IQuickItemEx<string>|undefined=awaitvscode.window.showQuickPick(parseSessionsToPicks(channel));
34+
exportasyncfunctionselectSession():Promise<void>{
35+
constchoice:IQuickItemEx<string>|undefined=awaitvscode.window.showQuickPick(parseSessionsToPicks());
3636
if(!choice||choice.description==="Active"){
3737
return;
3838
}
@@ -41,18 +41,18 @@ export async function selectSession(channel: vscode.OutputChannel): Promise<void
4141
return;
4242
}
4343
try{
44-
awaitexecuteCommand(channel,"node",[leetCodeBinaryPath,"session","-e",choice.value]);
44+
awaitexecuteCommand("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,channel);
48+
awaitpromptForOpenOutputChannel("Failed to switch session. Please open the output channel for details.",DialogType.error);
4949
}
5050
}
5151

52-
asyncfunctionparseSessionsToPicks(channel:vscode.OutputChannel):Promise<Array<IQuickItemEx<string>>>{
52+
asyncfunctionparseSessionsToPicks():Promise<Array<IQuickItemEx<string>>>{
5353
returnnewPromise(async(resolve:(res:Array<IQuickItemEx<string>>)=>void):Promise<void>=>{
5454
try{
55-
constsessions:ISession[]=awaitgetSessionList(channel);
55+
constsessions:ISession[]=awaitgetSessionList();
5656
constpicks:Array<IQuickItemEx<string>>=sessions.map((s:ISession)=>Object.assign({},{
5757
label:`${s.active ?"$(check) " :""}${s.name}`,
5858
description:s.active ?"Active" :"",
@@ -67,12 +67,12 @@ async function parseSessionsToPicks(channel: vscode.OutputChannel): Promise<Arra
6767
});
6868
resolve(picks);
6969
}catch(error){
70-
returnawaitpromptForOpenOutputChannel("Failed to list sessions. Please open the output channel for details.",DialogType.error,channel);
70+
returnawaitpromptForOpenOutputChannel("Failed to list sessions. Please open the output channel for details.",DialogType.error);
7171
}
7272
});
7373
}
7474

75-
exportasyncfunctioncreateSession(channel:vscode.OutputChannel):Promise<void>{
75+
exportasyncfunctioncreateSession():Promise<void>{
7676
constsession:string|undefined=awaitvscode.window.showInputBox({
7777
prompt:"Enter the new session name.",
7878
validateInput:(s:string):string|undefined=>s&&s.trim() ?undefined :"Session name must not be empty",
@@ -81,10 +81,10 @@ export async function createSession(channel: vscode.OutputChannel): Promise<void
8181
return;
8282
}
8383
try{
84-
awaitexecuteCommand(channel,"node",[leetCodeBinaryPath,"session","-c",session]);
84+
awaitexecuteCommand("node",[leetCodeBinaryPath,"session","-c",session]);
8585
vscode.window.showInformationMessage("New session created, you can switch to it by clicking the status bar.");
8686
}catch(error){
87-
awaitpromptForOpenOutputChannel("Failed to create session. Please open the output channel for details.",DialogType.error,channel);
87+
awaitpromptForOpenOutputChannel("Failed to create session. Please open the output channel for details.",DialogType.error);
8888
}
8989
}
9090

‎src/commands/show.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ import { selectWorkspaceFolder } from "../utils/workspaceUtils";
1111
import*aswslfrom"../utils/wslUtils";
1212
import*aslistfrom"./list";
1313

14-
exportasyncfunctionshowProblem(channel:vscode.OutputChannel,node?:LeetCodeNode):Promise<void>{
14+
exportasyncfunctionshowProblem(node?:LeetCodeNode):Promise<void>{
1515
if(!node){
1616
return;
1717
}
18-
awaitshowProblemInternal(channel,node.id);
18+
awaitshowProblemInternal(node.id);
1919
}
2020

21-
exportasyncfunctionsearchProblem(channel:vscode.OutputChannel):Promise<void>{
21+
exportasyncfunctionsearchProblem():Promise<void>{
2222
if(!leetCodeManager.getUser()){
2323
promptForSignIn();
2424
return;
2525
}
2626
constchoice:IQuickItemEx<string>|undefined=awaitvscode.window.showQuickPick(
27-
parseProblemsToPicks(list.listProblems(channel)),
27+
parseProblemsToPicks(list.listProblems()),
2828
{
2929
matchOnDetail:true,
3030
placeHolder:"Select one problem",
@@ -33,10 +33,10 @@ export async function searchProblem(channel: vscode.OutputChannel): Promise<void
3333
if(!choice){
3434
return;
3535
}
36-
awaitshowProblemInternal(channel,choice.value);
36+
awaitshowProblemInternal(choice.value);
3737
}
3838

39-
asyncfunctionshowProblemInternal(channel:vscode.OutputChannel,id:string):Promise<void>{
39+
asyncfunctionshowProblemInternal(id:string):Promise<void>{
4040
try{
4141
constleetCodeConfig:vscode.WorkspaceConfiguration=vscode.workspace.getConfiguration("leetcode");
4242
letdefaultLanguage:string|undefined=leetCodeConfig.get<string>("defaultLanguage");
@@ -50,7 +50,7 @@ async function showProblemInternal(channel: vscode.OutputChannel, id: string): P
5050

5151
constoutdir:string=awaitselectWorkspaceFolder();
5252
awaitfse.ensureDir(outdir);
53-
constresult:string=awaitexecuteCommand(channel,"node",[leetCodeBinaryPath,"show",id,"-gx","-l",language,"-o",`"${outdir}"`]);
53+
constresult:string=awaitexecuteCommand("node",[leetCodeBinaryPath,"show",id,"-gx","-l",language,"-o",`"${outdir}"`]);
5454
constreg:RegExp=/\*SourceCode:\s*(.*)/;
5555
constmatch:RegExpMatchArray|null=result.match(reg);
5656
if(match&&match.length>=2){
@@ -75,7 +75,7 @@ async function showProblemInternal(channel: vscode.OutputChannel, id: string): P
7575
}
7676
}
7777
}catch(error){
78-
awaitpromptForOpenOutputChannel("Failed to fetch the problem information. Please open the output channel for details.",DialogType.error,channel);
78+
awaitpromptForOpenOutputChannel("Failed to fetch the problem information. Please open the output channel for details.",DialogType.error);
7979
}
8080
}
8181

‎src/commands/submit.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { executeCommandWithProgress } from "../utils/cpUtils";
77
import{DialogType,promptForOpenOutputChannel,promptForSignIn,showResultFile}from"../utils/uiUtils";
88
import{getActivefilePath}from"../utils/workspaceUtils";
99

10-
exportasyncfunctionsubmitSolution(channel:vscode.OutputChannel,uri?:vscode.Uri):Promise<void>{
10+
exportasyncfunctionsubmitSolution(uri?:vscode.Uri):Promise<void>{
1111
if(!leetCodeManager.getUser()){
1212
promptForSignIn();
1313
return;
@@ -19,9 +19,9 @@ export async function submitSolution(channel: vscode.OutputChannel, uri?: vscode
1919
}
2020

2121
try{
22-
constresult:string=awaitexecuteCommandWithProgress("Submitting to LeetCode...",channel,"node",[leetCodeBinaryPath,"submit",`"${filePath}"`]);
22+
constresult:string=awaitexecuteCommandWithProgress("Submitting to LeetCode...","node",[leetCodeBinaryPath,"submit",`"${filePath}"`]);
2323
awaitshowResultFile(result);
2424
}catch(error){
25-
awaitpromptForOpenOutputChannel("Failed to submit the solution. Please open the output channel for details.",DialogType.error,channel);
25+
awaitpromptForOpenOutputChannel("Failed to submit the solution. Please open the output channel for details.",DialogType.error);
2626
}
2727
}

‎src/commands/test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { executeCommandWithProgress } from "../utils/cpUtils";
88
import{DialogType,promptForOpenOutputChannel,showFileSelectDialog,showResultFile}from"../utils/uiUtils";
99
import{getActivefilePath}from"../utils/workspaceUtils";
1010

11-
exportasyncfunctiontestSolution(channel:vscode.OutputChannel,uri?:vscode.Uri):Promise<void>{
11+
exportasyncfunctiontestSolution(uri?:vscode.Uri):Promise<void>{
1212
try{
1313
if(leetCodeManager.getStatus()===UserStatus.SignedOut){
1414
return;
@@ -47,7 +47,7 @@ export async function testSolution(channel: vscode.OutputChannel, uri?: vscode.U
4747
letresult:string|undefined;
4848
switch(choice.value){
4949
case":default":
50-
result=awaitexecuteCommandWithProgress("Submitting to LeetCode...",channel,"node",[leetCodeBinaryPath,"test",`"${filePath}"`]);
50+
result=awaitexecuteCommandWithProgress("Submitting to LeetCode...","node",[leetCodeBinaryPath,"test",`"${filePath}"`]);
5151
break;
5252
case":direct":
5353
consttestString:string|undefined=awaitvscode.window.showInputBox({
@@ -57,15 +57,15 @@ export async function testSolution(channel: vscode.OutputChannel, uri?: vscode.U
5757
ignoreFocusOut:true,
5858
});
5959
if(testString){
60-
result=awaitexecuteCommandWithProgress("Submitting to LeetCode...",channel,"node",[leetCodeBinaryPath,"test",`"${filePath}"`,"-t",`"${testString.replace(/"/g,"")}"`]);
60+
result=awaitexecuteCommandWithProgress("Submitting to LeetCode...","node",[leetCodeBinaryPath,"test",`"${filePath}"`,"-t",`"${testString.replace(/"/g,"")}"`]);
6161
}
6262
break;
6363
case":file":
6464
consttestFile:vscode.Uri[]|undefined=awaitshowFileSelectDialog();
6565
if(testFile&&testFile.length){
6666
constinput:string=awaitfse.readFile(testFile[0].fsPath,"utf-8");
6767
if(input.trim()){
68-
result=awaitexecuteCommandWithProgress("Submitting to LeetCode...",channel,"node",[leetCodeBinaryPath,"test",`"${filePath}"`,"-t",`"${input.replace(/"/g,"").replace(/\r?\n/g,"\\n")}"`]);
68+
result=awaitexecuteCommandWithProgress("Submitting to LeetCode...","node",[leetCodeBinaryPath,"test",`"${filePath}"`,"-t",`"${input.replace(/"/g,"").replace(/\r?\n/g,"\\n")}"`]);
6969
}else{
7070
vscode.window.showErrorMessage("The selected test file must not be empty.");
7171
}
@@ -79,6 +79,6 @@ export async function testSolution(channel: vscode.OutputChannel, uri?: vscode.U
7979
}
8080
awaitshowResultFile(result);
8181
}catch(error){
82-
awaitpromptForOpenOutputChannel("Failed to test the solution. Please open the output channel for details.",DialogType.error,channel);
82+
awaitpromptForOpenOutputChannel("Failed to test the solution. Please open the output channel for details.",DialogType.error);
8383
}
8484
}

‎src/extension.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,30 @@ import * as session from "./commands/session";
55
import*asshowfrom"./commands/show";
66
import*assubmitfrom"./commands/submit";
77
import*astestfrom"./commands/test";
8+
import{leetCodeChannel}from"./leetCodeChannel";
89
import{LeetCodeNode,LeetCodeTreeDataProvider}from"./leetCodeExplorer";
910
import{leetCodeManager}from"./leetCodeManager";
1011
import{leetCodeStatusBarItem}from"./leetCodeStatusBarItem";
1112
import{isNodeInstalled}from"./utils/nodeUtils";
1213

1314
exportasyncfunctionactivate(context:vscode.ExtensionContext):Promise<void>{
14-
constchannel:vscode.OutputChannel=vscode.window.createOutputChannel("LeetCode");
15-
if(!awaitisNodeInstalled(channel)){
15+
if(!awaitisNodeInstalled()){
1616
return;
1717
}
18-
leetCodeManager.getLoginStatus(channel);
19-
constleetCodeTreeDataProvider:LeetCodeTreeDataProvider=newLeetCodeTreeDataProvider(context,channel);
18+
leetCodeManager.getLoginStatus();
19+
constleetCodeTreeDataProvider:LeetCodeTreeDataProvider=newLeetCodeTreeDataProvider(context);
2020

2121
context.subscriptions.push(
2222
vscode.window.registerTreeDataProvider("leetCodeExplorer",leetCodeTreeDataProvider),
23-
vscode.commands.registerCommand("leetcode.signin",()=>leetCodeManager.signIn(channel)),
24-
vscode.commands.registerCommand("leetcode.signout",()=>leetCodeManager.signOut(channel)),
25-
vscode.commands.registerCommand("leetcode.selectSessions",()=>session.selectSession(channel)),
26-
vscode.commands.registerCommand("leetcode.createSession",()=>session.createSession(channel)),
27-
vscode.commands.registerCommand("leetcode.showProblem",(node:LeetCodeNode)=>show.showProblem(channel,node)),
28-
vscode.commands.registerCommand("leetcode.searchProblem",()=>show.searchProblem(channel)),
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()),
2929
vscode.commands.registerCommand("leetcode.refreshExplorer",()=>leetCodeTreeDataProvider.refresh()),
30-
vscode.commands.registerCommand("leetcode.testSolution",(uri?:vscode.Uri)=>test.testSolution(channel,uri)),
31-
vscode.commands.registerCommand("leetcode.submitSolution",(uri?:vscode.Uri)=>submit.submitSolution(channel,uri)),
30+
vscode.commands.registerCommand("leetcode.testSolution",(uri?:vscode.Uri)=>test.testSolution(uri)),
31+
vscode.commands.registerCommand("leetcode.submitSolution",(uri?:vscode.Uri)=>submit.submitSolution(uri)),
3232
);
3333

3434
leetCodeManager.on("statusChanged",()=>{
@@ -39,4 +39,5 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
3939

4040
exportfunctiondeactivate():void{
4141
leetCodeStatusBarItem.dispose();
42+
leetCodeChannel.dispose();
4243
}

‎src/leetCodeChannel.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"use strict";
2+
3+
import*asvscodefrom"vscode";
4+
5+
exportinterfaceILeetCodeChannel{
6+
appendLine(message:any,title?:string):void;
7+
append(message:any):void;
8+
show():void;
9+
dispose():void;
10+
}
11+
12+
classLeetCodeChannelimplementsILeetCodeChannel{
13+
privatereadonlychannel:vscode.OutputChannel=vscode.window.createOutputChannel("LeetCode");
14+
15+
publicappendLine(message:string):void{
16+
this.channel.appendLine(message);
17+
}
18+
19+
publicappend(message:string):void{
20+
this.channel.append(message);
21+
}
22+
23+
publicshow():void{
24+
this.channel.show();
25+
}
26+
27+
publicdispose():void{
28+
this.channel.dispose();
29+
}
30+
}
31+
32+
exportconstleetCodeChannel:ILeetCodeChannel=newLeetCodeChannel();

‎src/leetCodeExplorer.ts

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

45-
constructor(privatecontext:vscode.ExtensionContext,privatechannel:vscode.OutputChannel){}
45+
constructor(privatecontext:vscode.ExtensionContext){}
4646

4747
publicasyncrefresh():Promise<void>{
4848
awaitthis.getProblemData();
@@ -100,7 +100,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
100100
}
101101

102102
privateasyncgetProblemData():Promise<void>{
103-
constallProblems:list.IProblem[]=awaitlist.listProblems(this.channel);
103+
constallProblems:list.IProblem[]=awaitlist.listProblems();
104104
this.treeData.clear();
105105
for(constproblemofallProblems){
106106
constproblems:list.IProblem[]|undefined=this.treeData.get(problem.difficulty);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp