File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,7 +48,11 @@ impl super::BackgroundDocumentRequestHandler for CodeActions {
4848
4949 if snapshot. client_settings ( ) . fix_all ( ) {
5050 if supported_code_actions. contains ( & SupportedCodeAction :: SourceFixAll ) {
51- response. push ( fix_all ( & snapshot) . with_failure_code ( ErrorCode :: InternalError ) ?) ;
51+ if snapshot. is_notebook_cell ( ) {
52+ tracing:: debug!( "Ignoring `source.fixAll` code action for a notebook cell" ) ;
53+ } else {
54+ response. push ( fix_all ( & snapshot) . with_failure_code ( ErrorCode :: InternalError ) ?) ;
55+ }
5256 } else if supported_code_actions. contains ( & SupportedCodeAction :: NotebookSourceFixAll ) {
5357 response
5458 . push ( notebook_fix_all ( & snapshot) . with_failure_code ( ErrorCode :: InternalError ) ?) ;
@@ -57,8 +61,15 @@ impl super::BackgroundDocumentRequestHandler for CodeActions {
5761
5862 if snapshot. client_settings ( ) . organize_imports ( ) {
5963 if supported_code_actions. contains ( & SupportedCodeAction :: SourceOrganizeImports ) {
60- response
61- . push ( organize_imports ( & snapshot) . with_failure_code ( ErrorCode :: InternalError ) ?) ;
64+ if snapshot. is_notebook_cell ( ) {
65+ tracing:: debug!(
66+ "Ignoring `source.organizeImports` code action for a notebook cell"
67+ ) ;
68+ } else {
69+ response. push (
70+ organize_imports ( & snapshot) . with_failure_code ( ErrorCode :: InternalError ) ?,
71+ ) ;
72+ }
6273 } else if supported_code_actions
6374 . contains ( & SupportedCodeAction :: NotebookSourceOrganizeImports )
6475 {
Original file line number Diff line number Diff line change @@ -50,6 +50,21 @@ impl super::BackgroundDocumentRequestHandler for CodeActionResolve {
5050 . with_failure_code ( ErrorCode :: InvalidParams ) ;
5151 } ;
5252
53+ match action_kind {
54+ SupportedCodeAction :: SourceFixAll | SupportedCodeAction :: SourceOrganizeImports
55+ if snapshot. is_notebook_cell ( ) =>
56+ {
57+ // This should never occur because we ignore generating these code actions for a
58+ // notebook cell in the `textDocument/codeAction` request handler.
59+ return Err ( anyhow:: anyhow!(
60+ "Code action resolver cannot resolve {:?} for a notebook cell" ,
61+ action_kind. to_kind( ) . as_str( )
62+ ) )
63+ . with_failure_code ( ErrorCode :: InvalidParams ) ;
64+ }
65+ _ => { }
66+ }
67+
5368 action. edit = match action_kind {
5469 SupportedCodeAction :: SourceFixAll | SupportedCodeAction :: NotebookSourceFixAll => Some (
5570 resolve_edit_for_fix_all (
Original file line number Diff line number Diff line change @@ -184,4 +184,15 @@ impl DocumentSnapshot {
184184 pub ( crate ) fn encoding ( & self ) -> PositionEncoding {
185185 self . position_encoding
186186 }
187+
188+ /// Returns `true` if this snapshot represents a notebook cell.
189+ pub ( crate ) const fn is_notebook_cell ( & self ) -> bool {
190+ matches ! (
191+ & self . document_ref,
192+ index:: DocumentQuery :: Notebook {
193+ cell_url: Some ( _) ,
194+ ..
195+ }
196+ )
197+ }
187198}
You can’t perform that action at this time.
0 commit comments