[SCM] Lisaac compiler branch, master, updated. lisaac-0.12-418-g1ecc5b9

Damien Bouvarel dams.bouvarel at wanadoo.fr
Thu Aug 20 13:06:21 UTC 2009


The following commit has been merged in the master branch:
commit 1ecc5b981dff7e8d59799c18654ecfbd8940b2c5
Author: Damien Bouvarel <dams.bouvarel at wanadoo.fr>
Date:   Thu Aug 20 15:05:06 2009 +0200

    add completion on variable names

diff --git a/editor/eclipse/src/org/lisaac/ldt/model/LisaacCompletionParser.java b/editor/eclipse/src/org/lisaac/ldt/model/LisaacCompletionParser.java
index d539280..49addf2 100644
--- a/editor/eclipse/src/org/lisaac/ldt/model/LisaacCompletionParser.java
+++ b/editor/eclipse/src/org/lisaac/ldt/model/LisaacCompletionParser.java
@@ -11,7 +11,11 @@ import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.lisaac.ldt.LisaacPlugin;
 import org.lisaac.ldt.editors.LisaacEditor;
+import org.lisaac.ldt.model.items.IArgument;
 import org.lisaac.ldt.model.items.ICode;
+import org.lisaac.ldt.model.items.ITMArgs;
+import org.lisaac.ldt.model.items.ITMList;
+import org.lisaac.ldt.model.items.ITMLocal;
 import org.lisaac.ldt.model.items.ITMRead;
 import org.lisaac.ldt.model.items.Prototype;
 import org.lisaac.ldt.model.items.Slot;
@@ -65,6 +69,7 @@ public class LisaacCompletionParser extends LisaacParser {
 			}
 			return;
 		}
+		setPosition(0);
 		
 		// slot match
 		ICode code = readExpr();
@@ -87,13 +92,20 @@ public class LisaacCompletionParser extends LisaacParser {
 					model.getPathManager().getPathMatch(prefix, proposals, baseOffset);
 				}
 			} else {
-				// partial slot name (first keyword)
+				// partial name, search for matches
 				if (code instanceof ITMRead) {
 					String prefix = ((ITMRead) code).getName();
+					
+					// partial local name
+					if (currentSlot != null) {
+						currentSlot.getArgumentMatchProposals(prefix, proposals, baseOffset, 0);
+						currentSlot.getLocalMatchProposals(prefix, proposals, baseOffset, 0);
+					}
+					// partial slot name (first keyword)
 					currentPrototype.lookupSlotMatch(prefix, proposals, baseOffset, 0);
 				}
 			}
-		}
+		} 
 	}
 
 	//++ EXPR_MESSAGE -> EXPR_BASE { '.' SEND_MSG }
diff --git a/editor/eclipse/src/org/lisaac/ldt/model/items/IArgument.java b/editor/eclipse/src/org/lisaac/ldt/model/items/IArgument.java
index 8a464f5..1b05e87 100644
--- a/editor/eclipse/src/org/lisaac/ldt/model/items/IArgument.java
+++ b/editor/eclipse/src/org/lisaac/ldt/model/items/IArgument.java
@@ -1,5 +1,8 @@
 package org.lisaac.ldt.model.items;
 
