Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge branch 'remove-deprecated-api'
Browse files Browse the repository at this point in the history
  • Loading branch information
joefitzgerald committed Feb 21, 2015
2 parents 928e9ce + 690f7ca commit bfffb38
Show file tree
Hide file tree
Showing 12 changed files with 1 addition and 278 deletions.
28 changes: 0 additions & 28 deletions lib/main.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{Disposable} = require('atom')
Provider = require('./provider')
Suggestion = require('./suggestion')
{deprecate} = require('grim')

module.exports =
config:
Expand Down Expand Up @@ -120,28 +117,6 @@ module.exports =
@autocompleteManager?.dispose()
@autocompleteManager = null

registerProviderForEditorView: (provider, editorView) ->
@registerProviderForEditor(provider, editorView?.getModel())

# Private: Finds the autocomplete for the given TextEditor
# and registers the given provider
#
# provider - The new {Provider}
# editor - The {TextEditor} we should register the provider with
registerProviderForEditor: (provider, editor) ->
return unless @autocompleteManager?.providerManager?
return unless editor?.getGrammar()?.scopeName?
deprecate('registerProviderForEditor and registerProviderForEditorView are no longer supported. Please switch to the new API: https://github.com/atom-community/autocomplete-plus/wiki/Provider-API')
return @getAutocompleteManager().providerManager.registerLegacyProvider(provider, '.' + editor?.getGrammar()?.scopeName)

# Private: unregisters the given provider
#
# provider - The {Provider} to unregister
unregisterProvider: (provider) ->
return unless @getAutocompleteManager()?.providerManager?
deprecate('unregisterProvider is no longer supported. Please switch to the new API: https://github.com/atom-community/autocomplete-plus/wiki/Provider-API')
@getAutocompleteManager().providerManager.unregisterLegacyProvider(provider)

getAutocompleteManager: ->
if @activateTimeout?
clearTimeout(@activateTimeout)
Expand All @@ -151,9 +126,6 @@ module.exports =
@autocompleteManager = new AutocompleteManager()
return @autocompleteManager

Provider: Provider # TODO: This is deprecated, and will be removed soon
Suggestion: Suggestion # TODO: This is deprecated, and will be removed soon

# ||| |||
# vvv PROVIDER API vvv

Expand Down
48 changes: 0 additions & 48 deletions lib/provider-manager.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@ _ = require('underscore-plus')
Uuid = require('node-uuid')
SymbolProvider = require('./symbol-provider')
FuzzyProvider = require('./fuzzy-provider')
Suggestion = require('./suggestion')
Provider = require('./provider')

module.exports =
class ProviderManager
fuzzyProvider: null
fuzzyRegistration: null
store: null
subscriptions: null
legacyProviderRegistrations: null
globalBlacklist: null

constructor: ->
@subscriptions = new CompositeDisposable
@globalBlacklist = new CompositeDisposable
@legacyProviderRegistrations = new WeakMap
@providers = new Map
@store = new ScopedPropertyStore
@subscriptions.add(atom.config.observe('autocomplete-plus.enableBuiltinProvider', (value) => @toggleFuzzyProvider(value)))
Expand All @@ -37,7 +33,6 @@ class ProviderManager
@store = null
@providers?.clear()
@providers = null
@legacyProviderRegistrations = null

providersForScopeChain: (scopeChain) =>
return [] unless scopeChain?
Expand Down Expand Up @@ -93,9 +88,6 @@ class ProviderManager
isValidProvider: (provider) ->
return provider? and provider.requestHandler? and typeof provider.requestHandler is 'function' and provider.selector? and provider.selector isnt '' and provider.selector isnt false

isLegacyProvider: (provider) ->
return provider? and provider instanceof Provider

providerUuid: (provider) =>
return false unless provider?
return false unless @providers.has(provider)
Expand Down Expand Up @@ -174,43 +166,3 @@ class ProviderManager

# ^^^ PROVIDER API ^^^
# ||| |||

# For Legacy use only!!
registerLegacyProvider: (legacyProvider, selector) =>
return unless legacyProvider? and legacyProvider.buildSuggestionsShim?
return unless selector? and selector.trim() isnt ''

legacyProviderRegistration = @legacyProviderRegistrations.get(legacyProvider.constructor)

if legacyProviderRegistration
legacyProviderRegistration.service.dispose()
legacyProviderRegistration.selectors.push(selector) if legacyProviderRegistration.selectors.indexOf(selector) < 0

