99from watchdog .observers import Observer
1010
1111from .client import CopilotPlugin
12- from .decorators import _must_be_active_view_not_ignored
12+ from .decorators import _must_be_active_view
1313from .ui import ViewCompletionManager , ViewPanelCompletionManager
1414from .utils import (
1515 CopilotIgnore ,
@@ -46,7 +46,7 @@ def _is_saving(self) -> bool:
4646 def _is_saving (self , value : bool ) -> None :
4747 set_copilot_view_setting (self .view , "_is_saving" , value )
4848
49- @_must_be_active_view_not_ignored ()
49+ @_must_be_active_view ()
5050 def on_modified_async (self ) -> None :
5151 self ._is_modified = True
5252
@@ -60,20 +60,6 @@ def on_modified_async(self) -> None:
6060 if not self ._is_saving and get_session_setting (session , "auto_ask_completions" ) and not vcm .is_waiting :
6161 plugin .request_get_completions (self .view )
6262
63- def on_activated_async (self ) -> None :
64- if (
65- (window := self .view .window ())
66- and (plugin := CopilotPlugin .from_view (self .view ))
67- and copilot_ignore_observer
68- ):
69- copilot_ignore_observer .add_folders (window .folders ())
70- CopilotIgnore (window ).load_patterns ()
71- CopilotIgnore (window ).trigger (self .view )
72- if get_copilot_view_setting (self .view , "is_copilot_ignored" , False ):
73- plugin .update_status_bar_text ({"is_copilot_ignored" : "ignored" })
74- else :
75- plugin .update_status_bar_text ()
76-
7763 def on_deactivated_async (self ) -> None :
7864 ViewCompletionManager (self .view ).hide ()
7965
@@ -121,6 +107,16 @@ def test(value: Any) -> bool | None:
121107
122108 return None
123109
110+ def on_activated_async (self ) -> None :
111+ _ , session = CopilotPlugin .plugin_session (self .view )
112+ if (session and CopilotPlugin .should_ignore (self .view )) or (
113+ not session and not CopilotPlugin .should_ignore (self .view )
114+ ):
115+ # Hacky way to trigger adding and removing views from session
116+ prev_setting = self .view .settings ().get ("lsp_uri" )
117+ self .view .settings ().set ("lsp_uri" , "" )
118+ sublime .set_timeout_async (lambda : self .view .settings ().set ("lsp_uri" , prev_setting ), 5 )
119+
124120 def on_post_text_command (self , command_name : str , args : dict [str , Any ] | None ) -> None :
125121 if command_name == "lsp_save" :
126122 self ._is_saving = True
@@ -133,7 +129,7 @@ def on_post_text_command(self, command_name: str, args: dict[str, Any] | None) -
133129 def on_post_save_async (self ) -> None :
134130 self ._is_saving = False
135131
136- @_must_be_active_view_not_ignored ()
132+ @_must_be_active_view ()
137133 def on_selection_modified_async (self ) -> None :
138134 if not self ._is_modified :
139135 ViewCompletionManager (self .view ).handle_selection_change ()
0 commit comments