Sublime Forum

Custom plug-in, the console reports an error when triggered run() missing 2 required positional arguments: 'start_sign' and 'end_sign'

#1

TypeError: run() missing 2 required positional arguments: ‘start_sign’ and ‘end_sign’

The plug-in is locally developed and copied to the User directory

0 Likes

#2

Current solution: open the plug-in and use the shortcut key Ctrl + s to trigger a resave

0 Likes

#3

This is an indication that the command that you’re trying to execute requires two arguments, but you haven’t provided them.

Your key binding, menu entry etc needs to provide all command arguments at the point where you execute the command, or the command arguments need to have default values.

If this solves your problem, then the most likely culprit is that you’re doing something at plugin load time that’s not allowed. Only a small portion of the API is available when plugins load, and it’s not until their plugin_loaded() entry point is called that you can use the remainder of the API.

Generally this manifests as a plugin that fails when you start Sublime (when the API is not available) but works when you trigger a reload after Sublime has started, at which point the plugin API is already ready.

It’s hard to say without seeing your code what you might be doing wrong, however.

0 Likes

#4

Plug-in code
#######################
import json
import copy
import urllib
import sublime
import sublime_plugin

class DimensionCommand(sublime_plugin.TextCommand):
def run(self, edit):
“”"
插件驱动函数,入口
“”"
# choose_bool = sublime.ok_cancel_dialog(“开始选择维度”,“开始”)
# if choose_bool is True:
now_windows = sublime.active_window()
self.now_windows = now_windows
dims_data = self.get_dimension_data()
self.initialize_count = 0
self.labels = dims_data
self.user_choose_dimension = []
self.select(self.labels)

def select(self, choose_list):
    self.now_windows.show_quick_panel(self.labels, self.on_select)
    if self.initialize_count < 1:
        self.now_windows.run_command("append", {"characters": "请输入所需维度字段进行筛选!"})
        self.now_windows.run_command("move_to", {"to": "eol"})

    # self.now_windows.show_quick_panel(self.labels, on_select=lambda id: self.on_select(id, self.labels))


def get_dimension_data(self):
    """
    接口获取指标数据供用户筛选
    """
    dimension_params = {"requests_type":"get_dims", "site":"mart_ind"}
    params = json.dumps(dimension_params)
    params = bytes(params, 'utf8')
    requests = urllib.request.Request(url='http://{local_ip}:80/ajsql_service/module/get_config'.format(local_ip=self.get_local_ip()), data=params, method='POST')
    response = urllib.request.urlopen(requests)
    response = response.read().decode('utf-8')
    response = json.loads(response)
    if response.get("status_code") == 200:
        dimension_data = response.get("data")
    else:
        sublime.error_message("读取维度失败,请检查网络是否连通!")
    # dimension_array = [[key.split(":")[0], key.split(":")[1]] for key in dimension_data]
    return dimension_data


def on_select(self, index):
    """
    构造筛选框,提供维度指标筛选
    """
    self.initialize_count += 1
    if index != -1 and len(self.labels) > 0:
        save_bool = sublime.ok_cancel_dialog("继续选择", "继续")
        self.user_choose_dimension.append(self.labels[index])
        print("选我选我")
        if save_bool is True:
            self.labels.pop(index)
        self.select(self.labels)
    else:
        print("越界或者选完啦!")
        print(self.user_choose_dimension)
        if self.user_choose_dimension:
            transform_data = [key.replace(" -> ",".") for key in self.user_choose_dimension]
            self.view.run_command("ajsql_di_insert", {"text": "dimensions = " + str(transform_data)})

def get_local_ip(self):
    import os 
    print(os.getcwd())
    with open("ajsql_sublime.config", "r", encoding="utf-8") as f:
        local_ip = f.read()
    ip = json.loads(local_ip)
    return ip.get("LOCAL_IP")

class AjsqlDiInsertCommand(sublime_plugin.TextCommand):
“”"
当前Windows 清屏
当前Windwos 写入脚本
“”"
def run(self, edit, text):
region = sublime.Region(0, 999999)
windows_str = self.view.substr(region)
if “metrics” not in windows_str.lower():
print(“metrics 木滴了”)
self.view.replace(edit, region, “”)
self.view.insert(edit, 0, text.replace("’",’"’))
else:
# 获取文档宽高
vector = self.view.layout_extent()
# 获取文本位置
point = self.view.layout_to_text(vector)
# 执行写入操作
self.view.insert(edit, point, “\n” + text.replace("’",’"’))

###########################
Default (Windows).sublime-keymap file
{ “keys”: [“ctrl+alt+d”], “command”: “dimension”},

0 Likes

#5

Plug-in function: Get request data, display a drop-down box for users to choose, and write the selection result to the screen.

0 Likes

#6

Your code isn’t readable because it’s not marked up as preformated code; can you edit your post to add:

```python

before the first line and:

```

after the last line?

Regardless of that, the text start_sign and end_sign doesn’t seem to appear in this code at all, so I’m a bit confused as to how this plugin could be causing that error.

0 Likes

#7
import json
import copy
import urllib
import sublime
import sublime_plugin


class DimensionCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        """
        插件驱动函数,入口
        """
        # choose_bool = sublime.ok_cancel_dialog("开始选择维度","开始")
        # if choose_bool is True:
        now_windows = sublime.active_window()
        self.now_windows = now_windows
        dims_data = self.get_dimension_data()
        self.initialize_count = 0
        self.labels = dims_data
        self.user_choose_dimension = []
        self.select(self.labels)


    def select(self, choose_list):
        self.now_windows.show_quick_panel(self.labels, self.on_select)
        if self.initialize_count < 1:
            self.now_windows.run_command("append", {"characters": "请输入所需维度字段进行筛选!"})
            self.now_windows.run_command("move_to", {"to": "eol"})

        # self.now_windows.show_quick_panel(self.labels, on_select=lambda id: self.on_select(id, self.labels))


    def get_dimension_data(self):
        """
        接口获取指标数据供用户筛选
        """
        dimension_params = {"requests_type":"get_dims", "site":"mart_ind"}
        params = json.dumps(dimension_params)
        params = bytes(params, 'utf8')
        requests = urllib.request.Request(url='http://{local_ip}:80/ajsql_service/module/get_config'.format(local_ip=self.get_local_ip()), data=params, method='POST')
        response = urllib.request.urlopen(requests)
        response = response.read().decode('utf-8')
        response = json.loads(response)
        if response.get("status_code") == 200:
            dimension_data = response.get("data")
        else:
            sublime.error_message("读取维度失败,请检查网络是否连通!")
        # dimension_array = [[key.split(":")[0], key.split(":")[1]] for key in dimension_data]
        return dimension_data


    def on_select(self, index):
        """
        构造筛选框,提供维度指标筛选
        """
        self.initialize_count += 1
        if index != -1 and len(self.labels) > 0:
            save_bool = sublime.ok_cancel_dialog("继续选择", "继续")
            self.user_choose_dimension.append(self.labels[index])
            print("选我选我")
            if save_bool is True:
                self.labels.pop(index)
            self.select(self.labels)
        else:
            print("越界或者选完啦!")
            print(self.user_choose_dimension)
            if self.user_choose_dimension:
                transform_data = [key.replace(" -> ",".") for key in self.user_choose_dimension]
                self.view.run_command("ajsql_di_insert", {"text": "dimensions = " + str(transform_data)})

    def get_local_ip(self):
        import os 
        print(os.getcwd())
        with open("ajsql_sublime.config", "r", encoding="utf-8") as f:
            local_ip = f.read()
        ip = json.loads(local_ip)
        return ip.get("LOCAL_IP")


class AjsqlDiInsertCommand(sublime_plugin.TextCommand):
    """
    当前Windows 清屏
    当前Windwos 写入脚本
    """
    def run(self, edit, text):
        region = sublime.Region(0, 999999)
        windows_str = self.view.substr(region)
        if "metrics" not in windows_str.lower():
            print("metrics 木滴了")
            self.view.replace(edit, region, "")
            self.view.insert(edit, 0, text.replace("'",'"'))
        else:
            # 获取文档宽高
            vector = self.view.layout_extent()
            # 获取文本位置
            point = self.view.layout_to_text(vector)
            # 执行写入操作
            self.view.insert(edit, point, "\n" + text.replace("'",'"'))

Code does not include start_sign and end_sign

0 Likes

#8

Current solution: Copy the code to a new file and modify the plug-in class name. The above error disappeared. Thank you everyone.

0 Likes