Commits

Anonymous committed 1bb6517

Proposing each proposal at most once

  • Participants
  • Parent commits c0bee46

Comments (0)

Files changed (3)

File docs/workingon.txt

 *** Auto-complete imports names @ 3 ***
 
-- Test only reporting only completions with the given starting
-- Showing completions in GraphicalEditor
-- Test not proposing local assigns as global proposals
-- Propose global classes and functions
+
+- Proposing a name at most once? Use dicts instead of lists
 
 * Extract listbox; duplicates in editor and core
-? Proposing a name at most once? Use dicts instead of lists
 * Complete as you type (updating proposal list while typing)
 * Test not proposing the variables in current line
 * What if current line has errors
 * Applying the completion
 ? The connection between ASTs and Type Hierarchies
-? Should Projects have ContentAssist objects?
 
 * Better font selection on windows
 ? Think about a library for functional testing

File rope/codeassist.py

     
     def __init__(self, starting):
         self.starting = starting
-        self.result = []
+        self.result = {}
 
     def visitAssName(self, node):
         if node.name.startswith(self.starting):
-            self.result.append(CompletionProposal(node.name, 'global_variable'))
+            self.result[node.name] = CompletionProposal(node.name, 'global_variable')
 
     def visitFunction(self, node):
         if node.name.startswith(self.starting):
-            self.result.append(CompletionProposal(node.name, 'function'))
+            self.result[node.name] = CompletionProposal(node.name, 'function')
     
     def visitClass(self, node):
         if node.name.startswith(self.starting):
-            self.result.append(CompletionProposal(node.name, 'class'))
+            self.result[node.name] = CompletionProposal(node.name, 'class')
 
 
 class ICodeAssist(object):
                                        source_code[current_offset] == '_'):
             starting = source_code[current_offset] + starting
             current_offset -= 1;
-        result = []
+        result = {}
         code_ast = compiler.parse(source_code)
         visitor = _GlobalVisitor(starting)
         compiler.walk(code_ast, visitor)
-        result.extend(visitor.result)
-        return result
+        result.update(visitor.result)
+        return result.values()

File ropetest/codeassisttest.py

         result = self.assist.complete_code(code, len(code))
         self.assert_proposal_in_result('Sample', 'class', result)
 
+    def test_proposing_each_name_at_most_once(self):
+        code = 'variable = 10\nvariable = 20\nt = vari'
+        result = self.assist.complete_code(code, len(code))
+        count = len([x for x in result if x.completion == 'variable' and x.kind == 'global_variable'])
+        self.assertEquals(1, count)
+
 
 if __name__ == '__main__':
     unittest.main()