else
legacyProviderRegistration = {selectors: [selector]}
@legacyProviderRegistrations.set(legacyProvider.constructor, legacyProviderRegistration)

selector = legacyProviderRegistration.selectors.join(',')

legacyProviderRegistration.shim = @shimLegacyProvider(legacyProvider, selector)
legacyProviderRegistration.service = @registerProvider(legacyProviderRegistration.shim)
return legacyProviderRegistration.service

shimLegacyProvider: (legacyProvider, selector) ->
shim =
legacyProvider: legacyProvider
requestHandler: legacyProvider.buildSuggestionsShim
selector: selector
dispose: ->
requestHandler = null
legacyProvider.dispose() if legacyProvider.dispose?
legacyProvider = null
selector = null
shim

unregisterLegacyProvider: (legacyProvider) =>
return unless legacyProvider?
legacyProviderRegistration = @legacyProviderRegistrations.get(legacyProvider.constructor)
if legacyProviderRegistration
legacyProviderRegistration.service.dispose()
@legacyProviderRegistrations.delete(legacyProvider.constructor)
61 changes: 0 additions & 61 deletions lib/provider.coffee

This file was deleted.

11 changes: 0 additions & 11 deletions lib/suggestion.coffee

This file was deleted.

1 change: 0 additions & 1 deletion spec/autocomplete-blacklist-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{triggerAutocompletion, buildIMECompositionEvent, buildTextInputEvent} = require('./spec-helper')
_ = require('underscore-plus')
TestProvider = require('./lib/test-provider')

describe 'Autocomplete', ->
[completionDelay, editorView, editor, mainModule, autocompleteManager] = []
Expand Down
1 change: 0 additions & 1 deletion spec/fuzzy-provider-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{triggerAutocompletion, buildIMECompositionEvent, buildTextInputEvent} = require('./spec-helper')
_ = require('underscore-plus')
TestProvider = require('./lib/test-provider')

describe 'Autocomplete', ->
[completionDelay, editorView, editor, mainModule, autocompleteManager] = []
Expand Down
1 change: 0 additions & 1 deletion spec/html-label-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{waitForAutocomplete} = require('./spec-helper')
TestProvider = require('./lib/test-provider')

describe 'HTML labels', ->
[completionDelay, editorView, editor, mainModule, autocompleteManager, registration] = []
Expand Down
1 change: 0 additions & 1 deletion spec/issues/57-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{waitForAutocomplete, triggerAutocompletion, buildIMECompositionEvent, buildTextInputEvent} = require('../spec-helper')
TestProvider = require('../lib/test-provider')

describe 'Autocomplete', ->
[mainModule, autocompleteManager, editorView, editor, completionDelay, mainModule] = []
Expand Down
15 changes: 0 additions & 15 deletions spec/lib/test-provider.coffee

This file was deleted.

86 changes: 0 additions & 86 deletions spec/provider-api-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{waitForAutocomplete} = require('./spec-helper')
TestProvider = require('./lib/test-provider')
_ = require('underscore-plus')

describe 'Provider API', ->
Expand Down Expand Up @@ -44,91 +43,6 @@ describe 'Provider API', ->
waitsForPromise ->
atom.packages.activatePackage('language-javascript')

describe 'Legacy Provider API', ->
it 'registers the given provider for the given editor', ->
runs ->
expect(autocompleteManager.providerManager.store).toBeDefined()
expect(_.size(autocompleteManager.providerManager.providersForScopeChain('.source.js'))).toEqual(1)

testProvider = new TestProvider()
expect(autocompleteManager.providerManager.isLegacyProvider(testProvider)).toEqual(true)
registration = mainModule.registerProviderForEditor(testProvider, editor)

expect(_.size(autocompleteManager.providerManager.providersForScopeChain('.source.js'))).toEqual(2)
expect(autocompleteManager.providerManager.legacyProviderRegistrations.has(testProvider.constructor)).toEqual(true)
providerRegistration = autocompleteManager.providerManager.legacyProviderRegistrations.get(testProvider.constructor)
expect(providerRegistration.selectors).toEqual(['.source.js'])
expect(_.contains(autocompleteManager.providerManager.providersForScopeChain('.source.js'), testProvider)).toEqual(false)
expect(_.contains(autocompleteManager.providerManager.providersForScopeChain('.source.js'), providerRegistration.shim)).toEqual(true)

