@@ -15,7 +15,7 @@ const bool _includeInsiders = false;
15
15
class VsCode {
16
16
static const String extensionIdentifier = 'Dart-Code.dart-code' ;
17
17
18
- VsCode ._(this .directory, this .extensionDirectory, { Version version })
18
+ VsCode ._(this .directory, this .extensionDirectory, { Version version, this .edition })
19
19
: this .version = version ?? Version .unknown {
20
20
21
21
if (! fs.isDirectorySync (directory)) {
@@ -50,22 +50,25 @@ class VsCode {
50
50
final String directory;
51
51
final String extensionDirectory;
52
52
final Version version;
53
+ final String edition;
53
54
54
55
bool _isValid = false ;
55
56
Version _extensionVersion;
56
57
final List <String > _validationMessages = < String > [];
57
58
58
- factory VsCode .fromDirectory (String installPath, String extensionDirectory) {
59
+ factory VsCode .fromDirectory (String installPath, String extensionDirectory,
60
+ { String edition }) {
59
61
final String packageJsonPath =
60
62
fs.path.join (installPath, 'resources' , 'app' , 'package.json' );
61
63
final String versionString = _getVersionFromPackageJson (packageJsonPath);
62
64
Version version;
63
65
if (versionString != null )
64
66
version = new Version .parse (versionString);
65
- return new VsCode ._(installPath, extensionDirectory, version: version);
67
+ return new VsCode ._(installPath, extensionDirectory, version: version, edition : edition );
66
68
}
67
69
68
70
bool get isValid => _isValid;
71
+ String get productName => 'VS Code' + (edition != null ? ', $edition ' : '' );
69
72
70
73
Iterable <String > get validationMessages => _validationMessages;
71
74
@@ -90,21 +93,26 @@ class VsCode {
90
93
// $HOME/.vscode/extensions
91
94
// $HOME/.vscode-insiders/extensions
92
95
static List <VsCode > _installedMacOS () {
93
- final Map <String , String > stable = < String , String > {
94
- fs.path.join ('/Applications' , 'Visual Studio Code.app' , 'Contents' ):
95
- '.vscode' ,
96
- fs.path.join (homeDirPath, 'Applications' , 'Visual Studio Code.app' ,
97
- 'Contents' ): '.vscode'
98
- };
99
- final Map <String , String > insiders = < String , String > {
100
- fs.path.join (
101
- '/Applications' , 'Visual Studio Code - Insiders.app' , 'Contents' ):
102
- '.vscode-insiders' ,
103
- fs.path.join (homeDirPath, 'Applications' ,
104
- 'Visual Studio Code - Insiders.app' , 'Contents' ): '.vscode-insiders'
105
- };
106
-
107
- return _findInstalled (stable, insiders);
96
+ return _findInstalled (< _VsCodeInstallLocation > [
97
+ new _VsCodeInstallLocation (
98
+ fs.path.join ('/Applications' , 'Visual Studio Code.app' , 'Contents' ),
99
+ '.vscode' ,
100
+ ),
101
+ new _VsCodeInstallLocation (
102
+ fs.path.join (homeDirPath, 'Applications' , 'Visual Studio Code.app' , 'Contents' ),
103
+ '.vscode' ,
104
+ ),
105
+ new _VsCodeInstallLocation (
106
+ fs.path.join ('/Applications' , 'Visual Studio Code - Insiders.app' , 'Contents' ),
107
+ '.vscode-insiders' ,
108
+ isInsiders: true ,
109
+ ),
110
+ new _VsCodeInstallLocation (
111
+ fs.path.join (homeDirPath, 'Applications' , 'Visual Studio Code - Insiders.app' , 'Contents' ),
112
+ '.vscode-insiders' ,
113
+ isInsiders: true ,
114
+ )
115
+ ]);
108
116
}
109
117
110
118
// Windows:
@@ -120,17 +128,16 @@ class VsCode {
120
128
final String progFiles86 = platform.environment['programfiles(x86)' ];
121
129
final String progFiles = platform.environment['programfiles' ];
122
130
123
- final Map <String , String > stable = < String , String > {
124
- fs.path.join (progFiles86, 'Microsoft VS Code' ): '.vscode' ,
125
- fs.path.join (progFiles, 'Microsoft VS Code' ): '.vscode'
126
- };
127
- final Map <String , String > insiders = < String , String > {
128
- fs.path.join (progFiles86, 'Microsoft VS Code Insiders' ):
129
- '.vscode-insiders' ,
130
- fs.path.join (progFiles, 'Microsoft VS Code Insiders' ): '.vscode-insiders'
131
- };
132
-
133
- return _findInstalled (stable, insiders);
131
+ return _findInstalled (< _VsCodeInstallLocation > [
132
+ new _VsCodeInstallLocation (fs.path.join (progFiles86, 'Microsoft VS Code' ), '.vscode' ,
133
+ edition: '32-bit edition' ),
134
+ new _VsCodeInstallLocation (fs.path.join (progFiles, 'Microsoft VS Code' ), '.vscode' ,
135
+ edition: '64-bit edition' ),
136
+ new _VsCodeInstallLocation (fs.path.join (progFiles86 , 'Microsoft VS Code Insiders' ), '.vscode-insiders' ,
137
+ edition: '32-bit edition' , isInsiders: true ),
138
+ new _VsCodeInstallLocation (fs.path.join (progFiles, 'Microsoft VS Code Insiders' ), '.vscode-insiders' ,
139
+ edition: '64-bit edition' , isInsiders: true ),
140
+ ]);
134
141
}
135
142
136
143
// Linux:
@@ -140,26 +147,26 @@ class VsCode {
140
147
// $HOME/.vscode/extensions
141
148
// $HOME/.vscode-insiders/extensions
142
149
static List <VsCode > _installedLinux () {
143
- return _findInstalled (
144
- < String , String > { '/usr/share/code' : '.vscode' } ,
145
- < String , String > { '/usr/share/code-insiders' : '.vscode-insiders' }
146
- );
150
+ return _findInstalled (< _VsCodeInstallLocation > [
151
+ const _VsCodeInstallLocation ( '/usr/share/code' , '.vscode' ) ,
152
+ const _VsCodeInstallLocation ( '/usr/share/code-insiders' , '.vscode-insiders' , isInsiders : true ),
153
+ ] );
147
154
}
148
155
149
156
static List <VsCode > _findInstalled (
150
- Map < String , String > stable, Map < String , String > insiders ) {
151
- final Map < String , String > allPaths = < String , String > {};
152
- allPaths. addAll (stable);
153
- if (_includeInsiders)
154
- allPaths. addAll (insiders );
157
+ List < _VsCodeInstallLocation > allLocations ) {
158
+ final Iterable < _VsCodeInstallLocation > searchLocations =
159
+ _includeInsiders
160
+ ? allLocations
161
+ : allLocations. where (( _VsCodeInstallLocation p) => p.isInsiders != true );
155
162
156
163
final List <VsCode > results = < VsCode > [];
157
164
158
- for (String directory in allPaths.keys ) {
159
- if (fs.directory (directory ).existsSync ()) {
165
+ for (_VsCodeInstallLocation searchLocation in searchLocations ) {
166
+ if (fs.directory (searchLocation.installPath ).existsSync ()) {
160
167
final String extensionDirectory =
161
- fs.path.join (homeDirPath, allPaths[directory] , 'extensions' );
162
- results.add (new VsCode .fromDirectory (directory , extensionDirectory));
168
+ fs.path.join (homeDirPath, searchLocation.extensionsFolder , 'extensions' );
169
+ results.add (new VsCode .fromDirectory (searchLocation.installPath , extensionDirectory, edition : searchLocation.edition ));
163
170
}
164
171
}
165
172
@@ -178,3 +185,12 @@ class VsCode {
178
185
return json['version' ];
179
186
}
180
187
}
188
+
189
+ class _VsCodeInstallLocation {
190
+ final String installPath;
191
+ final String extensionsFolder;
192
+ final String edition;
193
+ final bool isInsiders;
194
+ const _VsCodeInstallLocation (this .installPath, this .extensionsFolder, { this .edition, bool isInsiders })
195
+ : this .isInsiders = isInsiders ?? false ;
196
+ }
0 commit comments