brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [02/10] brooklyn-ui git commit: completion proposal improvements
Date Thu, 03 Mar 2016 12:29:47 GMT
completion proposal improvements

gives root proposals at end of document or newline in the middle,
and filters out root proposals that have already been applied


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/commit/22785162
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/tree/22785162
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/diff/22785162

Branch: refs/heads/master
Commit: 227851625ba504f88146b6aaf3dd418a13e7a78f
Parents: 4896aa1
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Tue Mar 1 16:04:24 2016 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Tue Mar 1 16:04:24 2016 +0000

----------------------------------------------------------------------
 .../brooklyn-yaml-completion-proposals.js       | 34 ++++++++++++++------
 1 file changed, 25 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/22785162/src/main/webapp/assets/js/util/code-complete/brooklyn-yaml-completion-proposals.js
----------------------------------------------------------------------
diff --git a/src/main/webapp/assets/js/util/code-complete/brooklyn-yaml-completion-proposals.js
b/src/main/webapp/assets/js/util/code-complete/brooklyn-yaml-completion-proposals.js
index e183411..60b2fda 100644
--- a/src/main/webapp/assets/js/util/code-complete/brooklyn-yaml-completion-proposals.js
+++ b/src/main/webapp/assets/js/util/code-complete/brooklyn-yaml-completion-proposals.js
@@ -175,12 +175,16 @@ define([
     }
     
     var AppBlueprintProposer = {
-        getRootProposals: function() {
-          return [
-              { displayText: "name:", text: "name: " },
-              { displayText: "location:", text: "location:\n  " },
-              { displayText: "services:", text: "services:\n- type: " }
-            ];
+        getRootProposals: function(node) {
+          var result = [];
+          if (!node || !node.name)
+            result = result.concat( { displayText: "name:", text: "name: " } );
+          if (!node || !node.services)
+            result = result.concat( { displayText: "services:", text: "services:\n- type:
" } );
+          if (!node || !(node.location || node.locations))
+            result = result.concat( { displayText: "location:", text: "location:\n  " } );
+          
+          return result;
         },
         
         getServiceTypes: function(n) {
@@ -228,6 +232,11 @@ define([
             var result = [];
 //            console.log("context at position "+position, nn);
             while (n.role === 'primitive') n = n.parent;
+            var fromHereToEndOfOuterBlock;
+            if (nn[1].key) {
+                fromHereToEndOfOuterBlock = position <= nn[1].end ? nn[1].doc.substring(position,
nn[1].end) : nn[1].doc.substring(nn[1].end, position);
+                fromHereToEndOfOuterBlock = fromHereToEndOfOuterBlock.trim();
+            }
             if (nn[1].key && nn[1].key.result === 'services') {
                 // in services block
                 var canAddService = true;
@@ -262,8 +271,8 @@ define([
                 if (n.depth > 2) {
                     // deep in a service, no special assistance currently offered
                 }
-                
-                if (canAddService && (position == nn[1].end || position == nn[1].end+1))
{
+
+                if (canAddService && fromHereToEndOfOuterBlock.length==0) {
                     result.push( { displayText: 'Add a service', className: 'summary', text:
'\n- type: ' } );
                 }
             }
@@ -273,7 +282,14 @@ define([
                             return t+'\n'; }));
                 }
             }
+            
             // TODO other blocks
+            
+            // finally add root proposals
+            if (cmPosition.ch==0 && fromHereToEndOfOuterBlock && fromHereToEndOfOuterBlock.length==0)
{
+                result = result.concat(this.getRootProposals(nn[0] ? nn[0].result : null));
+            }
+            
             return result;
         }
     }
@@ -316,7 +332,7 @@ define([
                     var nn = findContexts(n, position);
                     
                     if (n.role === 'root') {
-                      result = proposer.getRootProposals();
+                      result = proposer.getRootProposals(n.result);
                     } else {
                       result = proposer.getProposals(nn, position, cmPosition);
                     }


Mime
View raw message