提交 dcdc6401 编写于 作者: J Joao Moreno

fixes #4169

上级 4da8ef4e
......@@ -22,10 +22,19 @@ import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { IEditorService } from 'vs/platform/editor/common/editor';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
interface ILegacyUse {
file: string;
lineNumber: number;
}
function ignore<T>(code: string, value: T = null): (err: any) => TPromise<T> {
return err => err.code === code ? TPromise.as<T>(value) : TPromise.wrapError<T>(err);
}
function readOrEmpty(name: string): TPromise<string> {
return pfs.readFile(name, 'utf8').then(null, ignore('ENOENT', ''));
}
const root = URI.parse(require.toUrl('')).fsPath;
const source = path.resolve(root, '..', 'bin', 'code');
const isAvailable = fs.existsSync(source);
......@@ -55,12 +64,12 @@ class InstallAction extends Action {
run(): TPromise<void> {
return this.checkLegacy()
.then(files => {
if (files.length > 0) {
const file = files[0];
.then(uses => {
if (uses.length > 0) {
const { file, lineNumber } = uses[0];
const resource = URI.create('file', null, file);
const env = this.contextService.getConfiguration().env;
const message = nls.localize('exists', "Please remove the alias referencing '{0}' in '{1}' and retry this action.", env.darwinBundleIdentifier, file);
const message = nls.localize('exists', "Please remove the alias referencing '{0}' in '{1}' (line {2}) and retry this action.", env.darwinBundleIdentifier, file, lineNumber);
const input = { resource, mime: 'text/x-shellscript' };
const actions = [
new Action('inlineEdit', nls.localize('editFile', "Edit '{0}'", file), '', true, () => {
......@@ -133,10 +142,7 @@ class InstallAction extends Action {
});
}
public checkLegacy(): TPromise<string[]> {
const readOrEmpty = name => pfs.readFile(name, 'utf8')
.then(null, ignore('ENOENT', ''));
checkLegacy(): TPromise<ILegacyUse[]> {
const files = [
path.join(os.homedir(), '.bash_profile'),
path.join(os.homedir(), '.bashrc'),
......@@ -145,14 +151,21 @@ class InstallAction extends Action {
return TPromise.join(files.map(f => readOrEmpty(f))).then(result => {
return result.reduce((result, contents, index) => {
const file = files[index];
const env = this.contextService.getConfiguration().env;
const lines = contents.split(/\r?\n/);
if (contents.indexOf(env.darwinBundleIdentifier) > -1) {
result.push(files[index]);
}
lines.some((line, index) => {
if (line.indexOf(env.darwinBundleIdentifier) > -1 && !/^\s*#/.test(line)) {
result.push({ file, lineNumber: index + 1 });
return true;
}
return false;
});
return result;
}, []);
}, [] as ILegacyUse[]);
});
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册