Skip to content

Commit e38e1a6

Browse files
Merge pull request #392 from DustinCampbell/improve-omnisharp-logging
Fix OmniSharp download and improve logging
2 parents 56abbd6 + 5ffff21 commit e38e1a6

File tree

2 files changed

+17
-28
lines changed

2 files changed

+17
-28
lines changed

src/omnisharpDownload.ts

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import * as tmp from 'tmp';
1313
import {parse} from 'url';
1414
import {SupportedPlatform, getSupportedPlatform} from './utils';
1515
import {getProxyAgent} from './proxy';
16+
import {OutputChannel} from 'vscode';
1617

17-
const Decompress = require('decompress');
18+
const decompress = require('decompress');
1819

1920
const BaseDownloadUrl = 'https://vscodeoscon.blob.core.windows.net/ext';
2021
const DefaultInstallLocation = path.join(__dirname, '../.omnisharp');
@@ -73,14 +74,14 @@ function download(urlString: string): Promise<stream.Readable> {
7374
});
7475
}
7576

76-
export function downloadOmnisharp(): Promise<boolean> {
77+
export function downloadOmnisharp(output: OutputChannel): Promise<boolean> {
7778
return new Promise<boolean>((resolve, reject) => {
78-
console.log(`[OmniSharp]: Installing to ${DefaultInstallLocation}`);
79+
output.appendLine(`[INFO] Installing to ${DefaultInstallLocation}`);
7980

8081
const assetName = getOmnisharpAssetName();
8182
const urlString = `${BaseDownloadUrl}/${assetName}`;
8283

83-
console.log(`[OmniSharp] Attempting to download ${assetName}...`);
84+
output.appendLine(`[INFO] Attempting to download ${assetName}...`);
8485

8586
return download(urlString)
8687
.then(inStream => {
@@ -89,7 +90,7 @@ export function downloadOmnisharp(): Promise<boolean> {
8990
return reject(err);
9091
}
9192

92-
console.log(`[OmniSharp] Downloading to ${tmpPath}...`);
93+
output.appendLine(`[INFO] Downloading to ${tmpPath}...`);
9394

9495
const outStream = fs.createWriteStream(null, { fd: fd });
9596

@@ -99,30 +100,18 @@ export function downloadOmnisharp(): Promise<boolean> {
99100
outStream.once('finish', () => {
100101
// At this point, the asset has finished downloading.
101102

102-
console.log(`[OmniSharp] Download complete!`);
103+
output.appendLine(`[INFO] Download complete!`);
104+
output.appendLine(`[INFO] Decompressing...`);
103105

104-
let decompress = new Decompress()
105-
.src(tmpPath)
106-
.dest(DefaultInstallLocation);
107-
108-
if (path.extname(assetName).toLowerCase() === '.zip') {
109-
decompress = decompress.use(Decompress.zip());
110-
console.log(`[OmniSharp] Unzipping...`);
111-
}
112-
else {
113-
decompress = decompress.use(Decompress.targz());
114-
console.log(`[OmniSharp] Untaring...`);
115-
}
116-
117-
decompress.run((err, files) => {
118-
if (err) {
106+
return decompress(tmpPath, DefaultInstallLocation)
107+
.then(files => {
108+
output.appendLine(`[INFO] Done! ${files.length} files unpacked.`)
109+
return resolve(true);
110+
})
111+
.error(err => {
112+
output.appendLine(`[ERROR] ${err}`);
119113
return reject(err);
120-
}
121-
122-
console.log(`[OmniSharp] Done! ${files.length} files unpacked.`)
123-
124-
return resolve(true);
125-
});
114+
});
126115
});
127116

128117
inStream.pipe(outStream);

src/omnisharpServerLauncher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function installOmnisharpIfNeeded(output: OutputChannel): Promise<string>
3737
throw err;
3838
}
3939

40-
return downloadOmnisharp().then(_ => {
40+
return downloadOmnisharp(output).then(_ => {
4141
return getOmnisharpLaunchFilePath();
4242
})
4343
});

0 commit comments

Comments
 (0)