Use new Kite install flow by abe33 · Pull Request #385 · autocomplete-python/autocomplete-python · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
73 changes: 35 additions & 38 deletions lib/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -152,68 +152,65 @@ module.exports =
{
AccountManager,
AtomHelper,
compatibility,
Installation,
Installer,
Metrics,
Logger,
StateController
StateController,
NodeClient,
install
} = require 'kite-installer'

if atom.config.get('kite.loggingLevel')
Logger.LEVEL = Logger.LEVELS[atom.config.get('kite.loggingLevel').toUpperCase()]

AccountManager.initClient 'alpha.kite.com', -1, true
atom.views.addViewProvider Installation, (m) -> m.element
editorCfg =
UUID: localStorage.getItem('metrics.userId')
name: 'atom'
pluginCfg =
name: 'autocomplete-python'

Metrics.Tracker.name = "atom acp"
Metrics.Tracker.source = 'autocomplete-python'
Metrics.enabled = atom.config.get('core.telemetryConsent') is 'limited'

atom.packages.onDidActivatePackage (pkg) =>
if pkg.name is 'kite'
@patchKiteCompletions(pkg)
Metrics.Tracker.name = "atom kite+acp"

checkKiteInstallation = () =>
if not atom.config.get 'autocomplete-python.useKite'
return
canInstall = StateController.canInstallKite()
compatible = compatibility.check()
Promise.all([compatible, canInstall]).then((values) =>
atom.config.set 'autocomplete-python.useKite', true
variant = {}
Metrics.Tracker.props = variant
Metrics.Tracker.props.lastEvent = event
title = "Choose a autocomplete-python engine"
@installation = new Installation variant, title
@installation.accountCreated(() =>
atom.config.set 'autocomplete-python.useKite', true
return unless atom.config.get 'autocomplete-python.useKite'

StateController.canInstallKite().then(() ->
Install = install.Install
installer = new Install(install.atom().autocompletePythonFlow(), {
path: atom.project.getPaths()[0] || os.homedir(),
}, {
failureStep: 'termination',
title: 'Choose your autocomplete-python engine',
})

initialClient = AccountManager.client
AccountManager.client = new NodeClient('alpha.kite.com', -1, '', true)

atom.workspace.getActivePane().addItem(installer)
atom.workspace.getActivePane().activateItem(installer)

installed = false

installer.onDidDestroy(->
atom.config.set('autocomplete-python.useKite', installed)
AccountManager.client = initialClient
)
@installation.flowSkipped(() =>
atom.config.set 'autocomplete-python.useKite', false

installer.onDidUdpdateState((state) ->
if typeof state.install != 'undefined'
installed = state.install.done || false
)
[projectPath] = atom.project.getPaths()
root = if projectPath? and path.relative(os.homedir(), projectPath).indexOf('..') is 0
path.parse(projectPath).root
else
os.homedir()

installer = new Installer([root])
installer.init @installation.flow, ->
Logger.verbose('in onFinish')
atom.packages.activatePackage('kite')
installer.on('did-skip-install', () ->
installed = false
atom.config.set('autocomplete-python.useKite', installed)
)

pane = atom.workspace.getActivePane()
@installation.flow.onSkipInstall () =>
atom.config.set 'autocomplete-python.useKite', false
pane.destroyActiveItem()
pane.addItem @installation, index: 0
pane.activateItemAtIndex 0
installer.start()
, (err) =>
if typeof err != 'undefined' and err.type == 'denied'
atom.config.set 'autocomplete-python.useKite', false
Expand Down
2 changes: 1 addition & 1 deletion package.json