@@ -38,18 +38,46 @@ def get_position(view: sublime.View, event: Optional[dict] = None, point: Option
38
38
return None
39
39
40
40
41
+ class LspWindowCommand (sublime_plugin .WindowCommand ):
42
+ """
43
+ Inherit from this class to define requests which are not bound to a particular view. This allows to run requests
44
+ for example from links in HtmlSheets or when an unrelated file has focus.
45
+ """
46
+
47
+ # When this is defined in a derived class, the command is enabled only if there exists a session with the given
48
+ # capability attached to a view in the window.
49
+ capability = ''
50
+
51
+ # When this is defined in a derived class, the command is enabled only if there exists a session with the given
52
+ # name attached to a view in the window.
53
+ session_name = ''
54
+
55
+ def is_enabled (self ) -> bool :
56
+ return self .session () is not None
57
+
58
+ def session (self ) -> Optional [Session ]:
59
+ for session in windows .lookup (self .window ).get_sessions ():
60
+ if self .capability and not session .has_capability (self .capability ):
61
+ continue
62
+ if self .session_name and session .config .name != self .session_name :
63
+ continue
64
+ return session
65
+ else :
66
+ return None
67
+
68
+
41
69
class LspTextCommand (sublime_plugin .TextCommand ):
42
70
"""
43
71
Inherit from this class to define your requests that should be triggered via the command palette and/or a
44
72
keybinding.
45
73
"""
46
74
47
- # When this is defined in a derived class, the command is enabled only if there exists a session attached to the
48
- # view that has the given capability .
75
+ # When this is defined in a derived class, the command is enabled only if there exists a session with the given
76
+ # capability attached to the active view .
49
77
capability = ''
50
78
51
- # When this is defined in a derived class, the command is enabled only if there exists a session attached to the
52
- # view that has the given name .
79
+ # When this is defined in a derived class, the command is enabled only if there exists a session with the given
80
+ # name attached to the active view .
53
81
session_name = ''
54
82
55
83
def is_enabled (self , event : Optional [dict ] = None , point : Optional [int ] = None ) -> bool :
0 commit comments