Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using package-deps 6 #751

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
150 changes: 0 additions & 150 deletions lib/julia-client.coffee

This file was deleted.

198 changes: 198 additions & 0 deletions lib/julia-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
'use babel'

import etch from 'etch';
import commands from './package/commands';
import config from './package/config';
import menu from './package/menu';
import * as settings from './package/settings';
import * as release from './package/release-note';
import toolbar from './package/toolbar';

// TODO: Update me when tagging a new relase (and release note)
const INK_VERSION_COMPAT = "^0.12.4";
const LATEST_RELEASE_NOTE_VERSION = "0.12.5";

const INK_LINK = '[`ink`](https://github.com/JunoLab/atom-ink)';
const LANGUAGE_JULIA_LINK = '[`language-julia`](https://github.com/JuliaEditorSupport/atom-language-julia)';

import misc from './misc'
import ui from './ui'
import connection from './connection'
import runtime from './runtime'

const JuliaClient = {
// TODO remove these from the export default and export them directly (prevents expensive copy)
// TODO don't use this.message use message directly (prevents expensive copy)
misc: misc,
ui: ui,
connection: connection,
runtime: runtime,

activate(state) {
etch.setScheduler(atom.views);
process.env['TERM'] = 'xterm-256color';
commands.activate(this);
for (let x of [menu, this.connection, this.runtime]) {
x.activate();
}
this.ui.activate(this.connection.client);

this.requireDeps(() => {
settings.updateSettings();

if (atom.config.get('julia-client.firstBoot')) {
this.ui.layout.queryDefaultLayout();
} else {
if (atom.config.get('julia-client.uiOptions.layouts.openDefaultPanesOnStartUp')) {
setTimeout((() => this.ui.layout.restoreDefaultLayout()), 150);
}
}
});
},

requireDeps(fn) {
const isLoaded = atom.packages.isPackageLoaded("ink") && atom.packages.isPackageLoaded("language-julia");

if (isLoaded) {
fn();
} else {
require('atom-package-deps').install('julia-client')
.then(() => this.enableDeps(fn))
.catch(function (err) {
console.error(err);
atom.notifications.addError('Installing Juno\'s dependencies failed.', {
description:
`Juno requires the packages ${INK_LINK} and ${LANGUAGE_JULIA_LINK} to run.
Please install them manually via \`File -> Settings -> Packages\`,
or open a terminal and run

apm install ink
apm install language-julia

and then restart Atom.`,
dismissable: true
}
);
});
}
},

enableDeps(fn) {
const isEnabled = atom.packages.isPackageLoaded("ink") && atom.packages.isPackageLoaded("language-julia");

if (isEnabled) {
fn();
} else {
atom.packages.enablePackage('ink');
atom.packages.enablePackage('language-julia');

if (atom.packages.isPackageLoaded("ink") && atom.packages.isPackageLoaded("language-julia")) {
atom.notifications.addSuccess("Automatically enabled Juno's dependencies.", {
description:
`Juno requires the ${INK_LINK} and ${LANGUAGE_JULIA_LINK} packages.
We've automatically enabled them for you.`,
dismissable: true
}
);

const inkVersion = atom.packages.loadedPackages["ink"].metadata.version;
const semverSatisfies = require('semver/functions/satisfies');
if (!atom.devMode && !semverSatisfies(inkVersion, INK_VERSION_COMPAT)) {
atom.notifications.addWarning("Potentially incompatible `ink` version detected.", {
description:
`Please make sure to upgrade ${INK_LINK} to a version compatible with \`${INK_VERSION_COMPAT}\`.
The currently installed version is \`${inkVersion}\`.

If you cannot install an appropriate version via via \`File -> Settings -> Packages\`,
open a terminal and run

apm install [email protected]

where \`x.y.z\` is satisfies \`${INK_VERSION_COMPAT}\`.`,
dismissable: true
}
);
}

fn();
} else {
atom.notifications.addError("Failed to enable Juno's dependencies.", {
description:
`Juno requires the ${INK_LINK} and ${LANGUAGE_JULIA_LINK} packages.
Please install them manually via \`File -> Settings -> Packages\`,
or open a terminal and run

apm install ink
apm install language-julia

and then restart Atom.`,
dismissable: true
}
);
}
}
},

config,

deactivate() {
[commands, menu, toolbar, release, this.connection, this.runtime, this.ui].map((x) => x.deactivate());
},

consumeInk(ink) {
commands.ink = ink;
for (let x of [this.connection, this.runtime, this.ui]) {
x.consumeInk(ink);
}
try {
const v = atom.config.get('julia-client.currentVersion');
if (v !== LATEST_RELEASE_NOTE_VERSION) {
release.activate(ink, LATEST_RELEASE_NOTE_VERSION);
} else {
release.activate(ink);
}
} catch (err) {
console.log(err);
} finally {
atom.config.set('julia-client.currentVersion', LATEST_RELEASE_NOTE_VERSION);
}
},

consumeStatusBar(bar) {
this.runtime.consumeStatusBar(bar);
},

consumeToolBar(bar) {
toolbar.consumeToolBar(bar);
},

consumeGetServerConfig(conf) {
this.connection.consumeGetServerConfig(conf);
},

consumeGetServerName(name) {
this.connection.consumeGetServerName(name);
},

consumeDatatip(datatipService) {
this.runtime.consumeDatatip(datatipService);
},

provideClient() {
return this.connection.client;
},

provideAutoComplete() {
return this.runtime.provideAutoComplete();
},

provideHyperclick() {
return this.runtime.provideHyperclick();
},

handleURI(parsedURI) {
this.runtime.handleURI(parsedURI);
}
};

export default JuliaClient;
13 changes: 13 additions & 0 deletions lib/ui/katexify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use babel'

// this file is lazy loaded by dynamic import simulation

import { renderToString } from 'katex'

export function texify (input, block) {
try {
return renderToString(input, {throwOnError: false, displayMode: block})
} catch (e) {
return input
}
}
8 changes: 7 additions & 1 deletion lib/ui/views.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ module.exports = views =

latex: ({attrs, text}) ->
block = attrs?.block || false
latex = @ink.KaTeX.texify(text, block)

# dynamic import simulation
latex = null
texify = Promise.resolve()
.then( () -> return require("./katexify.js"))
.then( (texify) -> latex = texify(text, block));

@render {type: 'html', block, content: latex}

views:
Expand Down
Loading