From 7cc3f7613e148360be7bdc8a6c6d7ff26dc5491c Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 17 Mar 2016 10:00:07 +0000 Subject: [PATCH 01/10] Move the `getCompletions` call for Snippets into the Snippets module. --- .../aceEditor/auto-complete/AutoCompleteManager.coffee | 6 ++---- .../directives/aceEditor/auto-complete/Snippets.coffee | 8 ++++++-- .../aceEditor/auto-complete/SuggestionManager.coffee | 3 +-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee index d2341f04f8..27f5b15a3a 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee @@ -3,7 +3,7 @@ define [ "ide/editor/directives/aceEditor/auto-complete/Snippets" "ace/ace" "ace/ext-language_tools" -], (SuggestionManager, Snippets) -> +], (SuggestionManager, SnippetManager) -> Range = ace.require("ace/range").Range getLastCommandFragment = (lineUpToCursor) -> @@ -38,9 +38,7 @@ define [ enableLiveAutocompletion: false }) - SnippetCompleter = - getCompletions: (editor, session, pos, prefix, callback) -> - callback null, Snippets + SnippetCompleter = new SnippetManager() references = @$scope.$root._references ReferencesCompleter = diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/Snippets.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/Snippets.coffee index 4bc3d16ef4..a637005711 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/Snippets.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/Snippets.coffee @@ -1,6 +1,6 @@ define () -> environments = [ - "abstract", + "abstract", "align", "align*", "equation", "equation*", "gather", "gather*", @@ -96,5 +96,9 @@ define () -> """ meta: "env" }] + class SnippetManager + getCompletions: (editor, session, pos, prefix, callback) -> + console.log ">> get snippet completions" + callback null, snippets - return snippets \ No newline at end of file + return SnippetManager diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee index 559a2c5981..e0c3710358 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee @@ -28,7 +28,7 @@ define [], () -> # Ignore single letter commands since auto complete is moot then. commandRegex: /\\([a-zA-Z][a-zA-Z]+)/ - + nextCommand: () -> i = @doc.search(@commandRegex) if i == -1 @@ -123,4 +123,3 @@ define [], () -> completionBeforeCursor: completionBeforeCursor completionAfterCursor: completionAfterCursor } - From 115734f82e69f274678ae0084deeb3b0aec729cf Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 17 Mar 2016 10:04:14 +0000 Subject: [PATCH 02/10] Rename Snippets -> SnippetManager --- .../aceEditor/auto-complete/AutoCompleteManager.coffee | 2 +- .../{Snippets.coffee => SnippetManager.coffee} | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) rename services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/{Snippets.coffee => SnippetManager.coffee} (93%) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee index 27f5b15a3a..32a60370c1 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee @@ -1,6 +1,6 @@ define [ "ide/editor/directives/aceEditor/auto-complete/SuggestionManager" - "ide/editor/directives/aceEditor/auto-complete/Snippets" + "ide/editor/directives/aceEditor/auto-complete/SnippetManager" "ace/ace" "ace/ext-language_tools" ], (SuggestionManager, SnippetManager) -> diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/Snippets.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee similarity index 93% rename from services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/Snippets.coffee rename to services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee index a637005711..5cf040f9d6 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/Snippets.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee @@ -9,7 +9,7 @@ define () -> "verbatim" ] - snippets = for env in environments + staticSnippets = for env in environments { caption: "\\begin{#{env}}..." snippet: """ @@ -20,7 +20,7 @@ define () -> meta: "env" } - snippets = snippets.concat [{ + staticSnippets = staticSnippets.concat [{ caption: "\\begin{array}..." snippet: """ \\begin{array}{${1:cc}} @@ -96,9 +96,10 @@ define () -> """ meta: "env" }] + class SnippetManager getCompletions: (editor, session, pos, prefix, callback) -> console.log ">> get snippet completions" - callback null, snippets + callback null, staticSnippets return SnippetManager From c25c2b676a4144733b8098d3d22cc2c1a7548a98 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 17 Mar 2016 11:14:05 +0000 Subject: [PATCH 03/10] Parse `\newenvironment{}` commands. --- .../auto-complete/SnippetManager.coffee | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee index 5cf040f9d6..d09c8d9013 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee @@ -97,9 +97,24 @@ define () -> meta: "env" }] + CUSTOM_ENVIRONMENT_REGEX = /^\\newenvironment{(\w+)}.*$/gm + + parseCustomEnvironmentNames = (text) -> + names = [] + iterations = 0 + while match = CUSTOM_ENVIRONMENT_REGEX.exec(text) + names.push match[1] + iterations += 1 + if iterations >= 1000 + return names + return names + class SnippetManager getCompletions: (editor, session, pos, prefix, callback) -> - console.log ">> get snippet completions" + # console.log ">> get snippet completions", editor, session, pos, prefix + docText = session.getValue() + customEnvironmentNames = parseCustomEnvironmentNames(docText) + # console.log customEnvironmentNames callback null, staticSnippets return SnippetManager From eebd25351db9e6057183b1f16fadd3d174a28282 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 17 Mar 2016 11:23:53 +0000 Subject: [PATCH 04/10] Add the custom environments to the list of snippets --- .../aceEditor/auto-complete/SnippetManager.coffee | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee index d09c8d9013..cc894ad39d 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee @@ -115,6 +115,19 @@ define () -> docText = session.getValue() customEnvironmentNames = parseCustomEnvironmentNames(docText) # console.log customEnvironmentNames - callback null, staticSnippets + snippets = staticSnippets.concat( + customEnvironmentNames.map (name) -> + { + caption: "\\begin{#{name}}..." + snippet: """ + \\begin{#{name}} + \t$1 + \\end{#{name}} + """ + meta: "env" + + } + ) + callback null, snippets return SnippetManager From d655e99439b227ecfede1a480651c2a6094d0364 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 17 Mar 2016 12:07:21 +0000 Subject: [PATCH 05/10] Parse existing `begin` commands too. --- .../auto-complete/SnippetManager.coffee | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee index cc894ad39d..438e83fd6b 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee @@ -109,14 +109,28 @@ define () -> return names return names + BEGIN_COMMAND_REGEX = /^\\begin{(\w+)}.*$/gm + + parseBeginCommandNames = (text) -> + names = [] + iterations = 0 + while match = BEGIN_COMMAND_REGEX.exec(text) + names.push match[1] + iterations += 1 + if iterations >= 1000 + return names + return names + class SnippetManager getCompletions: (editor, session, pos, prefix, callback) -> # console.log ">> get snippet completions", editor, session, pos, prefix docText = session.getValue() customEnvironmentNames = parseCustomEnvironmentNames(docText) + beginCommandNames = parseBeginCommandNames(docText) # console.log customEnvironmentNames + parsedNames = _.union(customEnvironmentNames, beginCommandNames) snippets = staticSnippets.concat( - customEnvironmentNames.map (name) -> + parsedNames.map (name) -> { caption: "\\begin{#{name}}..." snippet: """ @@ -125,7 +139,6 @@ define () -> \\end{#{name}} """ meta: "env" - } ) callback null, snippets From 95a6e1900e913418c6872e2155dc8b9ac22de7e7 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 17 Mar 2016 14:09:45 +0000 Subject: [PATCH 06/10] Add autocomplete entries for the `end{}` commands --- .../aceEditor/auto-complete/SnippetManager.coffee | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee index 438e83fd6b..d4d8e4ca86 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee @@ -140,6 +140,16 @@ define () -> """ meta: "env" } + ).concat( + # arguably these `end` commands shouldn't be here, as they're not snippets + # but this is where we have access to the `begin` environment names + # *shrug* + parsedNames.map (name) -> + { + caption: "\\end{#{name}}" + value: "\\end{#{name}}" + meta: "env" + } ) callback null, snippets From 229ced6f2f51276ad76bac341a9e9304aadcfcaf Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 17 Mar 2016 14:43:34 +0000 Subject: [PATCH 07/10] Remove Indentation. --- .../directives/aceEditor/auto-complete/SnippetManager.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee index d4d8e4ca86..dce8f96d0e 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee @@ -135,7 +135,7 @@ define () -> caption: "\\begin{#{name}}..." snippet: """ \\begin{#{name}} - \t$1 + $1 \\end{#{name}} """ meta: "env" From 53b46e42cde5d6cf302849cbeb5c5eac836d897d Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 17 Mar 2016 15:27:20 +0000 Subject: [PATCH 08/10] Refactor, take indentation into account. --- .../auto-complete/SnippetManager.coffee | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee index dce8f96d0e..3b3d4baf3b 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee @@ -97,46 +97,44 @@ define () -> meta: "env" }] - CUSTOM_ENVIRONMENT_REGEX = /^\\newenvironment{(\w+)}.*$/gm - parseCustomEnvironmentNames = (text) -> - names = [] + parseCustomEnvironments = (text) -> + re = /^\\newenvironment{(\w+)}.*$/gm + result = [] iterations = 0 - while match = CUSTOM_ENVIRONMENT_REGEX.exec(text) - names.push match[1] + while match = re.exec(text) + result.push {name: match[1], whitespace: null} iterations += 1 if iterations >= 1000 - return names - return names + return result + return result - BEGIN_COMMAND_REGEX = /^\\begin{(\w+)}.*$/gm - parseBeginCommandNames = (text) -> - names = [] + parseBeginCommands = (text) -> + re = /^\\begin{(\w+)}.*\n([\t ]*).*$/gm + result = [] iterations = 0 - while match = BEGIN_COMMAND_REGEX.exec(text) - names.push match[1] + while match = re.exec(text) + result.push {name: match[1], whitespace: match[2]} iterations += 1 if iterations >= 1000 - return names - return names + return result + return result class SnippetManager getCompletions: (editor, session, pos, prefix, callback) -> - # console.log ">> get snippet completions", editor, session, pos, prefix docText = session.getValue() - customEnvironmentNames = parseCustomEnvironmentNames(docText) - beginCommandNames = parseBeginCommandNames(docText) - # console.log customEnvironmentNames - parsedNames = _.union(customEnvironmentNames, beginCommandNames) + customEnvironments = parseCustomEnvironments(docText) + beginCommands = parseBeginCommands(docText) + parsedItems = _.union(customEnvironments, beginCommands) snippets = staticSnippets.concat( - parsedNames.map (name) -> + parsedItems.map (item) -> { - caption: "\\begin{#{name}}..." + caption: "\\begin{#{item.name}}..." snippet: """ - \\begin{#{name}} - $1 - \\end{#{name}} + \\begin{#{item.name}} + #{item.whitespace || ''}$1 + \\end{#{item.name}} """ meta: "env" } @@ -144,10 +142,10 @@ define () -> # arguably these `end` commands shouldn't be here, as they're not snippets # but this is where we have access to the `begin` environment names # *shrug* - parsedNames.map (name) -> + parsedItems.map (item) -> { - caption: "\\end{#{name}}" - value: "\\end{#{name}}" + caption: "\\end{#{item.name}}" + value: "\\end{#{item.name}}" meta: "env" } ) From 020fd2e88dfa9411807cd05ebb6751a5779f0305 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 17 Mar 2016 15:58:57 +0000 Subject: [PATCH 09/10] De-dupe autocomplete entries --- .../aceEditor/auto-complete/SnippetManager.coffee | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee index 3b3d4baf3b..6dc605e8ea 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee @@ -126,7 +126,12 @@ define () -> docText = session.getValue() customEnvironments = parseCustomEnvironments(docText) beginCommands = parseBeginCommands(docText) - parsedItems = _.union(customEnvironments, beginCommands) + parsedItemsMap = {} + for environment in customEnvironments + parsedItemsMap[environment.name] = environment + for command in beginCommands + parsedItemsMap[command.name] = command + parsedItems = _.values(parsedItemsMap) snippets = staticSnippets.concat( parsedItems.map (item) -> { From 11d77df898d9ecb13da4347dee069ddb9a1bfb46 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 17 Mar 2016 16:18:46 +0000 Subject: [PATCH 10/10] Fix weird tab behaviour --- .../directives/aceEditor/auto-complete/SnippetManager.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee index 6dc605e8ea..7b7593565d 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SnippetManager.coffee @@ -138,7 +138,7 @@ define () -> caption: "\\begin{#{item.name}}..." snippet: """ \\begin{#{item.name}} - #{item.whitespace || ''}$1 + #{item.whitespace || ''}$0 \\end{#{item.name}} """ meta: "env"