From dada8c98df0607a5d29d6016a939469c27169921 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 8 Jun 2020 03:37:59 -0500 Subject: [PATCH 1/5] decaffeinate lib/connection --- lib/connection.coffee | 52 -------------------------------- lib/connection.js | 70 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 52 deletions(-) delete mode 100644 lib/connection.coffee create mode 100644 lib/connection.js diff --git a/lib/connection.coffee b/lib/connection.coffee deleted file mode 100644 index 40463175..00000000 --- a/lib/connection.coffee +++ /dev/null @@ -1,52 +0,0 @@ -{time} = require './misc' -externalTerminal = require './connection/terminal' - -module.exports = - IPC: require './connection/ipc' - messages: require './connection/messages' - client: require './connection/client' - local: require './connection/local' - terminal: require './connection/terminal' - - activate: -> - @messages.activate() - @client.activate() - @client.boot = => @boot() - @local.activate() - @booting = false - - deactivate: -> - @client.deactivate() - - consumeInk: (ink) -> - @IPC.consumeInk ink - @ink = ink - - consumeGetServerConfig: (getconf) -> - @local.consumeGetServerConfig(getconf) - - consumeGetServerName: (name) -> - @local.consumeGetServerName(name) - - _boot: (provider) -> - if not @client.isActive() and not @booting - @booting = true - @client.setBootMode(provider) - if provider is 'External Terminal' - p = externalTerminal.connectedRepl() - else - p = @local.start(provider) - - if @ink? - @ink.Opener.allowRemoteFiles(provider == 'Remote') - p.then => - @booting = false - p.catch => - @booting = false - time "Julia Boot", @client.import('ping')() - - bootRemote: -> - @_boot('Remote') - - boot: -> - @_boot(atom.config.get('julia-client.juliaOptions.bootMode')) diff --git a/lib/connection.js b/lib/connection.js new file mode 100644 index 00000000..35fe9106 --- /dev/null +++ b/lib/connection.js @@ -0,0 +1,70 @@ +'use babel' +import { time } from './misc'; +import externalTerminal from './connection/terminal'; + +export default { + // TODO Fix all of these dynamic requires and circular dependencies + IPC: require('./connection/ipc'), + messages: require('./connection/messages'), + client: require('./connection/client'), + local: require('./connection/local'), + terminal: require('./connection/terminal'), + + activate() { + this.messages.activate(); + this.client.activate(); + this.client.boot = () => this.boot(); + this.local.activate(); + this.booting = false; + }, + + deactivate() { + this.client.deactivate(); + }, + + consumeInk(ink) { + this.IPC.consumeInk(ink); + this.ink = ink; + }, + + consumeGetServerConfig(getconf) { + this.local.consumeGetServerConfig(getconf); + }, + + consumeGetServerName(name) { + this.local.consumeGetServerName(name); + }, + + _boot(provider) { + if (!this.client.isActive() && !this.booting) { + this.booting = true; + this.client.setBootMode(provider); + + let p; + if (provider === 'External Terminal') { + p = externalTerminal.connectedRepl(); + } else { + p = this.local.start(provider); + } + + if (this.ink) { + this.ink.Opener.allowRemoteFiles(provider === 'Remote'); + } + p.then(() => { + this.booting = false; + }); + p.catch(() => { + this.booting = false; + }); + return time("Julia Boot", this.client.import('ping')()); + } + }, + + bootRemote() { + return this._boot('Remote'); + }, + + boot() { + return this._boot(atom.config.get('julia-client.juliaOptions.bootMode')); + } +}; From bb8fe7041f596437f8e256fd992db8c8c71a8752 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 8 Jun 2020 03:52:44 -0500 Subject: [PATCH 2/5] Fix dynamic requires --- lib/connection.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/connection.js b/lib/connection.js index 35fe9106..2351f764 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -2,13 +2,21 @@ import { time } from './misc'; import externalTerminal from './connection/terminal'; +// TODO use babel to export ... from ... +import IPC from './connection/ipc' +import messages from './connection/messages' +import client from './connection/client' +import local from './connection/local' +import terminal from './connection/terminal' + export default { - // TODO Fix all of these dynamic requires and circular dependencies - IPC: require('./connection/ipc'), - messages: require('./connection/messages'), - client: require('./connection/client'), - local: require('./connection/local'), - terminal: require('./connection/terminal'), + // 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) + IPC: IPC, + messages: messages, + client: client, + local: local, + terminal: terminal, activate() { this.messages.activate(); From 9b8186512a40197d67ad0e5f66823b51276b27ac Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 8 Jun 2020 07:25:23 -0500 Subject: [PATCH 3/5] named export + remove this. Since this is was a module, it remained a module I analyzed these files. All except debugger (updated here) and julia-client (updated in other PR) use named import: File connection.js Found usages (24 usages found) Unclassified usage (17 usages found) lib\runtime (16 usages found) completions.js (1 usage found) 10 import { client } from '../connection' console.js (1 usage found) 3 import { client } from '../connection' datatip.js (1 usage found) 11 import { client } from '../connection' debugger.js (2 usages found) 6 import { client } from '../connection' 7 import connection from '../connection' debuginfo.js (1 usage found) 3 import { client } from '../connection' environments.js (1 usage found) 6 import { client } from '../connection' formatter.js (1 usage found) 4 import { client } from '../connection' frontend.js (1 usage found) 3 import { client } from '../connection' goto.js (1 usage found) 7 import { client } from '../connection' linter.js (1 usage found) 4 import { client } from '../connection' outline.js (1 usage found) 5 import { client } from '../connection' packages.js (1 usage found) 3 import { client } from '../connection' plots.js (1 usage found) 3 import { client } from '../connection' profiler.js (1 usage found) 3 import { client } from '../connection' urihandler.js (1 usage found) 3 import { client } from '../connection' lib\ui (1 usage found) docs.js (1 usage found) 4 import { client } from '../connection' Usage in string literals (7 usages found) lib (1 usage found) julia-client.coffee (1 usage found) 21 connection: require './connection' lib\package (1 usage found) config.coffee (1 usage found) 1 {terminal} = require '../connection' lib\runtime (3 usages found) evaluation.coffee (1 usage found) 5 {client} = require '../connection' modules.coffee (1 usage found) 6 {client} = require '../connection' workspace.coffee (1 usage found) 3 {client} = require '../connection' lib\ui (2 usages found) progress.coffee (1 usage found) 2 {client} = require '../connection' views.coffee (1 usage found) 3 {client} = require '../connection' --- lib/connection.js | 91 ++++++++++++++++++++--------------------- lib/runtime/debugger.js | 27 ++++++------ 2 files changed, 58 insertions(+), 60 deletions(-) diff --git a/lib/connection.js b/lib/connection.js index 2351f764..884fd0c1 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -9,70 +9,69 @@ import client from './connection/client' import local from './connection/local' import terminal from './connection/terminal' -export default { - // 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) - IPC: IPC, - messages: messages, - client: client, - local: local, - terminal: terminal, +exports.IPC = IPC +exports.messages = messages +exports.client = client +exports.local = local +exports.terminal = terminal - activate() { - this.messages.activate(); - this.client.activate(); - this.client.boot = () => this.boot(); - this.local.activate(); - this.booting = false; - }, +let booting = false; +let ink; - deactivate() { - this.client.deactivate(); - }, +export function activate() { + messages.activate(); + client.activate(); + client.boot = () => boot(); + local.activate(); + booting = false; +} - consumeInk(ink) { - this.IPC.consumeInk(ink); - this.ink = ink; - }, +export function deactivate() { + client.deactivate(); +} - consumeGetServerConfig(getconf) { - this.local.consumeGetServerConfig(getconf); - }, +export function consumeInk(ink_in) { + ink = ink_in; + IPC.consumeInk(ink); +} - consumeGetServerName(name) { - this.local.consumeGetServerName(name); - }, +export function consumeGetServerConfig(getconf) { + local.consumeGetServerConfig(getconf); +} - _boot(provider) { - if (!this.client.isActive() && !this.booting) { - this.booting = true; - this.client.setBootMode(provider); +export function consumeGetServerName(name) { + local.consumeGetServerName(name); +} + +export function _boot(provider) { + if (!client.isActive() && !booting) { + booting = true; + client.setBootMode(provider); let p; if (provider === 'External Terminal') { p = externalTerminal.connectedRepl(); } else { - p = this.local.start(provider); + p = local.start(provider); } - if (this.ink) { - this.ink.Opener.allowRemoteFiles(provider === 'Remote'); + if (ink) { + ink.Opener.allowRemoteFiles(provider === 'Remote'); } p.then(() => { - this.booting = false; + booting = false; }); p.catch(() => { - this.booting = false; + booting = false; }); - return time("Julia Boot", this.client.import('ping')()); + return time("Julia Boot", client.import('ping')()); } - }, +} - bootRemote() { - return this._boot('Remote'); - }, +export function bootRemote() { + return _boot('Remote'); +} - boot() { - return this._boot(atom.config.get('julia-client.juliaOptions.bootMode')); - } -}; +export function boot() { + return _boot(atom.config.get('julia-client.juliaOptions.bootMode')); +} diff --git a/lib/runtime/debugger.js b/lib/runtime/debugger.js index 03bed5e7..253fb973 100644 --- a/lib/runtime/debugger.js +++ b/lib/runtime/debugger.js @@ -3,8 +3,7 @@ import { CompositeDisposable } from 'atom' import { views } from '../ui' -import { client } from '../connection' -import connection from '../connection' +import { client, boot as connection_boot } from '../connection' import { blocks, cells, paths } from '../misc' import modules from './modules' @@ -273,53 +272,53 @@ export function debugBlock(shouldStep, cell) { } export function clearbps() { - connection.boot() + connection_boot() breakpoints.clear() if (client.isActive()) client.import('clearbps')() } function toggleJuliaBP (item) { - connection.boot() + connection_boot() return client.import('toggleBP')(item) } function clearJulia () { - connection.boot() + connection_boot() return client.import('clearbps')() } function toggleUncaughtJulia () { - connection.boot() + connection_boot() return client.import('toggleUncaught')() } function toggleExceptionJulia () { - connection.boot() + connection_boot() return client.import('toggleException')() } function toggleCompiled () { - connection.boot() + connection_boot() return client.import('toggleCompiled')() } function getBreakpoints () { - connection.boot() + connection_boot() return client.import('getBreakpoints')() } function addArgsJulia (args) { - connection.boot() + connection_boot() return client.import('addArgs')(args) } function toggleAllActiveJulia (args) { - connection.boot() + connection_boot() return client.import('toggleAllActiveBP')(args) } function toggleActiveJulia (item) { - connection.boot() + connection_boot() return client.import('toggleActiveBP')(item) } function addCondition (item, cond) { - connection.boot() + connection_boot() return client.import('addConditionById')(item, cond) } function setLevel (level) { - connection.boot() + connection_boot() return client.import('setStackLevel')(level) } From 1926ddb5e500e6975b44949b45416d1d26eb4c3c Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 8 Jun 2020 08:07:34 -0500 Subject: [PATCH 4/5] put exports at the end --- lib/connection.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/connection.js b/lib/connection.js index 884fd0c1..b4651886 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -2,19 +2,12 @@ import { time } from './misc'; import externalTerminal from './connection/terminal'; -// TODO use babel to export ... from ... import IPC from './connection/ipc' import messages from './connection/messages' import client from './connection/client' import local from './connection/local' import terminal from './connection/terminal' -exports.IPC = IPC -exports.messages = messages -exports.client = client -exports.local = local -exports.terminal = terminal - let booting = false; let ink; @@ -75,3 +68,9 @@ export function bootRemote() { export function boot() { return _boot(atom.config.get('julia-client.juliaOptions.bootMode')); } + +exports.IPC = IPC +exports.messages = messages +exports.client = client +exports.local = local +exports.terminal = terminal From 9832c51cf505719707020663bc71fabb49ef8af5 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 8 Jun 2020 08:36:05 -0500 Subject: [PATCH 5/5] require directly in coffeescript files --- lib/package/config.coffee | 2 +- lib/runtime/evaluation.coffee | 2 +- lib/runtime/modules.coffee | 2 +- lib/runtime/workspace.coffee | 2 +- lib/ui/progress.coffee | 2 +- lib/ui/views.coffee | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/package/config.coffee b/lib/package/config.coffee index 24cc61c8..0e934fb1 100644 --- a/lib/package/config.coffee +++ b/lib/package/config.coffee @@ -1,4 +1,4 @@ -{terminal} = require '../connection' +terminal = require '../connection/terminal' config = juliaPath: diff --git a/lib/runtime/evaluation.coffee b/lib/runtime/evaluation.coffee index b9c68781..db9f4428 100644 --- a/lib/runtime/evaluation.coffee +++ b/lib/runtime/evaluation.coffee @@ -2,7 +2,7 @@ path = require 'path' {dialog, BrowserWindow} = require('electron').remote -{client} = require '../connection' +client = require '../connection/client' {notifications, views, selector, docpane} = require '../ui' {paths, blocks, cells, words, weave} = require '../misc' {processLinks} = require '../ui/docs' diff --git a/lib/runtime/modules.coffee b/lib/runtime/modules.coffee index 09f98ecd..9a44b90a 100644 --- a/lib/runtime/modules.coffee +++ b/lib/runtime/modules.coffee @@ -3,7 +3,7 @@ {CompositeDisposable, Disposable, Emitter} = require 'atom' {debounce} = require 'underscore-plus' -{client} = require '../connection' +client = require '../connection/client' {show} = require '../ui/selector' {module: getmodule, allmodules, ismodule} = client.import ['module', 'allmodules', 'ismodule'] diff --git a/lib/runtime/workspace.coffee b/lib/runtime/workspace.coffee index e4e9d172..66903421 100644 --- a/lib/runtime/workspace.coffee +++ b/lib/runtime/workspace.coffee @@ -1,6 +1,6 @@ {CompositeDisposable} = require 'atom' -{client} = require '../connection' +client = require '../connection/client' {views} = require '../ui' goto = require './goto' modules = require './modules' diff --git a/lib/ui/progress.coffee b/lib/ui/progress.coffee index d5466317..d2089c3d 100644 --- a/lib/ui/progress.coffee +++ b/lib/ui/progress.coffee @@ -1,5 +1,5 @@ {CompositeDisposable} = require 'atom' -{client} = require '../connection' +client = require '../connection/client' {formatTimePeriod} = require '../misc' module.exports = diff --git a/lib/ui/views.coffee b/lib/ui/views.coffee index dc278d92..ab12ec4b 100644 --- a/lib/ui/views.coffee +++ b/lib/ui/views.coffee @@ -1,6 +1,6 @@ Highlighter = require './highlighter' -{client} = require '../connection' +client = require '../connection/client' {once} = require '../misc' getlazy = client.import 'getlazy'