|
1 | | -/////////////////////////////////////////////////////////////////////////////// |
2 | | -/* |
3 | | -Main Extension module. Contains activate function, command registrations, |
4 | | -and registers the Workspace Explorer data tree provider. |
5 | | -
|
6 | | -@author tomsaunders |
7 | | -
|
8 | | -*/ |
9 | | - |
10 | | -/////////////////////////////////////////////////////////////////////////////// |
11 | | -// Imports |
12 | | -/////////////////////////////////////////////////////////////////////////////// |
| 1 | +// ------------------------------------------------------------------ // |
| 2 | +// Main Extension module. Contains activate function, |
| 3 | +// command registrations, and registers the Workspace Explorer |
| 4 | +// data tree provider. |
| 5 | +// ------------------------------------------------------------------ // |
13 | 6 |
|
14 | 7 | const vscode = require('vscode'); |
15 | | -const { WorkspaceTreeDataProvider } = require('./workspaceDataTreeProvider'); |
16 | 8 | const { spawn } = require('child_process'); |
17 | | -const os = require("os"); |
18 | | -const fs = require("fs"); |
19 | | -const path = require("path"); |
20 | | - |
21 | | -/////////////////////////////////////////////////////////////////////////////// |
22 | | -// Main |
23 | | -/////////////////////////////////////////////////////////////////////////////// |
| 9 | +const os = require('os'); |
| 10 | +const fs = require('fs'); |
| 11 | +const path = require('path'); |
| 12 | +const { WorkspaceTreeDataProvider } = require('./workspaceDataTreeProvider'); |
24 | 13 |
|
25 | | -/* |
26 | | -Activates the Extension when the Explorer view-container is open |
27 | | -and the workspace explorer is expanded. |
28 | | -*/ |
| 14 | +// Activates the Extension when the Explorer view-container is open |
| 15 | +// and the workspace explorer is expanded. |
29 | 16 | function activate() { |
30 | | - /* |
31 | | - Grab the extension version from the package.json file and publish |
32 | | - it on key commands. |
33 | | - */ |
34 | | - let extensionVersion = JSON.parse( |
35 | | - fs.readFileSync( |
36 | | - path.join( |
37 | | - path.dirname(__filename), |
38 | | - 'package.json' |
39 | | - ), |
40 | | - "utf8" |
41 | | - )).version; |
| 17 | + // Grab the extension version from the package.json file and publish |
| 18 | + // it on key commands. |
| 19 | + const extensionVersion = JSON.parse( |
| 20 | + fs.readFileSync( |
| 21 | + path.join( |
| 22 | + path.dirname(__filename), |
| 23 | + 'package.json', |
| 24 | + ), |
| 25 | + 'utf8', |
| 26 | + ), |
| 27 | + ).version; |
42 | 28 |
|
43 | | - console.log( |
44 | | - `[vscode-workspace-explorer] ${extensionVersion} ==> Activated` |
45 | | - ); |
| 29 | + console.log( |
| 30 | + `[vscode-workspace-explorer] ${extensionVersion} ==> Activated`, |
| 31 | + ); |
46 | 32 |
|
47 | 33 |
|
48 | | - // Identify which application to use. |
49 | | - let applicationName; |
50 | | - if (vscode.env.appName == "Visual Studio Code - Insiders"){ |
51 | | - applicationName = "code-insiders"; |
52 | | - } else { |
53 | | - applicationName = "code"; |
54 | | - } |
| 34 | + // Identify which application to use. |
| 35 | + let applicationName; |
| 36 | + if (vscode.env.appName == 'Visual Studio Code - Insiders') { |
| 37 | + applicationName = 'code-insiders'; |
| 38 | + } else { |
| 39 | + applicationName = 'code'; |
| 40 | + } |
55 | 41 |
|
56 | | - // Register open in new window command. |
57 | | - vscode.commands.registerCommand( |
58 | | - "workspaceExplorer.openWorkspaceInNewWindow", |
59 | | - (context) => { |
60 | | - console.log( |
61 | | - `[vscode-workspace-explorer] ${extensionVersion} ==> Opening ` + |
62 | | - `${context.workspaceFileNameAndFilePath} in a new window.`); |
63 | | - let results = spawn( |
64 | | - applicationName, |
65 | | - [`"${context.workspaceFileNameAndFilePath}"`], |
66 | | - {cwd: os.homedir(), detached: true, shell: true} |
67 | | - ); |
| 42 | + // Register open in new window command. |
| 43 | + vscode.commands.registerCommand( |
| 44 | + 'workspaceExplorer.openWorkspaceInNewWindow', |
| 45 | + (context) => { |
| 46 | + console.log( |
| 47 | + `[vscode-workspace-explorer] ${extensionVersion} ==> Opening ` |
| 48 | + + `${context.workspaceFileNameAndFilePath} in a new window.`, |
| 49 | + ); |
| 50 | + const results = spawn( |
| 51 | + applicationName, |
| 52 | + [`"${context.workspaceFileNameAndFilePath}"`], |
| 53 | + { cwd: os.homedir(), detached: true, shell: true }, |
| 54 | + ); |
68 | 55 |
|
69 | | - results.stdout.on('data', (data) => { |
70 | | - console.log(`stdout ${data}`) |
71 | | - }) |
| 56 | + results.stdout.on('data', (data) => { |
| 57 | + console.log(`stdout ${data}`); |
| 58 | + }); |
| 59 | + }, |
| 60 | + ); |
72 | 61 |
|
73 | | - }); |
| 62 | + // Register open in same window command. |
| 63 | + vscode.commands.registerCommand( |
| 64 | + 'workspaceExplorer.openWorkspaceInSameWindow', |
| 65 | + (workspaceFileNameAndFilePath) => { |
| 66 | + console.log( |
| 67 | + `[vscode-workspace-explorer] ${extensionVersion} ` |
| 68 | + + '==> Opening ' |
| 69 | + + `${workspaceFileNameAndFilePath} in this window.`, |
| 70 | + ); |
| 71 | + spawn( |
| 72 | + applicationName, |
| 73 | + ['-r', `"${workspaceFileNameAndFilePath}"`], |
| 74 | + { cwd: os.homedir(), detached: true, shell: true }, |
| 75 | + ); |
| 76 | + }, |
| 77 | + ); |
74 | 78 |
|
75 | | - // Register open in same window command. |
76 | | - vscode.commands.registerCommand( |
77 | | - "workspaceExplorer.openWorkspaceInSameWindow", |
78 | | - (workspaceFileNameAndFilePath) => { |
79 | | - console.log( |
80 | | - `[vscode-workspace-explorer] ${extensionVersion} ` + |
81 | | - "==> Opening " + |
82 | | - `${workspaceFileNameAndFilePath} in this window.`); |
83 | | - spawn( |
84 | | - applicationName, |
85 | | - ['-r', `"${workspaceFileNameAndFilePath}"`], |
86 | | - {cwd: os.homedir(), detached: true, shell: true} |
87 | | - ); |
88 | | - }) |
| 79 | + // Register Refresh Command. |
| 80 | + vscode.commands.registerCommand( |
| 81 | + 'workspaceExplorer.refreshWorkspaceExplorer', |
| 82 | + () => { |
| 83 | + console.log( |
| 84 | + `[vscode-workspace-explorer] ${extensionVersion} ` |
| 85 | + + '==> Refreshing Workspace Explorer', |
| 86 | + ); |
| 87 | + dataTreeProvider.refresh(); |
| 88 | + }, |
| 89 | + ); |
89 | 90 |
|
90 | | - // Register Refresh Command. |
91 | | - vscode.commands.registerCommand( |
92 | | - "workspaceExplorer.refreshWorkspaceExplorer", |
93 | | - () => { |
94 | | - console.log( |
95 | | - `[vscode-workspace-explorer] ${extensionVersion} ` + |
96 | | - "==> Refreshing Workspace Explorer"); |
97 | | - dataTreeProvider.refresh(); |
98 | | - }); |
| 91 | + // Register Settings Command. |
| 92 | + vscode.commands.registerCommand( |
| 93 | + 'workspaceExplorer.openWorkspaceExplorerSettings', |
| 94 | + () => { |
| 95 | + console.log( |
| 96 | + `[vscode-workspace-explorer] ${extensionVersion} ` |
| 97 | + + '==> Opening Settings for Workspace Explorer', |
| 98 | + ); |
| 99 | + vscode.commands.executeCommand('workbench.action.openSettings2'); |
| 100 | + }, |
| 101 | + ); |
99 | 102 |
|
100 | | - // Register Settings Command. |
101 | | - vscode.commands.registerCommand( |
102 | | - "workspaceExplorer.openWorkspaceExplorerSettings", |
103 | | - () => { |
104 | | - console.log( |
105 | | - `[vscode-workspace-explorer] ${extensionVersion} ` + |
106 | | - "==> Opening Settings for Workspace Explorer"); |
107 | | - vscode.commands.executeCommand('workbench.action.openSettings2') |
108 | | - }); |
109 | | - |
110 | | - // Build tree structure. |
111 | | - const dataTreeProvider = new WorkspaceTreeDataProvider(); |
112 | | - vscode.window.registerTreeDataProvider( |
113 | | - "workspaceExplorer", dataTreeProvider |
114 | | - ); |
115 | | - |
| 103 | + // Build tree structure. |
| 104 | + const dataTreeProvider = new WorkspaceTreeDataProvider(); |
| 105 | + vscode.window.registerTreeDataProvider( |
| 106 | + 'workspaceExplorer', dataTreeProvider, |
| 107 | + ); |
116 | 108 | } |
117 | 109 | exports.activate = activate; |
0 commit comments