33
44'use strict' ;
55
6- import * as fileSystem from 'fs' ;
76import * as path from 'path' ;
8- import * as request from 'request' ;
97import * as requestProgress from 'request-progress' ;
10- import { OutputChannel , ProgressLocation , window } from 'vscode' ;
11- import { STANDARD_OUTPUT_CHANNEL } from '../common/constants' ;
8+ import { ProgressLocation , window } from 'vscode' ;
129import { createDeferred } from '../common/helpers' ;
13- import { IFileSystem , IPlatformService } from '../common/platform/types' ;
10+ import { IFileSystem } from '../common/platform/types' ;
1411import { IExtensionContext , IOutputChannel } from '../common/types' ;
15- import { IServiceContainer } from '../ioc/types' ;
1612import { PlatformData , PlatformName } from './platformData' ;
13+ import { IDownloadFileService } from './types' ;
1714
1815// tslint:disable-next-line:no-require-imports no-var-requires
1916const StreamZip = require ( 'node-stream-zip' ) ;
@@ -31,25 +28,21 @@ export const DownloadLinks = {
3128} ;
3229
3330export class LanguageServerDownloader {
34- private readonly output : OutputChannel ;
35- private readonly platform : IPlatformService ;
36- private readonly platformData : PlatformData ;
37- private readonly fs : IFileSystem ;
38-
39- constructor ( private readonly services : IServiceContainer , private engineFolder : string ) {
40- this . output = this . services . get < OutputChannel > ( IOutputChannel , STANDARD_OUTPUT_CHANNEL ) ;
41- this . fs = this . services . get < IFileSystem > ( IFileSystem ) ;
42- this . platform = this . services . get < IPlatformService > ( IPlatformService ) ;
43- this . platformData = new PlatformData ( this . platform , this . fs ) ;
44- }
45-
46- public async getDownloadUri ( ) {
47- const platformString = await this . platformData . getPlatformName ( ) ;
31+ constructor (
32+ private readonly output : IOutputChannel ,
33+ private readonly fs : IFileSystem ,
34+ private readonly platformData : PlatformData ,
35+ private requestHandler : IDownloadFileService ,
36+ private engineFolder : string
37+ ) { }
38+
39+ public getDownloadUri ( ) {
40+ const platformString = this . platformData . getPlatformName ( ) ;
4841 return DownloadLinks [ platformString ] ;
4942 }
5043
5144 public async downloadLanguageServer ( context : IExtensionContext ) : Promise < void > {
52- const downloadUri = await this . getDownloadUri ( ) ;
45+ const downloadUri = this . getDownloadUri ( ) ;
5346
5447 let localTempFilePath = '' ;
5548 try {
@@ -71,7 +64,7 @@ export class LanguageServerDownloader {
7164 const tempFile = await this . fs . createTemporaryFile ( downloadFileExtension ) ;
7265
7366 const deferred = createDeferred ( ) ;
74- const fileStream = fileSystem . createWriteStream ( tempFile . filePath ) ;
67+ const fileStream = this . fs . createWriteStream ( tempFile . filePath ) ;
7568 fileStream . on ( 'finish' , ( ) => {
7669 fileStream . close ( ) ;
7770 } ) . on ( 'error' , ( err ) => {
@@ -83,7 +76,8 @@ export class LanguageServerDownloader {
8376 location : ProgressLocation . Window
8477 } , ( progress ) => {
8578
86- requestProgress ( request ( uri ) )
79+ requestProgress (
80+ this . requestHandler ! . downloadFile ( uri ) )
8781 . on ( 'progress' , ( state ) => {
8882 // https://www.npmjs.com/package/request-progress
8983 const received = Math . round ( state . size . transferred / 1024 ) ;
@@ -147,11 +141,10 @@ export class LanguageServerDownloader {
147141 return deferred . promise ;
148142 } ) ;
149143
150- // Set file to executable
151- if ( ! this . platform . isWindows ) {
152- const executablePath = path . join ( installFolder , this . platformData . getEngineExecutableName ( ) ) ;
153- fileSystem . chmodSync ( executablePath , '0764' ) ; // -rwxrw-r--
154- }
144+ // Set file to executable (nothing happens in Windows, as chmod has no definition there)
145+ const executablePath = path . join ( installFolder , this . platformData . getEngineExecutableName ( ) ) ;
146+ await this . fs . chmod ( executablePath , '0764' ) ; // -rwxrw-r--
147+
155148 this . output . appendLine ( 'done.' ) ;
156149 }
157150}
0 commit comments