+import java.util.ArrayList;
+
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
 import org.lisaac.ldt.model.types.IType;
 
 public interface IArgument extends IVariable {
@@ -11,4 +14,7 @@ public interface IArgument extends IVariable {
 	boolean hasName(String word);
 	
 	void printIn(StringBuffer buffer);
+
+	void getMatchProposals(String n, ArrayList<ICompletionProposal> matchList,
+			int offset, int length);
 }
diff --git a/editor/eclipse/src/org/lisaac/ldt/model/items/ITMArgs.java b/editor/eclipse/src/org/lisaac/ldt/model/items/ITMArgs.java
index d053c6e..8097273 100644
--- a/editor/eclipse/src/org/lisaac/ldt/model/items/ITMArgs.java
+++ b/editor/eclipse/src/org/lisaac/ldt/model/items/ITMArgs.java
@@ -1,8 +1,14 @@
 package org.lisaac.ldt.model.items;
 
+import java.util.ArrayList;
+
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.swt.graphics.Image;
 import org.lisaac.ldt.model.Position;
 import org.lisaac.ldt.model.types.IType;
 import org.lisaac.ldt.model.types.TypeMulti;
+import org.lisaac.ldt.outline.OutlineImages;
 
 public class ITMArgs implements IArgument {
 
@@ -92,5 +98,23 @@ public class ITMArgs implements IArgument {
 	public Position getPosition() {
 		return position;
 	}
+
+	public void getMatchProposals(String n,
+			ArrayList<ICompletionProposal> matchList, int offset, int length) {
+		
+		for (int i=0; i<name.length; i++) {
+			if (name[i].startsWith(n)) {
+				String match = name[i];
+				if (Slot.checkUnicity(matchList, match)) {
+					Image image = OutlineImages.PRIVATE_NONSHARED;// TODO new image for args
+					
+					String partialMatch = match.substring(n.length());
+					matchList.add(new CompletionProposal(partialMatch, offset, length,
+							partialMatch.length(), image, match, null,
+							null));
+				}
+			}
+		}	
+	}
 }
 	
\ No newline at end of file
diff --git a/editor/eclipse/src/org/lisaac/ldt/model/items/ITMArgument.java b/editor/eclipse/src/org/lisaac/ldt/model/items/ITMArgument.java
index ae1abdc..fa2a0ea 100644
--- a/editor/eclipse/src/org/lisaac/ldt/model/items/ITMArgument.java
+++ b/editor/eclipse/src/org/lisaac/ldt/model/items/ITMArgument.java
@@ -1,8 +1,14 @@
 package org.lisaac.ldt.model.items;
 
+import java.util.ArrayList;
+
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.swt.graphics.Image;
 import org.lisaac.ldt.model.Position;
 import org.lisaac.ldt.model.types.IType;
 import org.lisaac.ldt.model.types.ITypeMono;
+import org.lisaac.ldt.outline.OutlineImages;
 
 public class ITMArgument implements IArgument {
 	
@@ -49,4 +55,25 @@ public class ITMArgument implements IArgument {
 	public Position getPosition() {
 		return position;
 	}
+
+	public String match(String n) {
+		if (name.startsWith(n)) {
+			return name;
+		}
+		return null;
+	}
+
+	public void getMatchProposals(String n,
+			ArrayList<ICompletionProposal> matchList, int offset, int length) {
+		
+		String match = match(n);
+		if (match != null && Slot.checkUnicity(matchList, match)) {
+			Image image = OutlineImages.PRIVATE_NONSHARED;// TODO new image for args
+			
+			String partialMatch = match.substring(n.length());
+			matchList.add(new CompletionProposal(partialMatch, offset, length,
+					partialMatch.length(), image, match, null,
+					null));
+		}
+	}
 }
diff --git a/editor/eclipse/src/org/lisaac/ldt/model/items/ITMList.java b/editor/eclipse/src/org/lisaac/ldt/model/items/ITMList.java
index be09219..aeddd3c 100644
--- a/editor/eclipse/src/org/lisaac/ldt/model/items/ITMList.java
+++ b/editor/eclipse/src/org/lisaac/ldt/model/items/ITMList.java
@@ -68,6 +68,24 @@ public class ITMList implements ICode {
 		return null;
 	}
 	
+	public String getLocalMatch(String n) {
+		if (localList != null) {
+			for (int i=0; i<localList.length; i++) {
+				if (localList[i].name.startsWith(n)) {
+					return localList[i].name;
+				}
+			}
+		}
+		if (staticList != null) {
+			for (int i=0; i<staticList.length; i++) {
+				if (staticList[i].name.startsWith(n)) {
+					return staticList[i].name;
+				}
+			}
+		}
+		return null;
+	}
+	
 	public IType getType(Slot slot, Prototype prototype) {
 		if (code != null && code.length > 0) {
 			return code[code.length-1].getType(slot, prototype); // FIXME list type
diff --git a/editor/eclipse/src/org/lisaac/ldt/model/items/Slot.java b/editor/eclipse/src/org/lisaac/ldt/model/items/Slot.java
index 90d2b16..192cf61 100644
--- a/editor/eclipse/src/org/lisaac/ldt/model/items/Slot.java
+++ b/editor/eclipse/src/org/lisaac/ldt/model/items/Slot.java
@@ -11,6 +11,7 @@ import org.eclipse.text.edits.TextEdit;
 import org.lisaac.ldt.model.LisaacParser;
 	import org.lisaac.ldt.model.Position;
 	import org.lisaac.ldt.model.types.IType;
+import org.lisaac.ldt.outline.OutlineImages;
 import org.lisaac.ldt.outline.OutlineSlot;
 
 	public class Slot {
@@ -315,8 +316,6 @@ import org.lisaac.ldt.outline.OutlineSlot;
 
 			Image image = new OutlineSlot(this).getImage();
 			String displayString = getSignature(true);
-
-			
 			
 			if (checkUnicity(proposals,displayString)) {
 				proposals.add(new CompletionProposal(displayString, offset, length,
@@ -339,8 +338,54 @@ import org.lisaac.ldt.outline.OutlineSlot;
 					null));
 			}
 		}
+		
+		public void getArgumentMatchProposals(String n,
+				ArrayList<ICompletionProposal> matchList, int offset, int length) {
+			
+			if (argumentList != null) {
+				for (int i = 0; i < argumentList.length; i++) {
+					argumentList[i].getMatchProposals(n,matchList, offset, length);
+				}
+			}
+		}
+		
+		public void getLocalMatchProposals(String n,
+				ArrayList<ICompletionProposal> matchList, int offset, int length) {
+			
+			ITMList list;
+			if (subLists != null) {
+				for (int i = 0; i < subLists.size(); i++) {
+					ICode c = subLists.get(i);
+
+					if (c instanceof ITMList) {
+						list = (ITMList) c;
+						if (list != null && list.isInside(offset)) {
+							// list variable
+							String match = list.getLocalMatch(n);
+							if (match != null && checkUnicity(matchList, match)) {
+								Image image = OutlineImages.PRIVATE_NONSHARED;// TODO '+' or '-' local..
+								
+								String partialMatch = match.substring(n.length());
+								matchList.add(new CompletionProposal(partialMatch, offset, length,
+										partialMatch.length(), image, match, null,
+										null));
+							}
+						}
+					} else if (c instanceof ITMBlock) {
+						list = ((ITMBlock) c).list;
+						IArgument arg = ((ITMBlock) c).argument;
+
+						if (list != null && arg != null
+								&& list.isInside(offset)) {
+							// block argument
+							arg.getMatchProposals(n, matchList, offset, length);
+						}
+					}
+				}
+			}
+		}
 
-		private boolean checkUnicity(ArrayList<ICompletionProposal> proposals, String str) {
+		public static boolean checkUnicity(ArrayList<ICompletionProposal> proposals, String str) {
 			for (int i=0; i<proposals.size(); i++) {
 				if (proposals.get(i).getDisplayString().compareTo(str) == 0) {
 					return false;

-- 
Lisaac compiler



More information about the Lisaac-commits mailing list