it 'registers the given provider once when called multiple times for the given editor', ->
runs ->
expect(autocompleteManager.providerManager.store).toBeDefined()
expect(_.size(autocompleteManager.providerManager.providersForScopeChain('.source.js'))).toEqual(1)

testProvider = new TestProvider()
expect(autocompleteManager.providerManager.isLegacyProvider(testProvider)).toEqual(true)
registration = mainModule.registerProviderForEditor(testProvider, editor)

expect(_.size(autocompleteManager.providerManager.providersForScopeChain('.source.js'))).toEqual(2)
expect(autocompleteManager.providerManager.legacyProviderRegistrations.has(testProvider.constructor)).toEqual(true)
providerRegistration = autocompleteManager.providerManager.legacyProviderRegistrations.get(testProvider.constructor)
expect(providerRegistration.selectors).toEqual(['.source.js'])
expect(_.contains(autocompleteManager.providerManager.providersForScopeChain('.source.js'), testProvider)).toEqual(false)
expect(_.contains(autocompleteManager.providerManager.providersForScopeChain('.source.js'), providerRegistration.shim)).toEqual(true)

registration = mainModule.registerProviderForEditor(testProvider, editor)

expect(_.size(autocompleteManager.providerManager.providersForScopeChain('.source.js'))).toEqual(2)
expect(autocompleteManager.providerManager.legacyProviderRegistrations.has(testProvider.constructor)).toEqual(true)
providerRegistration = autocompleteManager.providerManager.legacyProviderRegistrations.get(testProvider.constructor)
expect(providerRegistration.selectors).toEqual(['.source.js'])
expect(_.contains(autocompleteManager.providerManager.providersForScopeChain('.source.js'), testProvider)).toEqual(false)
expect(_.contains(autocompleteManager.providerManager.providersForScopeChain('.source.js'), providerRegistration.shim)).toEqual(true)

registration = mainModule.registerProviderForEditor(testProvider, editor)

expect(_.size(autocompleteManager.providerManager.providersForScopeChain('.source.js'))).toEqual(2)
expect(autocompleteManager.providerManager.legacyProviderRegistrations.has(testProvider.constructor)).toEqual(true)
providerRegistration = autocompleteManager.providerManager.legacyProviderRegistrations.get(testProvider.constructor)
expect(providerRegistration.selectors).toEqual(['.source.js'])
expect(_.contains(autocompleteManager.providerManager.providersForScopeChain('.source.js'), testProvider)).toEqual(false)
expect(_.contains(autocompleteManager.providerManager.providersForScopeChain('.source.js'), providerRegistration.shim)).toEqual(true)

it 'unregisters the provider from all editors', ->
runs ->
expect(autocompleteManager.providerManager.store).toBeDefined()
testProvider = new TestProvider()
expect(autocompleteManager.providerManager.isLegacyProvider(testProvider)).toEqual(true)
registration = mainModule.registerProviderForEditor(testProvider, editor)

expect(_.size(autocompleteManager.providerManager.providersForScopeChain('.source.js'))).toEqual(2)
expect(autocompleteManager.providerManager.legacyProviderRegistrations.has(testProvider.constructor)).toEqual(true)
providerRegistration = autocompleteManager.providerManager.legacyProviderRegistrations.get(testProvider.constructor)
expect(providerRegistration.selectors).toEqual(['.source.js'])
expect(_.contains(autocompleteManager.providerManager.providersForScopeChain('.source.js'), testProvider)).toEqual(false)
expect(_.contains(autocompleteManager.providerManager.providersForScopeChain('.source.js'), providerRegistration.shim)).toEqual(true)

mainModule.unregisterProvider(testProvider)
expect(autocompleteManager.providerManager.store).toBeDefined()
expect(_.size(autocompleteManager.providerManager.providersForScopeChain('.source.js'))).toEqual(1)
expect(autocompleteManager.providerManager.legacyProviderRegistrations.has(testProvider.constructor)).toEqual(false)

it 'buildSuggestions is called for a registered provider', ->
runs ->
testProvider = new TestProvider()
mainModule.registerProviderForEditor(testProvider, editor)

spyOn(testProvider, 'buildSuggestions').andCallThrough()

# Trigger an autocompletion
editor.moveToBottom()
editor.moveToBeginningOfLine()
editor.insertText('f')
advanceClock(completionDelay)

expect(testProvider.buildSuggestions).toHaveBeenCalled()

describe 'Provider API v1.0.0', ->
[registration1, registration2, registration3] = []

Expand Down
Loading

0 comments on commit bfffb38

Please sign in to comment.