From d871c187108d158198fbfbe6fe5bcf822a412592 Mon Sep 17 00:00:00 2001 From: Manindra Moharana Date: Fri, 26 Jul 2013 20:13:59 +0530 Subject: [PATCH] no completions in single line comments --- pdex/Todo, GSoC 2013.txt | 2 +- .../mode/experimental/ASTGenerator.java | 43 +++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/pdex/Todo, GSoC 2013.txt b/pdex/Todo, GSoC 2013.txt index 945daaff4..2b70df518 100644 --- a/pdex/Todo, GSoC 2013.txt +++ b/pdex/Todo, GSoC 2013.txt @@ -37,11 +37,11 @@ x Completion for array access, strings[0]. Finer details * printStuff(int,float,String) - completion endings have to be appropriate. Right now it's just printStuff(,,). Cursor positioning also needs to be taken care of(done). Argument list as tooltip if possible? -* Show declaring class for completions *! p5 enhanced stuff in java, how does it fit in with everything else, and edge cases. Possibly add support for them. Offset handling improvements should help here. * Diamond operator isn't supported for now. Bummer. * Icons for completions? Or overkill right now? +x Show declaring class for completions x! Ignore String case while finding completion candidates x Multiple 3rd party classes found in various packages. Not a chance no more. x Obj a1; a1.-> completion doesn't work before it is instantiated. Look into that. Began working again by itself. Yay! diff --git a/pdex/src/processing/mode/experimental/ASTGenerator.java b/pdex/src/processing/mode/experimental/ASTGenerator.java index a04265296..cd82b12d1 100644 --- a/pdex/src/processing/mode/experimental/ASTGenerator.java +++ b/pdex/src/processing/mode/experimental/ASTGenerator.java @@ -238,7 +238,7 @@ public class ASTGenerator { } // OutlineVisitor visitor = new OutlineVisitor(); // compilationUnit.accept(visitor); - calculateComments(); + getCodeComments(); codeTree = new DefaultMutableTreeNode( getNodeAsString((ASTNode) compilationUnit .types().get(0))); @@ -757,6 +757,10 @@ public class ASTGenerator { private String lastPredictedWord = " "; public void preparePredictions(final String word, final int line, final int lineStartNonWSOffset) { + if(caretWithinLineComment()){ + System.out.println("No predictions."); + return; + } SwingWorker worker = new SwingWorker() { @Override @@ -807,6 +811,21 @@ public class ASTGenerator { } } + + // Ensure that we're not inside a comment. TODO: Binary search + + /*for (Comment comm : getCodeComments()) { + int commLineNo = PdeToJavaLineNumber(compilationUnit + .getLineNumber(comm.getStartPosition())); + if(commLineNo == lineNumber){ + System.out.println("Found a comment line " + comm); + System.out.println("Comment LSO " + + javaCodeOffsetToLineStartOffset(compilationUnit + .getLineNumber(comm.getStartPosition()), + comm.getStartPosition())); + break; + } + }*/ // Now parse the expression into an ASTNode object ASTNode nearestNode = null; @@ -2580,15 +2599,33 @@ public class ASTGenerator { } - private void calculateComments(){ + private List getCodeComments(){ List commentList = compilationUnit.getCommentList(); - System.out.println("Total comments: " + commentList.size()); +// System.out.println("Total comments: " + commentList.size()); // int i = 0; // for (Comment comment : commentList) { // System.out.println(++i + ": "+comment + " Line:" // + compilationUnit.getLineNumber(comment.getStartPosition()) + ", " // + comment.getLength()); // } + return commentList; + } + + protected boolean caretWithinLineComment(){ + String pdeLine = editor.getLineText(editor.textArea().getCaretLine()).trim(); + int caretPos = editor.textArea().getCaretPosition() + - editor.textArea() + .getLineStartNonWhiteSpaceOffset(editor.textArea().getCaretLine()); + int x = pdeLine.indexOf("//"); + System.out.println(x + " , " + caretPos + ", Checking line for comment " + pdeLine); + //lineStartOffset = editor.textArea(). + + if (x >= 0 && caretPos > x) { + System.out.println("INSIDE a comment"); + return true; + } + System.out.println("not within comment"); + return false; } /**