@@ -57,7 +57,14 @@ import { executeService } from "../service/ExecuteService";
57
57
import { getNodeIdFromFile } from "../utils/SystemUtils" ;
58
58
import { logOutput , promptForOpenOutputChannel , promptForSignIn , promptHintMessage } from "../utils/OutputUtils" ;
59
59
import { treeDataService } from "../service/TreeDataService" ;
60
- import { genFileExt , genFileName , getyyyymmdd , getDayNowStr } from "../utils/SystemUtils" ;
60
+ import {
61
+ genFileExt ,
62
+ genFileName ,
63
+ getyyyymmdd ,
64
+ getDayNowStr ,
65
+ getTextEditorFilePathByUri ,
66
+ usingCmd ,
67
+ } from "../utils/SystemUtils" ;
61
68
import { IDescriptionConfiguration , isStarShortcut } from "../utils/ConfigUtils" ;
62
69
import * as systemUtils from "../utils/SystemUtils" ;
63
70
import { solutionService } from "../service/SolutionService" ;
@@ -88,33 +95,6 @@ class TreeViewController implements Disposable {
88
95
}
89
96
} , this ) ;
90
97
}
91
- // 获取当前文件的路径
92
- /**
93
- * It returns the path of the currently active file, or undefined if there is no active file
94
- * @param [uri] - The file path to open.
95
- * @returns A promise that resolves to a string or undefined.
96
- */
97
- public async getActiveFilePath ( uri ?: vscode . Uri ) : Promise < string | undefined > {
98
- let textEditor : vscode . TextEditor | undefined ;
99
- if ( uri ) {
100
- textEditor = await vscode . window . showTextDocument ( uri , {
101
- preview : false ,
102
- } ) ;
103
- } else {
104
- textEditor = vscode . window . activeTextEditor ;
105
- }
106
-
107
- if ( ! textEditor ) {
108
- return undefined ;
109
- }
110
- if ( textEditor . document . isDirty && ! ( await textEditor . document . save ( ) ) ) {
111
- vscode . window . showWarningMessage ( "请先保存当前文件" ) ;
112
- return undefined ;
113
- }
114
- return systemUtils . useWsl ( )
115
- ? systemUtils . toWslPath ( textEditor . document . uri . fsPath )
116
- : textEditor . document . uri . fsPath ;
117
- }
118
98
119
99
// 提交问题
120
100
/**
@@ -130,7 +110,7 @@ class TreeViewController implements Disposable {
130
110
return ;
131
111
}
132
112
133
- const filePath : string | undefined = await this . getActiveFilePath ( uri ) ;
113
+ const filePath : string | undefined = await getTextEditorFilePathByUri ( uri ) ;
134
114
if ( ! filePath ) {
135
115
return ;
136
116
}
@@ -160,7 +140,7 @@ class TreeViewController implements Disposable {
160
140
return ;
161
141
}
162
142
163
- const filePath : string | undefined = await this . getActiveFilePath ( uri ) ;
143
+ const filePath : string | undefined = await getTextEditorFilePathByUri ( uri ) ;
164
144
if ( ! filePath ) {
165
145
return ;
166
146
}
@@ -277,7 +257,7 @@ class TreeViewController implements Disposable {
277
257
return ;
278
258
}
279
259
280
- const filePath : string | undefined = await this . getActiveFilePath ( uri ) ;
260
+ const filePath : string | undefined = await getTextEditorFilePathByUri ( uri ) ;
281
261
if ( ! filePath ) {
282
262
return ;
283
263
}
@@ -308,7 +288,7 @@ class TreeViewController implements Disposable {
308
288
return ;
309
289
}
310
290
311
- const filePath : string | undefined = await this . getActiveFilePath ( uri ) ;
291
+ const filePath : string | undefined = await getTextEditorFilePathByUri ( uri ) ;
312
292
if ( ! filePath ) {
313
293
return ;
314
294
}
@@ -324,26 +304,6 @@ class TreeViewController implements Disposable {
324
304
}
325
305
}
326
306
327
- /**
328
- * "If the ComSpec environment variable is not set, or if it is set to cmd.exe, then return true."
329
- *
330
- * The ComSpec environment variable is set to the path of the command processor. On Windows, this is
331
- * usually cmd.exe. On Linux, it is usually bash
332
- * @returns A boolean value.
333
- */
334
- public usingCmd ( ) : boolean {
335
- const comSpec : string | undefined = process . env . ComSpec ;
336
- // 'cmd.exe' is used as a fallback if process.env.ComSpec is unavailable.
337
- if ( ! comSpec ) {
338
- return true ;
339
- }
340
-
341
- if ( comSpec . indexOf ( "cmd.exe" ) > - 1 ) {
342
- return true ;
343
- }
344
- return false ;
345
- }
346
-
347
307
/**
348
308
* If you're on Windows, and you're using cmd.exe, then you need to escape double quotes with
349
309
* backslashes. Otherwise, you don't
@@ -358,7 +318,7 @@ class TreeViewController implements Disposable {
358
318
return `'${ test } '` ;
359
319
}
360
320
361
- if ( this . usingCmd ( ) ) {
321
+ if ( usingCmd ( ) ) {
362
322
// 一般需要走进这里, 除非改了 环境变量ComSpec的值
363
323
if ( systemUtils . useVscodeNode ( ) ) {
364
324
//eslint-disable-next-line
@@ -628,7 +588,7 @@ class TreeViewController implements Disposable {
628
588
}
629
589
} else if ( ! input ) {
630
590
// Triggerred from command
631
- problemInput = await this . getActiveFilePath ( ) ;
591
+ problemInput = await getTextEditorFilePathByUri ( ) ;
632
592
}
633
593
634
594
if ( ! problemInput ) {
@@ -682,7 +642,7 @@ class TreeViewController implements Disposable {
682
642
return ;
683
643
}
684
644
try {
685
- let problemInput = await this . getActiveFilePath ( ) ;
645
+ let problemInput = await getTextEditorFilePathByUri ( ) ;
686
646
// vscode.window.showErrorMessage(twoFactor || "输入错误");
687
647
const solution : string = await executeService . getTestApi ( problemInput || "" ) ;
688
648
solutionService . show ( solution ) ;
0 commit comments