Hi,
we are developing jbehave plugin for a sublime 2, I have stuck on the autocompletion functionality, please help me resolve a couple issues.
-
In the ‘on_post_save’ state I am going through all the *Steps.java’ files and find lines start with "@Given|@When|@Then’;
after that "clean’ the jbehave java step to the valid result:
before: "@When(“I click button $butthon”)
after: "When I click button $button -
In the ‘on_query_completions’ state I give ‘prefix’ argument and return a list of proccessed steps, so return looks like:
“Given I am on the page”
“Given the workspaces”
“When I click button $button”
“Then the workspace is delete”
…
I have debugged the next code a lot, it returns the correct list of steps, but unfortunately the autocomplate shows me only default values.
dl.dropboxusercontent.com/u/383 … ugging.png
As you can see, the result list contains 438 steps for “Given” prefix, but in the *.story" file the autocompletion shows nothing
Please take a look to the attached plugin code, ignore the bad coding, because I am noobie in python.
[code]
import sublime, sublime_plugin
import os
import re
import fnmatch
STEPS_FOLDER = r’C:\th\thx\repo\juice-test\juice-test-behaviour\src\main\java\com\thunderhead\juice\integration\jbehave\steps’
class AutoCompleteJbehaveCollector(sublime_plugin.EventListener):
“”" Autocompletes steps “”"
files_list = None
all_steps_list = None
all_steps_parsed_list = None
def __init__(self):
self.files_list = ]
self.all_steps_list = ]
self.all_steps_parsed_list = ]
def get_java_steps_files(self, dir_name):
""" Get all the java steps files """
for root, dirnames, filenames in os.walk(dir_name):
for filename in fnmatch.filter(filenames, "*Steps.java"):
self.files_list.append(os.path.join(root, filename))
return self.files_list
def get_all_steps(self):
""" Returns a list of @When('I click on button $button') lines' """
if len(self.files_list) == 0:
self.get_java_steps_files(STEPS_FOLDER)
for file in self.files_list:
with open(file) as java_step_class:
for line in java_step_class:
if re.match(r'\s*@(When|Then|Given)', line):
self.all_steps_list.append(line.strip())
def remove_characters_from_java_step(self, java_step):
return java_step.replace('@', '').replace('\"', '').replace('(', ' ').replace(')', ' ')
def remove_characters_from_java_steps(self):
""" Returns a list of When I click on button $button lines' """
for step in self.all_steps_list:
self.all_steps_parsed_list.append(self.remove_characters_from_java_step(step))
def get_autocomplete_list(self, prefix):
autocomplete_list = ]
for step in self.all_steps_parsed_list:
if step.startswith(prefix):
autocomplete_list.append(step)
return autocomplete_list
def on_post_save(self, view):
self.get_all_steps()
self.remove_characters_from_java_steps()
def on_query_completions(self, view, prefix, location):
completions = ]
if '.story' in view.file_name():
completions = self.get_autocomplete_list(prefix)
print("prefix:" + prefix)
print("len:" + str(len(completions)))
return completions[/code]
Could you show me a sample, how to show a static list in the autocompletion, for example:
def on_query_completions(self, view, prefix, location):
if '.story' in view.file_name():
return ('qwerty', 'sublime')
Thank you for helping