1
1
import * as vscode from "vscode" ;
2
2
import { BaselinesProvider , TreeNode } from "./baselines" ;
3
- import { showBaselineDiff } from "./showBaselineDiff" ;
4
3
import { createBaselineFinder } from "./baselineFinder" ;
5
4
import { baselineToTester } from "./baselineToTest" ;
6
5
6
+ // https://code.visualstudio.com/api/references/commands
7
+
7
8
export function activate ( context : vscode . ExtensionContext ) {
8
9
const workspace = vscode . workspace . workspaceFolders ! [ 0 ] ;
9
10
const watcher = createBaselineFinder ( workspace . uri . fsPath ) ;
@@ -12,25 +13,46 @@ export function activate(context: vscode.ExtensionContext) {
12
13
const baselinesProvider = new BaselinesProvider ( watcher . resultsEmitter ) ;
13
14
vscode . window . registerTreeDataProvider ( "tsDev.baselines" , baselinesProvider ) ;
14
15
15
- let disposable = vscode . commands . registerCommand ( "io.orta.typescript-dev.show-baseline-diff" , showBaselineDiff ) ;
16
- context . subscriptions . push ( disposable ) ;
16
+ const getTest = baselineToTester ( { tscRoot : workspace . uri . fsPath } ) ;
17
17
18
- let cmd1 = vscode . commands . registerCommand ( "tsDev.openReferenceShort" , ( item : TreeNode ) => {
18
+ const diffTool = vscode . commands . registerCommand ( "tsDev.openDiffTool" , ( ) => {
19
+ require ( "child_process" ) . exec ( "gulp diff" ) ;
20
+ } ) ;
21
+
22
+ const open = vscode . commands . registerCommand ( "tsDev.openReferenceShort" , ( item : TreeNode ) => {
19
23
vscode . commands . executeCommand ( "vscode.open" , vscode . Uri . parse ( item . uri . fsPath . replace ( "local" , "reference" ) ) ) ;
20
24
} ) ;
21
25
22
- const getTest = baselineToTester ( { tscRoot : workspace . uri . fsPath } ) ;
26
+ const diff = vscode . commands . registerCommand ( "tsDev.openDiffShort" , ( item : TreeNode ) => {
27
+ const local = vscode . Uri . parse ( item . uri . fsPath ) ;
28
+ const ref = vscode . Uri . parse ( item . uri . fsPath . replace ( "local" , "reference" ) ) ;
29
+ vscode . commands . executeCommand ( "vscode.diff" , local , ref , `Diff for ${ item . display } ` ) ;
30
+ } ) ;
23
31
24
- let cmd2 = vscode . commands . registerCommand ( "tsDev.openTestShort" , ( item : TreeNode ) => {
32
+ const test = vscode . commands . registerCommand ( "tsDev.openTestShort" , ( item : TreeNode ) => {
25
33
const testFile = getTest ( item . uri . fsPath ) ;
26
34
if ( ! testFile ) {
27
- vscode . window . showErrorMessage ( `Could not find a test file for ${ item . uri . fsPath } ` ) ;
35
+ vscode . window . showErrorMessage ( `Could not find a test file for ${ item . uri . fsPath } ` , "Copy Local Path" ) . then ( ( res ) => {
36
+ if ( res && res . length ) {
37
+ vscode . env . clipboard . writeText ( item . uri . fsPath ) ;
38
+ vscode . window . showInformationMessage ( "Copied" ) ;
39
+ }
40
+ } ) ;
28
41
} else {
29
- // const [path, number] = testFile.split(":")[0];
30
- // const meta: vscode.TextDocumentShowOptions = ;
31
- // const d = vscode.window.showTextDocument();
32
- vscode . commands . executeCommand ( "vscode.open" , "file:/" + vscode . Uri . parse ( testFile ) ) ;
42
+ const [ path , line ] = testFile . split ( ":" ) ;
43
+ const opts : vscode . TextDocumentShowOptions = line
44
+ ? {
45
+ selection : new vscode . Range ( new vscode . Position ( Number ( line ) , 0 ) , new vscode . Position ( Number ( line ) , 0 ) ) ,
46
+ }
47
+ : { } ;
48
+ vscode . commands . executeCommand ( "vscode.open" , vscode . Uri . parse ( path ) , opts ) ;
33
49
}
34
50
} ) ;
35
- context . subscriptions . push ( cmd2 ) ;
51
+
52
+ const copy = vscode . commands . registerCommand ( "tsDev.copyPath" , ( item : TreeNode ) => {
53
+ vscode . env . clipboard . writeText ( item . uri . fsPath ) ;
54
+ vscode . window . showInformationMessage ( "Copied" ) ;
55
+ } ) ;
56
+
57
+ context . subscriptions . push ( open , test , diff , copy , diffTool ) ;
36
58
}
0 commit comments