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

Commit126cf7c

Browse files
authored
Update channel feature pt 2 (microsoft#2541)
* Find Mac code script; Commenting; Move code into try catches correctly filter errors; Add notification on installation* Merge files from correct commit* Revert changes made from not having master branch code
1 parentad451bb commit126cf7c

File tree

4 files changed

+97
-40
lines changed

4 files changed

+97
-40
lines changed

‎Extension/src/LanguageServer/extension.ts‎

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { PlatformInformation } from '../platform';
2121
import{Range}from'vscode-languageclient';
2222
import{execSync}from'child_process';
2323
import*astmpfrom'tmp';
24-
import{getTargetBuildUrl}from'../githubAPI';
24+
import{getTargetBuildInfo}from'../githubAPI';
2525

2626
letprevCrashFile:string;
2727
letclients:ClientCollection;
@@ -234,11 +234,22 @@ async function installVsix(vsixLocation: string, updateChannel: string): Promise
234234
returnPlatformInformation.GetPlatformInformation().then((platformInfo)=>{
235235
constvsCodeScriptPath:string=function(platformInfo):string{
236236
if(platformInfo.platform==='win32'){
237-
constvsCodeProcessPath:string=path.dirname(process.execPath);
238-
return'"'+path.join(vsCodeProcessPath,'bin','code.cmd')+'"';
237+
constvsCodeBinName:string=path.basename(process.execPath);
238+
// Windows VS Code Insiders breaks VS Code naming conventions
239+
letcmdFile:string;
240+
if(vsCodeBinName==='Code - Insiders.exe'){
241+
cmdFile='code-insiders.cmd';
242+
}else{
243+
cmdFile='code.cmd';
244+
}
245+
constvsCodeExeDir:string=path.dirname(process.execPath);
246+
return'"'+path.join(vsCodeExeDir,'bin',cmdFile)+'"';
247+
}elseif(platformInfo.platform==='darwin'){
248+
return'"'+path.join(process.execPath,'..','..','..','..','..',
249+
'Resources','app','bin','code')+'"';
239250
}else{
240-
constvsCodeProcessPath:string=path.basename(process.execPath);
241-
conststdout:Buffer=execSync('which '+vsCodeProcessPath);
251+
constvsCodeBinName:string=path.basename(process.execPath);
252+
conststdout:Buffer=execSync('which '+vsCodeBinName);
242253
returnstdout.toString().trim();
243254
}
244255
}(platformInfo);
@@ -255,7 +266,6 @@ async function installVsix(vsixLocation: string, updateChannel: string): Promise
255266
execSync(uninstallCommand);
256267
}
257268
execSync(installCommand);
258-
clearInterval(insiderUpdateTimer);
259269
returnPromise.resolve();
260270
}catch(error){
261271
returnPromise.reject(newError('Failed to install VSIX'));
@@ -269,29 +279,55 @@ async function installVsix(vsixLocation: string, updateChannel: string): Promise
269279
*@param updateChannel The user's updateChannel setting.
270280
*/
271281
asyncfunctioncheckAndApplyUpdate(updateChannel:string):Promise<void>{
282+
// Helper fn to avoid code duplication
283+
letlogFailure:(error:Error)=>void=(error:Error)=>{
284+
telemetry.logLanguageServerEvent('installVsix',{'error':error.message,'success':'false'});
285+
};
286+
// Wrap in new Promise to allow tmp.file callback to successfully resolve/reject
287+
// as tmp.file does not do anything with the callback functions return value
272288
constp:Promise<void>=newPromise<void>((resolve,reject)=>{
273-
getTargetBuildUrl(updateChannel).then(downloadUrl=>{
274-
if(!downloadUrl){
289+
getTargetBuildInfo(updateChannel).then(buildInfo=>{
290+
if(!buildInfo){
275291
resolve();
276292
return;
277293
}
278294

279-
// Create a temporary file, download thevsix to it, then install thevsix
280-
tmp.file({postfix:'.vsix'},(err,vsixPath,fd,cleanupCallback)=>{
295+
// Create a temporary file, download theVSIX to it, then install theVSIX
296+
tmp.file({postfix:'.vsix'},async(err,vsixPath,fd,cleanupCallback)=>{
281297
if(err){
282298
reject(newError('Failed to create vsix file'));
283299
return;
284300
}
285301

286-
util.downloadFileToDestination(downloadUrl,vsixPath)
287-
.then(()=>installVsix(vsixPath,updateChannel))
288-
.then(()=>telemetry.logLanguageServerEvent('installVsix',{'success':'true'}))
289-
.then(()=>resolve(),()=>reject());
302+
// Place in try/catch as the .catch call catches a rejection in downloadFileToDestination
303+
// then the .catch call will return a resolved promise
304+
// Thusly, the .catch call must also throw, as a return would simply return an unused promise
305+
// instead of returning early from this function scope
306+
try{
307+
awaitutil.downloadFileToDestination(buildInfo.downloadUrl,vsixPath)
308+
.catch(()=>{thrownewError('Failed to download VSIX package');});
309+
awaitinstallVsix(vsixPath,updateChannel)
310+
.catch((error:Error)=>{throwerror;});
311+
}catch(error){
312+
reject(error);
313+
return;
314+
}
315+
clearInterval(insiderUpdateTimer);
316+
util.promptReloadWindow(`The C/C++ Extension has been updated to version${buildInfo.name}. \
317+
Please reload the window for the changes to take effect.`);
318+
telemetry.logLanguageServerEvent('installVsix',{'success':'true'});
319+
320+
resolve();
290321
});
291-
},error=>reject(error));
322+
},(error:Error)=>{
323+
// Handle getTargetBuildInfo rejection
324+
logFailure(error);
325+
reject(error);
326+
});
292327
});
293328
returnp.catch((error:Error)=>{
294-
telemetry.logLanguageServerEvent('installVsix',{'error':error.message,'success':'false'});
329+
// Handle .then following getTargetBuildInfo rejection
330+
logFailure(error);
295331
returnPromise.reject(error);
296332
});
297333
}

‎Extension/src/common.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,12 @@ export async function renamePromise(oldName: string, newName: string): Promise<v
572572
}
573573

574574
exportfunctionpromptForReloadWindowDueToSettingsChange():void{
575+
promptReloadWindow("Reload the workspace for the settings change to take effect.");
576+
}
577+
578+
exportfunctionpromptReloadWindow(message:string):void{
575579
letreload:string="Reload";
576-
vscode.window.showInformationMessage("Reload the workspace for the settings change to take effect.",reload).then((value:string)=>{
580+
vscode.window.showInformationMessage(message,reload).then((value:string)=>{
577581
if(value===reload){
578582
vscode.commands.executeCommand("workbench.action.reloadWindow");
579583
}
@@ -604,13 +608,10 @@ export function downloadFileToDestination(urlStr: string, destinationPath: strin
604608
returnreject();
605609
}
606610
// Write file using downloaded data
607-
letdownloadedBytes=0;// tslint:disable-line
608611
letcreatedFile:fs.WriteStream=fs.createWriteStream(destinationPath);
609-
response.on('data',(data)=>{downloadedBytes+=data.length;});
610-
response.on('end',()=>{createdFile.close();});
611-
createdFile.on('close',()=>{resolve();});
612+
createdFile.on('finish',()=>{resolve();});
612613
response.on('error',(error)=>{reject();});
613-
response.pipe(createdFile,{end:false});
614+
response.pipe(createdFile);
614615
});
615616
request.on('error',(error)=>{reject();});
616617
request.end();

‎Extension/src/githubAPI.ts‎

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,35 @@ function vsixNameForPlatform(info: PlatformInformation): string {
113113
returnvsixName;
114114
}
115115

116+
/**
117+
* Interface for return value of getTargetBuildInfo containing the download URL and version of a Build.
118+
*/
119+
exportinterfaceBuildInfo{
120+
downloadUrl:string;
121+
name:string;
122+
}
123+
116124
/**
117125
* Use the GitHub API to retrieve the download URL of the extension version the user should update to, if any.
118126
*@param updateChannel The user's updateChannel setting.
119127
*@return Download URL for the extension VSIX package that the user should install. If the user
120128
* does not need to update, resolves to undefined.
121129
*/
122-
exportasyncfunctiongetTargetBuildUrl(updateChannel:string):Promise<string>{
130+
exportasyncfunctiongetTargetBuildInfo(updateChannel:string):Promise<BuildInfo>{
123131
returngetReleaseJson()
124132
.then(builds=>getTargetBuild(builds,updateChannel))
125-
.then(build=>{
133+
.then(asyncbuild=>{
126134
if(!build){
127135
returnPromise.resolve(undefined);
128136
}
129-
returnPlatformInformation.GetPlatformInformation()
130-
.then(platformInfo=>vsixNameForPlatform(platformInfo))
131-
.then(vsixName=>getVsixDownloadUrl(build,vsixName));
137+
try{
138+
constplatformInfo:PlatformInformation=awaitPlatformInformation.GetPlatformInformation();
139+
constvsixName:string=vsixNameForPlatform(platformInfo);
140+
constdownloadUrl:string=getVsixDownloadUrl(build,vsixName);
141+
return{downloadUrl:downloadUrl,name:build.name};
142+
}catch(error){
143+
returnPromise.reject(error);
144+
}
132145
});
133146
}
134147

@@ -173,30 +186,37 @@ async function getReleaseJson(): Promise<Build[]> {
173186
// Create temp file to hold JSON
174187
tmp.file(async(err,releaseJsonPath,fd,cleanupCallback)=>{
175188
if(err){
176-
returnreject(newError('Failed to create release json file'));
189+
reject(newError('Failed to create release json file'));
190+
return;
177191
}
178192

179-
// Helper functions to handle promise rejection
180-
constrejectDownload:()=>Error=()=>{returnnewError('Failed to download release JSON');};
181-
constrejectRead:()=>Error=()=>{returnnewError('Failed to read release JSON file');};
182-
constrejectParse:()=>Error=()=>{returnnewError('Failed to parse release JSON');};
183-
184193
try{
185194
// Download release JSON
186195
constreleaseUrl:string='https://api.github.com/repos/Microsoft/vscode-cpptools/releases';
187196
constheader:OutgoingHttpHeaders={'User-Agent':'vscode-cpptools'};
188-
awaitutil.downloadFileToDestination(releaseUrl,releaseJsonPath,header).catch(()=>{throwrejectDownload();});
197+
awaitutil.downloadFileToDestination(releaseUrl,releaseJsonPath,header)
198+
.catch(()=>{thrownewError('Failed to download release JSON');});
189199

190200
// Read the release JSON file
191-
constfileContent:string=awaitutil.readFileText(releaseJsonPath).catch(()=>{throwrejectRead();});
201+
constfileContent:string=awaitutil.readFileText(releaseJsonPath)
202+
.catch(()=>{thrownewError('Failed to read release JSON file');});
192203

193204
// Parse the file
194-
constreleaseJson:any=awaitJSON.parse(fileContent).catch(()=>{throwrejectParse();});
205+
letreleaseJson:any;
206+
try{
207+
releaseJson=JSON.parse(fileContent);
208+
}catch(error){
209+
thrownewError('Failed to parse release JSON');
210+
}
195211

196212
// Type check
197-
returnisArrayOfBuilds(releaseJson) ?resolve(releaseJson) :reject(releaseJson);
213+
if(isArrayOfBuilds(releaseJson)){
214+
resolve(releaseJson);
215+
}else{
216+
reject(releaseJson);
217+
}
198218
}catch(error){
199-
returnreject(error);
219+
reject(error);
200220
}
201221
});
202222
});

‎Extension/src/main.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ async function finalizeExtensionActivation(): Promise<void> {
324324
}
325325
}else{
326326
letpackageJson:any=util.getRawPackageJson();
327-
if(packageJson['C_Cpp.updateChannel']==='Default'){
328-
packageJson['C_Cpp.updateChannel']='Insiders';
327+
if(packageJson.contributes.configuration.properties['C_Cpp.updateChannel'].default==='Default'){
328+
packageJson.contributes.configuration.properties['C_Cpp.updateChannel'].default='Insiders';
329329
returnutil.writeFileText(util.getPackageJsonPath(),util.stringifyPackageJson(packageJson));
330330
}
331331
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp