Sublime Forum

How to stop/restart all LSP plugins using the sublime text python api

#1

How to stop/restart all LSP plugins using the sublime text python API. Something like view.run_command(...) or


class Xmrf(sublime_plugin.TextCommand):
    # toggle allac
    # window = sublime.active_window()
    # window.run_command("lsp_enable_language_server_in_project")
    # window.run_command("lsp_disable_language_server_in_project")
    def run(self, edit):
        view = self.view
        global ISOFF
        ISOFF = not ISOFF
        if ISOFF:
            view.set_status("2b_allac", f"AC(off)")
        else:
            view.set_status("2b_allac", f"AC(on)")
        # id_settings = "Preferences.sublime-settings"
        # id_key = "ignored_packages"
        # settings = sublime.load_settings(id_settings)
        # tmp = settings.get(id_key)
        # for aa in ["LSP-pyright", "LSP-json", "LSP-clangd"]:
        #     if self.ison_lsp:
        #         if aa in tmp:
        #             tmp.remove(aa)
        #     else:
        #         tmp.append(aa)
        # self.ison_lsp = not self.ison_lsp
        # print("--------------------")
        # print("ignored_packages", tmp)
        # print("--------------------")
        # settings.set(id_key, tmp)
        # sublime.save_settings(id_settings)
0 Likes

#2

Maybe there is a better answer (for all servers) but for restart a certain server:

view.run_command("lsp_restart_server", {"config_name": "LSP-intelephense"})
0 Likes

#3

Thank you~

0 Likes

#4
class Xmrf(sublime_plugin.TextCommand):
    # toggle allac
    # window.run_command("lsp_enable_language_server_in_project")
    # window.run_command("lsp_disable_language_server_in_project")
    # view.run_command("lsp_enable_language_server_globally", {"config_name": "LSP-pyright"})
    def run(self, edit):
        # window = sublime.active_window()
        view = self.view
        global ISOFF
        ISOFF = not ISOFF
        if ISOFF:
            view.set_status("2b_allac", f"AC(off)")
            view.run_command(
                "lsp_enable_language_server_globally", {"config_name": "LSP-pyright"}
            )
        else:
            view.set_status("2b_allac", f"AC(on)")
            view.run_command(
                "lsp_disable_language_server_globally", {"config_name": "LSP-pyright"}
            )

I have tried, but it doesn’t work.

view.run_command(“not_exist_command”) will give no error even the command not exist?

0 Likes

#5

no. isn’t that easy to try by yourself lol.

I have tried, but it doesn’t work.

That’s how it works in one of my private plugin. (I mean lsp_restart_server. Not lsp_disable_language_server_globally)

0 Likes

#6

The command lsp_disable_language_server_globally you use doesn’t take any argument. It’s mean to be user-interactive at least at this moment.

0 Likes

#7

Thank you~ I understand now.

0 Likes