diff --git a/lib/main.coffee b/lib/main.coffee index 0d2f8455..7b96def1 100644 --- a/lib/main.coffee +++ b/lib/main.coffee @@ -1,7 +1,4 @@ {Disposable} = require('atom') -Provider = require('./provider') -Suggestion = require('./suggestion') -{deprecate} = require('grim') module.exports = config: @@ -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) @@ -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 diff --git a/lib/provider-manager.coffee b/lib/provider-manager.coffee index 24b80315..bfdcbf7c 100644 --- a/lib/provider-manager.coffee +++ b/lib/provider-manager.coffee @@ -4,8 +4,6 @@ _ = 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 @@ -13,13 +11,11 @@ class ProviderManager 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))) @@ -37,7 +33,6 @@ class ProviderManager @store = null @providers?.clear() @providers = null - @legacyProviderRegistrations = null providersForScopeChain: (scopeChain) => return [] unless scopeChain? @@ -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) @@ -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) diff --git a/lib/provider.coffee b/lib/provider.coffee deleted file mode 100644 index 31bceea6..00000000 --- a/lib/provider.coffee +++ /dev/null @@ -1,61 +0,0 @@ -{deprecate} = require('grim') - -# Public: A provider provides an interface to the autocomplete package. Third-party -# packages can register providers which will then be used to generate the -# suggestions list. -module.exports = -class Provider - wordRegex: /\b\w*[a-zA-Z_-]+\w*\b/g - - constructor: -> - deprecate('`Provider` is no longer supported. Please switch to the new API: https://github.com/atom-community/autocomplete-plus/wiki/Provider-API') - @initialize.apply(this, arguments) - - # Public: An initializer for subclasses - initialize: -> - return - - # Public: Defines whether the words returned at {::buildSuggestions} should be added to - # the default suggestions or should be displayed exclusively - exclusive: false - - buildSuggestionsShim: (options) => - return unless options?.editor? - @editor = options.editor - @buildSuggestions.apply(this, arguments) - - # Public: Gets called when the document has been changed. Returns an array with - # suggestions. If `exclusive` is set to true and this method returns suggestions, - # the suggestions will be the only ones that are displayed. - # - # Returns An {Array} of suggestions. - buildSuggestions: -> - throw new Error('Subclass must implement a buildSuggestions(options) method') - - # Public: Gets called when a suggestion has been confirmed by the user. Return true - # to replace the word with the suggestion. Return false if you want to handle - # the behavior yourself. - # - # suggestion - The {Suggestion} to confirm - # - # Returns {Boolean} indicating whether the suggestion should be automatically replaced. - confirm: (suggestion) -> - return true - - # Public: Finds and returns the content before the current cursor position - # - # selection - The {Selection} for the current cursor position - # - # Returns {String} with the prefix of the {Selection} - prefixOfSelection: (selection) -> - selectionRange = selection.getBufferRange() - lineRange = [[selectionRange.start.row, 0], [selectionRange.end.row, @editor.lineTextForBufferRow(selectionRange.end.row).length]] - prefix = '' - @editor.getBuffer().scanInRange @wordRegex, lineRange, ({match, range, stop}) -> - stop() if range.start.isGreaterThan(selectionRange.end) - - if range.intersectsWith(selectionRange) - prefixOffset = selectionRange.start.column - range.start.column - prefix = match[0][0...prefixOffset] if range.start.isLessThan(selectionRange.start) - - return prefix diff --git a/lib/suggestion.coffee b/lib/suggestion.coffee deleted file mode 100644 index 7b18d0f1..00000000 --- a/lib/suggestion.coffee +++ /dev/null @@ -1,11 +0,0 @@ -{deprecate} = require('grim') -module.exports = -class Suggestion - constructor: (@provider, options) -> - deprecate('`Suggestion` is no longer supported. Please switch to the new API: https://github.com/atom-community/autocomplete-plus/wiki/Provider-API') - @word = options.word if options.word? - @prefix = options.prefix if options.prefix? - @label = options.label if options.label? - @data = options.data if options.data? - @renderLabelAsHtml = options.renderLabelAsHtml if options.renderLabelAsHtml? - @className = options.className if options.className? diff --git a/spec/autocomplete-blacklist-spec.coffee b/spec/autocomplete-blacklist-spec.coffee index dce30ef2..56a9c996 100644 --- a/spec/autocomplete-blacklist-spec.coffee +++ b/spec/autocomplete-blacklist-spec.coffee @@ -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] = [] diff --git a/spec/fuzzy-provider-spec.coffee b/spec/fuzzy-provider-spec.coffee index f8075473..52862a84 100644 --- a/spec/fuzzy-provider-spec.coffee +++ b/spec/fuzzy-provider-spec.coffee @@ -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] = [] diff --git a/spec/html-label-spec.coffee b/spec/html-label-spec.coffee index dd3ddb8c..be977379 100644 --- a/spec/html-label-spec.coffee +++ b/spec/html-label-spec.coffee @@ -1,5 +1,4 @@ {waitForAutocomplete} = require('./spec-helper') -TestProvider = require('./lib/test-provider') describe 'HTML labels', -> [completionDelay, editorView, editor, mainModule, autocompleteManager, registration] = [] diff --git a/spec/issues/57-spec.coffee b/spec/issues/57-spec.coffee index 97f1bace..de35bf2a 100644 --- a/spec/issues/57-spec.coffee +++ b/spec/issues/57-spec.coffee @@ -1,5 +1,4 @@ {waitForAutocomplete, triggerAutocompletion, buildIMECompositionEvent, buildTextInputEvent} = require('../spec-helper') -TestProvider = require('../lib/test-provider') describe 'Autocomplete', -> [mainModule, autocompleteManager, editorView, editor, completionDelay, mainModule] = [] diff --git a/spec/lib/test-provider.coffee b/spec/lib/test-provider.coffee deleted file mode 100644 index 35c10412..00000000 --- a/spec/lib/test-provider.coffee +++ /dev/null @@ -1,15 +0,0 @@ -{Provider, Suggestion} = require('../../lib/main') - -module.exports = -class TestProvider extends Provider - buildSuggestions: -> - [new Suggestion(this, - word: 'ohai', - prefix: 'ohai', - label: 'ohai', - renderLabelAsHtml: true, - className: 'ohai' - )] - - dispose: -> - foo = 'bar' diff --git a/spec/provider-api-spec.coffee b/spec/provider-api-spec.coffee index caa24cc1..60172c27 100644 --- a/spec/provider-api-spec.coffee +++ b/spec/provider-api-spec.coffee @@ -1,5 +1,4 @@ {waitForAutocomplete} = require('./spec-helper') -TestProvider = require('./lib/test-provider') _ = require('underscore-plus') describe 'Provider API', -> @@ -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] = [] diff --git a/spec/provider-manager-spec.coffee b/spec/provider-manager-spec.coffee index f8ecc4f9..17d005a1 100644 --- a/spec/provider-manager-spec.coffee +++ b/spec/provider-manager-spec.coffee @@ -1,9 +1,8 @@ ProviderManager = require('../lib/provider-manager') -TestProvider = require('./lib/test-provider') _ = require('underscore-plus') describe 'Provider Manager', -> - [providerManager, testProvider, legacyTestProvider, registration] = [] + [providerManager, testProvider, registration] = [] beforeEach -> runs -> @@ -19,14 +18,10 @@ describe 'Provider Manager', -> dispose: -> return - legacyTestProvider = new TestProvider() - afterEach -> runs -> registration?.dispose() if registration?.dispose? registration = null - legacyTestProvider?.dispose() if legacyTestProvider?.dispose? - legacyTestProvider = null testProvider?.dispose() if testProvider?.dispose? testProvider = null providerManager?.dispose() @@ -87,10 +82,6 @@ describe 'Provider Manager', -> expect(providerManager.providers.has(testProvider)).toEqual(false) expect(_.contains(providerManager.subscriptions?.disposables, testProvider)).toEqual(false) - it 'can identify a legacy provider', -> - expect(providerManager.isLegacyProvider(testProvider)).toEqual(false) - expect(providerManager.isLegacyProvider(legacyTestProvider)).toEqual(true) - it 'can identify a provider with a missing requestHandler', -> bogusProvider = badRequestHandler: (options) -> @@ -202,20 +193,6 @@ describe 'Provider Manager', -> expect(_.contains(providerManager.providersForScopeChain('.source.js'), bogusProvider)).toEqual(false) expect(providerManager.providers.has(bogusProvider)).toEqual(false) - it 'shims a legacy provider during registration', -> - expect(_.size(providerManager.providersForScopeChain('.source.js'))).toEqual(1) - expect(_.contains(providerManager.providersForScopeChain('.source.js'), providerManager.fuzzyProvider)).toEqual(true) - expect(_.contains(providerManager.providersForScopeChain('.source.js'), legacyTestProvider)).toEqual(false) - expect(providerManager.providers.has(legacyTestProvider)).toEqual(false) - - expect(providerManager.isLegacyProvider(legacyTestProvider)).toEqual(true) - registration = providerManager.registerLegacyProvider(legacyTestProvider, '.source.js') - expect(_.size(providerManager.providersForScopeChain('.source.js'))).toEqual(2) - expect(providerManager.legacyProviderRegistrations.has(legacyTestProvider.constructor)).toEqual(true) - legacyProviderRegistration = providerManager.legacyProviderRegistrations.get(legacyTestProvider.constructor) - expect(_.contains(providerManager.providersForScopeChain('.source.js'), legacyTestProvider)).toEqual(false) - expect(_.contains(providerManager.providersForScopeChain('.source.js'), legacyProviderRegistration.shim)).toEqual(true) - it 'registers a provider with a blacklist', -> testProvider = requestHandler: (options) -> diff --git a/spec/symbol-provider-spec.coffee b/spec/symbol-provider-spec.coffee index d7ee63cc..f48a9fc4 100644 --- a/spec/symbol-provider-spec.coffee +++ b/spec/symbol-provider-spec.coffee @@ -1,7 +1,6 @@ {Point} = require 'atom' {triggerAutocompletion, buildIMECompositionEvent, buildTextInputEvent} = require('./spec-helper') _ = require('underscore-plus') -TestProvider = require('./lib/test-provider') indexOfWord = (suggestionList, word) -> for suggestion, i in suggestionList