From f5a14d23547ab1184f4fdbd24febd119cd6bec73 Mon Sep 17 00:00:00 2001 From: Lalit-som Date: Mon, 25 Sep 2017 03:18:16 +0530 Subject: [PATCH 01/11] fixed Global Attributes Doc URL on global events --- lib/provider.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/provider.coffee b/lib/provider.coffee index ff4ca9d..f477e8a 100644 --- a/lib/provider.coffee +++ b/lib/provider.coffee @@ -181,7 +181,10 @@ module.exports = "#{@getTagDocsURL(tag)}#attr-#{attribute}" getGlobalAttributeDocsURL: (attribute) -> - "https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/#{attribute}" + if attribute.startsWith('on') + "https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/#{attribute}" + else + "https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/#{attribute}" firstCharsEqual = (str1, str2) -> str1[0].toLowerCase() is str2[0].toLowerCase() From 6c5e3ee561e087681dd2ff564380f9f45ca9556a Mon Sep 17 00:00:00 2001 From: Lalit-som Date: Mon, 25 Sep 2017 03:37:46 +0530 Subject: [PATCH 02/11] removed trailing white space --- lib/provider.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/provider.coffee b/lib/provider.coffee index f477e8a..8252218 100644 --- a/lib/provider.coffee +++ b/lib/provider.coffee @@ -184,7 +184,7 @@ module.exports = if attribute.startsWith('on') "https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/#{attribute}" else - "https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/#{attribute}" - + "https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/#{attribute}" + firstCharsEqual = (str1, str2) -> str1[0].toLowerCase() is str2[0].toLowerCase() From c88e105525f34bf0cc55bfd790f48feeeb89b33a Mon Sep 17 00:00:00 2001 From: Lalit-som Date: Mon, 25 Sep 2017 06:37:08 +0530 Subject: [PATCH 03/11] removed a bug because of no description in on* event --- lib/provider.coffee | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/provider.coffee b/lib/provider.coffee index 8252218..24ef7f2 100644 --- a/lib/provider.coffee +++ b/lib/provider.coffee @@ -118,7 +118,7 @@ module.exports = displayText: attribute type: 'attribute' description: description ? "Global #{attribute} attribute" - descriptionMoreURL: if description then @getGlobalAttributeDocsURL(attribute) else null + descriptionMoreURL: @getGlobalAttributeDocsURL(attribute,description) getAttributeValueCompletions: ({prefix, editor, bufferPosition}) -> completions = [] @@ -180,11 +180,13 @@ module.exports = getLocalAttributeDocsURL: (attribute, tag) -> "#{@getTagDocsURL(tag)}#attr-#{attribute}" - getGlobalAttributeDocsURL: (attribute) -> - if attribute.startsWith('on') + getGlobalAttributeDocsURL: (attribute,description) -> + if description + "https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/#{attribute}" + else if attribute.startsWith('on') "https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/#{attribute}" else - "https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/#{attribute}" - + null + firstCharsEqual = (str1, str2) -> str1[0].toLowerCase() is str2[0].toLowerCase() From 233a85d142be5666c2e84dd3b1f00f3e2755c8e3 Mon Sep 17 00:00:00 2001 From: Lalit-som Date: Mon, 25 Sep 2017 06:45:45 +0530 Subject: [PATCH 04/11] added space after comma --- lib/provider.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/provider.coffee b/lib/provider.coffee index 24ef7f2..0e3eecf 100644 --- a/lib/provider.coffee +++ b/lib/provider.coffee @@ -118,7 +118,7 @@ module.exports = displayText: attribute type: 'attribute' description: description ? "Global #{attribute} attribute" - descriptionMoreURL: @getGlobalAttributeDocsURL(attribute,description) + descriptionMoreURL: @getGlobalAttributeDocsURL(attribute, description) getAttributeValueCompletions: ({prefix, editor, bufferPosition}) -> completions = [] @@ -180,7 +180,7 @@ module.exports = getLocalAttributeDocsURL: (attribute, tag) -> "#{@getTagDocsURL(tag)}#attr-#{attribute}" - getGlobalAttributeDocsURL: (attribute,description) -> + getGlobalAttributeDocsURL: (attribute, description) -> if description "https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/#{attribute}" else if attribute.startsWith('on') From 37cc7fc7cfbb9bfe952362360b1c24e522d1cf65 Mon Sep 17 00:00:00 2001 From: Lalit-som Date: Mon, 25 Sep 2017 07:06:42 +0530 Subject: [PATCH 05/11] added test assertions for onabort and aria-busy in provider-spec.coffee --- spec/provider-spec.coffee | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/spec/provider-spec.coffee b/spec/provider-spec.coffee index 1637c6b..4f8cdaa 100644 --- a/spec/provider-spec.coffee +++ b/spec/provider-spec.coffee @@ -294,7 +294,17 @@ describe "HTML autocompletions", -> expect(-> completions = getCompletions()).not.toThrow() expect(completions[0].displayText).toBe 'onafterprint' - it "does not provide a descriptionMoreURL if the attribute does not have a unique description", -> + it "does not provide a descriptionMoreURL if the attribute does not have a unique description and does not start with on*", -> + editor.setText(' editor.setText(' expect(completions[0].displayText).toBe 'onabort' expect(completions[0].description).toBe 'Global onabort attribute' - expect(completions[0].descriptionMoreURL).toBeNull() + expect(completions[0].descriptionMoreURL.endsWith('/Web/API/GlobalEventHandlers/onabort')).toBe true it "autocompletes attribute values without a prefix", -> editor.setText(' Date: Mon, 25 Sep 2017 07:22:22 +0530 Subject: [PATCH 06/11] changed aria to ar in assertions --- spec/provider-spec.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/provider-spec.coffee b/spec/provider-spec.coffee index 4f8cdaa..f784b23 100644 --- a/spec/provider-spec.coffee +++ b/spec/provider-spec.coffee @@ -295,7 +295,7 @@ describe "HTML autocompletions", -> expect(completions[0].displayText).toBe 'onafterprint' it "does not provide a descriptionMoreURL if the attribute does not have a unique description and does not start with on*", -> - editor.setText(' Date: Mon, 25 Sep 2017 07:40:24 +0530 Subject: [PATCH 07/11] added assertion aria- --- spec/provider-spec.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/provider-spec.coffee b/spec/provider-spec.coffee index f784b23..74728cf 100644 --- a/spec/provider-spec.coffee +++ b/spec/provider-spec.coffee @@ -295,8 +295,8 @@ describe "HTML autocompletions", -> expect(completions[0].displayText).toBe 'onafterprint' it "does not provide a descriptionMoreURL if the attribute does not have a unique description and does not start with on*", -> - editor.setText(' Date: Mon, 25 Sep 2017 07:48:58 +0530 Subject: [PATCH 08/11] removed aria- assertion --- spec/provider-spec.coffee | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/spec/provider-spec.coffee b/spec/provider-spec.coffee index 74728cf..d3b8ce7 100644 --- a/spec/provider-spec.coffee +++ b/spec/provider-spec.coffee @@ -294,16 +294,6 @@ describe "HTML autocompletions", -> expect(-> completions = getCompletions()).not.toThrow() expect(completions[0].displayText).toBe 'onafterprint' - it "does not provide a descriptionMoreURL if the attribute does not have a unique description and does not start with on*", -> - editor.setText(' editor.setText(' Date: Mon, 25 Sep 2017 15:09:50 +0530 Subject: [PATCH 09/11] added docs for aria-attribute and role --- lib/provider.coffee | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/provider.coffee b/lib/provider.coffee index 0e3eecf..25c0fc4 100644 --- a/lib/provider.coffee +++ b/lib/provider.coffee @@ -181,12 +181,15 @@ module.exports = "#{@getTagDocsURL(tag)}#attr-#{attribute}" getGlobalAttributeDocsURL: (attribute, description) -> - if description - "https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/#{attribute}" - else if attribute.startsWith('on') + if attribute.startsWith('on') "https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/#{attribute}" + else if attribute.startsWith('aria-') + # As of September 2017, MDN does not have pages for ARIA attributes + "https://www.w3.org/TR/wai-aria-1.1/##{attribute}" + else if attribute.startsWith('role') + "https://www.w3.org/TR/wai-aria-1.1/#usage_intro" else - null + "https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/#{attribute}" firstCharsEqual = (str1, str2) -> str1[0].toLowerCase() is str2[0].toLowerCase() From 7056e1958ba74079ea43a5cb0a7cc41fc9a19112 Mon Sep 17 00:00:00 2001 From: Lalit-som Date: Tue, 26 Sep 2017 00:47:37 +0530 Subject: [PATCH 10/11] added tests for role attribute and removed description parameter --- lib/provider.coffee | 6 +++--- spec/provider-spec.coffee | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/provider.coffee b/lib/provider.coffee index 25c0fc4..34a9cba 100644 --- a/lib/provider.coffee +++ b/lib/provider.coffee @@ -118,7 +118,7 @@ module.exports = displayText: attribute type: 'attribute' description: description ? "Global #{attribute} attribute" - descriptionMoreURL: @getGlobalAttributeDocsURL(attribute, description) + descriptionMoreURL: @getGlobalAttributeDocsURL(attribute) getAttributeValueCompletions: ({prefix, editor, bufferPosition}) -> completions = [] @@ -180,13 +180,13 @@ module.exports = getLocalAttributeDocsURL: (attribute, tag) -> "#{@getTagDocsURL(tag)}#attr-#{attribute}" - getGlobalAttributeDocsURL: (attribute, description) -> + getGlobalAttributeDocsURL: (attribute) -> if attribute.startsWith('on') "https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/#{attribute}" else if attribute.startsWith('aria-') # As of September 2017, MDN does not have pages for ARIA attributes "https://www.w3.org/TR/wai-aria-1.1/##{attribute}" - else if attribute.startsWith('role') + else if attribute is 'role' "https://www.w3.org/TR/wai-aria-1.1/#usage_intro" else "https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/#{attribute}" diff --git a/spec/provider-spec.coffee b/spec/provider-spec.coffee index d3b8ce7..2fcaf61 100644 --- a/spec/provider-spec.coffee +++ b/spec/provider-spec.coffee @@ -294,7 +294,7 @@ describe "HTML autocompletions", -> expect(-> completions = getCompletions()).not.toThrow() expect(completions[0].displayText).toBe 'onafterprint' - it "provide a descriptionMoreURL if the attribute does not have a unique description but starts with on*", -> + it "provides a descriptionMoreURL if the attribute does not have a unique description but starts with on*", -> editor.setText(' expect(completions[0].description).toBe 'Global onabort attribute' expect(completions[0].descriptionMoreURL.endsWith('/Web/API/GlobalEventHandlers/onabort')).toBe true + it "provides a descriptionMoreURL if the attribute is role", -> + editor.setText('
editor.setText(' Date: Thu, 28 Sep 2017 01:10:22 +0530 Subject: [PATCH 11/11] filter suggestions list by prefix --- spec/provider-spec.coffee | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/spec/provider-spec.coffee b/spec/provider-spec.coffee index 2fcaf61..db5a0f0 100644 --- a/spec/provider-spec.coffee +++ b/spec/provider-spec.coffee @@ -12,7 +12,21 @@ describe "HTML autocompletions", -> bufferPosition: bufferPosition scopeDescriptor: cursor.getScopeDescriptor() prefix: prefix - provider.getSuggestions(request) + + filterByPrefix(provider.getSuggestions(request), prefix) + + + filterByPrefix = (rawSuggestionsList, prefix) -> + if prefix.length < 3 + rawSuggestionsList + else + filteredSuggestionsList = [] + for suggestion in rawSuggestionsList + attribute = suggestion.text or suggestion.displayText + if attribute.indexOf(prefix) isnt -1 + filteredSuggestionsList.push suggestion + + filteredSuggestionsList beforeEach -> waitsForPromise -> atom.packages.activatePackage('autocomplete-html') @@ -304,6 +318,16 @@ describe "HTML autocompletions", -> expect(completions[0].description).toBe 'Global onabort attribute' expect(completions[0].descriptionMoreURL.endsWith('/Web/API/GlobalEventHandlers/onabort')).toBe true + it "provides a descriptionMoreURL if the attribute is role", -> + editor.setText('
editor.setText('